Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 4.00 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public void PesquisaDiretorios(string NomeDir)
  2.         {
  3.             DirectoryInfo DirInfo = new DirectoryInfo(NomeDir);
  4.             try
  5.             {
  6.                 // obtém arquivos do diretório
  7.                 FileInfo[] AFileInfo = DirInfo.GetFiles("*.pdf");
  8.                 // processa arquivos, adicionando-os na ListView
  9.                 foreach (FileInfo FilInfo in AFileInfo)
  10.                 {
  11.                     nome_arq = FilInfo.FullName;
  12.                     string nome_arq_trunk = nome_arq.Substring(nome_arq.LastIndexOf('\\') + 1);
  13.                     int id = retornaIdCadastrado(nome_arq_trunk);
  14.                     string extensao = nome_arq_trunk.Substring(nome_arq_trunk.LastIndexOf('.'));
  15.                     string novoNomeGD = montarFormatoGD(id.ToString(), extensao);
  16.                     Versao versao = new Versao();
  17.                     versao.CaminhoDoArquivo = Settings.Default.DiretorioPendentesOCR;
  18.                     versao.Extensao = extensao;
  19.                     versao.NomeDoArquivo = nome_arq_trunk;
  20.                     versao.Id = id;
  21.                     Indexador indexador = new Indexador();
  22.                     indexador.Indexe(versao);
  23.                     extraiu = true;
  24.                     //File.Move(Settings.Default.DiretorioPendentes + nome_arq_trunk, Settings.Default.DiretorioExtraidos + nome_arq_trunk);
  25.  
  26.                     if (extraiu)
  27.                     {
  28.                         arquivosExtraidos++;
  29.                     }
  30.                     else
  31.                     {
  32.                         arquivosNaoExtraidos++;
  33.                     }
  34.                     labelTTArquivos.Text = i.ToString() + " de " + progressBarExtracao.Maximum + " arquivos extraídos";
  35.                     labelTTArquivos.Visible = true;
  36.                     progressBarExtracao.PerformStep();
  37.                     Application.DoEvents();
  38.                     i++;
  39.                 }
  40.             }
  41.             catch (Exception e)
  42.             {
  43.                 extraiu = false;
  44.                 MessageBox.Show(e.Message);
  45.             }
  46.         }
  47.  
  48.  
  49. public class Indexador
  50.     {
  51.         public void Indexe(Versao versao)
  52.         {
  53.             try
  54.             {
  55.  
  56.                 IGoldenIndex goldenIndex =
  57.                     GoldenIndexClient.Instance(Settings.Default.MaquinaGoldenIndex,
  58.                                                Settings.Default.PortaGoldenIndex,
  59.                                                Settings.Default.UriGoldenIndex,
  60.                                                Settings.Default.ProtocoloGoldenIndex);
  61.                 User usuarioGoldenIndex = GoldenIndexClient.Authenticate(Settings.Default.UsuarioGoldenIndex,
  62.                                                                          Settings.Default.SenhaGoldenIndex, goldenIndex);
  63.  
  64.                 string extensao = versao.Extensao.StartsWith(".") ? versao.Extensao : string.Concat(".", versao.Extensao);
  65.                 if (!goldenIndex.IsSupported(usuarioGoldenIndex, extensao))
  66.                 {
  67.                     // Se não for um arquivo suportado, não faz nada
  68.                     return;
  69.                 }
  70.  
  71.                 FileData arquivo = new FileData();
  72.                 arquivo.Url = Settings.Default.DiretorioPendentesOCR + versao.NomeDoArquivo;
  73.                 arquivo.IndexerParameters = new IndexerParameters
  74.                 {
  75.                     Table = "tcejurisprudencia",
  76.                     ContentField = "conteudo_Arquivo",
  77.                     IdField = "id",
  78.                     IdFieldValue = versao.Id.ToString()
  79.                 };
  80.                 goldenIndex.SaveFile(usuarioGoldenIndex, arquivo);
  81.             }
  82.             catch (Exception exception)
  83.             {
  84.                 string erro = exception.Message;
  85.             }
  86.         }
  87.     }
  88.  
  89. public class Versao
  90.     {
  91.         public int? Id { get; set; }
  92.         public string CaminhoDoArquivo { get; set; }
  93.         public string NomeDoArquivo { get; set; }
  94.  
  95.         public string Extensao { get; set; }
  96.     }