示例#1
0
        /*Baixa os arquivos de edital*/
        private static void DownloadEditais(List <string> editais, Licitacao licitacao, MatchCollection linkForm)
        {
            try
            {
                RService.Log("(DownloadEditais) " + Name + ": Consultando arquivos de edital, licitação... " + licitacao.IdLicitacaoFonte + " at {0}", Path.GetTempPath() + Name + ".txt");

                if (!Directory.Exists(PathEditais))
                {
                    Directory.CreateDirectory(PathEditais);
                }

                for (int i = 0; i < editais.Count; i++)
                {
                    //Busca os arquivos da licitação
                    LicitacaoArquivoRepository repoArq         = new LicitacaoArquivoRepository();
                    List <LicitacaoArquivo>    arquivosAntigos = repoArq.FindByLicitacao(licitacao.Id);

                    var  edital  = editais[i];
                    bool isExist = false;

                    string nameFile = Regex.Replace(edital.Split('/')[edital.Split('/').Length - 1],
                                                    string.Format("[{0}]", Regex.Escape(
                                                                      new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars()))), "");

                    while (nameFile.Contains("%1A"))
                    {
                        nameFile = Regex.Replace(nameFile, "%1A", "_");
                    }

                    foreach (var arquivoAntigo in arquivosAntigos)
                    {
                        /*Verifica se o arquivo já existe*/
                        if (nameFile.Equals(arquivoAntigo.NomeArquivoFonte))
                        {
                            isExist = true;
                            break;
                        }
                    }
                    if (!isExist)
                    {
                        Thread.Sleep(5000);
                        FillForm(linkForm[i].Value);
                        if (LicitacaoArquivoController.CreateLicitacaoArquivo(Name, licitacao, edital, PathEditais, nameFile, web.Manage().Cookies.AllCookies))
                        {
                            NumArquivosLicitacao++;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                RService.Log("Exception (DownloadEditais) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt");
            }
        }
示例#2
0
        /*Baixa os arquivos de edital*/
        private static void DownloadEditais(List <string> editais, Licitacao licitacao, MatchCollection linkForm)
        {
            try
            {
                RService.Log("(DownloadEditais) " + GetNameRobot() + ": Consultando arquivos de edital, licitação... " + licitacao.IdLicitacaoFonte + " at {0}", Path.GetTempPath() + GetNameRobot() + ".txt");

                if (!Directory.Exists(PathEditais))
                {
                    Directory.CreateDirectory(PathEditais);
                }

                for (int i = 0; i < editais.Count; i++)
                {
                    //Busca os arquivos da licitação
                    LicitacaoArquivoRepository repoArq         = new LicitacaoArquivoRepository();
                    List <LicitacaoArquivo>    arquivosAntigos = repoArq.FindByLicitacao(licitacao.Id);

                    var  edital  = editais[i];
                    bool isExist = false;

                    string nameFile = string.Format("Anexo{0}Licitacao{1}", i, licitacao.Id);

                    foreach (var arquivoAntigo in arquivosAntigos)
                    {
                        /*Verifica se o arquivo já existe*/
                        if (nameFile.Equals(arquivoAntigo.NomeArquivoFonte))
                        {
                            isExist = true;
                            break;
                        }
                    }
                    if (!isExist)
                    {
                        if (LicitacaoArquivoController.CreateLicitacaoArquivo(GetNameRobot(), licitacao, edital, PathEditais, nameFile, web.Manage().Cookies.AllCookies))
                        {
                            NumArquivosLicitacao++;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                RService.Log("Exception (DownloadEditais) " + GetNameRobot() + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + GetNameRobot() + ".txt");
            }
        }
示例#3
0
        private static void GetFiles(Licitacao licitacao)
        {
            try
            {
                if (!Directory.Exists(PathEditais))
                {
                    Directory.CreateDirectory(PathEditais);
                }

                web.FindElement(By.Id("showEdital")).Click();
                Thread.Sleep(3000);

                var html = web.PageSource;

                var fileRx = new Regex(Constants.CRJ_FILELINK_REGEX);

                if (fileRx.IsMatch(html))
                {
                    var matches   = fileRx.Matches(html);
                    var fileLinks = HandleMatchedContent(matches);

                    foreach (var link in fileLinks)
                    {
                        var fileName = link.Split('/')[9];
                        WebHandle.DownloadFileWebRequest(link, PathEditais, fileName);

                        if (LicitacaoArquivoController.CreateLicitacaoArquivo(Name, licitacao, PathEditais, fileName, web.Manage().Cookies.AllCookies))
                        {
                            RService.Log("(GetFiles) " + Name + ": Arquivo " + fileName + " inserido com sucesso para licitação " + licitacao.IdLicitacaoFonte + " at {0}", LogPath);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                RService.Log("Exception (GetFiles) " + Name + ": " + e.Message + " / " + e.StackTrace + " at {0}", LogPath);
            }
        }
示例#4
0
        private static void CreateArquivo(Licitacao licitacao, string filename)
        {
            try
            {
                if (File.Exists(PathEditais + filename))
                {
                    if (LicitacaoArquivoController.CreateLicitacaoArquivo(Name, licitacao, PathEditais, filename, web.Manage().Cookies.AllCookies))
                    {
                        RService.Log("(CreateArquivo) " + Name + ": Arquivo inserido com sucesso para licitação " + licitacao.Num + " at {0}", LogPath);
                    }

                    File.Delete(PathEditais + filename);
                }
                else
                {
                    RService.Log("Exception (CreateArquivo) " + Name + ": Download do arquivo " + filename + " não foi concluído com sucesso at {0}", LogPath);
                }
            }
            catch (Exception e)
            {
                RService.Log("Exception (CreateArquivo) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", LogPath);
            }
        }