コード例 #1
0
        private static void Init()
        {
            RService.Log("(Init) " + Name + ": Começando o processamento... " + "at {0}", Path.GetTempPath() + Name + ".txt");

            try
            {
                nameToModalidade         = ModalidadeController.GetNameToModalidade();
                nameToOrgao              = OrgaoController.GetNomeUfToOrgao();
                ufToCapital              = CityUtil.GetUfToCapital();
                ufToNomeCidadeToIdCidade = CidadeController.GetUfToNameCidadeToIdCidade();
                lote = LoteController.CreateLote(43, 508);
                repo = new LicitacaoRepository();

                HtmlDocument htmlDoc = WebHandle.GetHtmlDocOfPage(Constants.CN_COTACOES, Encoding.GetEncoding("ISO-8859-1"));

                RService.Log("(Init) " + Name + ": Percorrendo as cotações do dia " + DateTime.Today.ToShortDateString() + " at {0}", Path.GetTempPath() + Name + ".txt");

                foreach (var row in htmlDoc.DocumentNode.Descendants("tr").Where(x => x.Attributes.Contains("class") && x.Attributes["class"].Value.Contains("estiloLinhaTabela")).ToList())
                {
                    if (row.ChildNodes[5].InnerText == "Sim")
                    {
                        icms = true;
                    }
                    else
                    {
                        icms = false;
                    }

                    HandleCreate(htmlDoc, row);
                }
            }
            catch (Exception e)
            {
                RService.Log("Exception (Init) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt");
            }
        }
コード例 #2
0
ファイル: BBController.cs プロジェクト: FTorres41/WebCrawlers
        /*Metodo que inicia o processamento de dados*/
        private static void Init()
        {
            RService.Log("(Init) " + Name + ": Começando o processamento... " + "at {0}", Path.GetTempPath() + Name + ".txt");
            try
            {
                Repo = new LicitacaoRepository();

                /*Realiza a atualização das situações das licitações já inseridas*/
                //UpdateLicitacoes();

                /*Inicia listas e dictionary's com informações necessárias*/
                NameToOrgao              = OrgaoController.GetNomeUfToOrgao();
                NameToModalidade         = ModalidadeController.GetNameToModalidade();
                UfToCapital              = CityUtil.GetUfToCapital();
                UfToNomeCidadeToIdCidade = CidadeController.GetUfToNameCidadeToIdCidade();
                Lote = LoteController.CreateLote(43, IdFonte);

                TryReload = true;
                if (DoSearch())
                {
                    /*Percorre cada licitação encontrada*/
                    foreach (var numUf in numUFs)
                    {
                        /*Acessa a página da licitação*/
                        try
                        {
                            if (!LicitacaoController.Exists(numUf.Split(':')[0]))
                            {
                                /*Cria o objeto licitação com as informações da página*/
                                Licitacao licitacao = CreateLicitacao(numUf);

                                if (licitacao != null)
                                {
                                    Repo.Insert(licitacao);
                                    NumLicitacoes++;
                                    RService.Log("(Init) " + Name + ": Licitação inserida com sucesso at {0}", Path.GetTempPath() + Name + ".txt");

                                    /*Segmenta a licitação recém criada*/
                                    //SegmentarLicitacao(licitacao);
                                    DownloadEdAndCreatLicArq(licitacao);
                                }
                                else
                                {
                                    if (licitacao != null && licitacao.Orgao != null)
                                    {
                                        RService.Log("Exception (CreateLicitacao) " + Name + ": A licitação de nº " + licitacao.Num + " e órgão " + licitacao.Orgao.Nome + " - " + licitacao.Orgao.Estado + " não foi salva - Motivo(s): " + mensagemErro + " at {0}", Path.GetTempPath() + Name + ".txt");
                                    }
                                    else
                                    {
                                        RService.Log("Exception (CreateLicitacao) " + Name + ": A licitação de nº " + numUf.Split(':')[0] + " não foi salva - Motivo(s): " + mensagemErro + " at {0}", Path.GetTempPath() + Name + ".txt");
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            RService.Log("Exception (Init - CreateLicitacao) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                RService.Log("Exception (Init) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt");
            }
        }