Esempio n. 1
0
        /*Método pelo qual o serviço inicia o robô no Timer agendado.*/
        internal static void InitCallBack(object state)
        {
            try
            {
                isRM = false;

                //Busca as informações do robô no banco de dados.
                config = ConfigRobotController.FindByName(Name);

                //Se o robô estiver ativo inicia o processamento.
                if (config.Active == 'Y')
                {
                    // Deleta o último arquivo de log.
                    if (File.Exists(Path.GetTempPath() + Name + ".txt"))
                    {
                        File.Delete(Path.GetTempPath() + Name + ".txt");
                    }

                    config.Status = 'R';
                    ConfigRobotController.Update(config);
                    using (FileStream fs = File.Create(Path.GetTempPath() + Guid.NewGuid().ToString() + ".ire")) { }
                    Init();

                    //Verifica se teve atualização
                    config = ConfigRobotController.FindByName(Name);

                    //Verifica quantas licitações foram coletadas nessa execução, grava em log.
                    config.NumLicitLast = NumLicitacoes;
                    RService.Log(Name + " find " + NumLicitacoes + " novas licitações at {0}", Path.GetTempPath() + Name + ".txt");
                    RService.Log(Name + " consumiu " + NumCaptcha + " captchas at {0}", Path.GetTempPath() + Name + ".txt");
                    NumLicitacoes = 0;

                    config.LastDate = DateTime.Now;
                }

                //Reprogamando a próxima execução do robô.
                RService.ScheduleMe(config);

                //Atualiza as informações desse robô.
                config.Status = 'W';
                ConfigRobotController.Update(config);

                //Arquivo que indica ao manager que é hora de atualizar as informações.
                File.Create(Path.GetTempPath() + Guid.NewGuid().ToString() + ".ire");
            }
            catch (Exception e)
            {
                RService.Log("Exception (InitCallBack) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt");

                if (web != null)
                {
                    web.Close();
                }
            }

            RService.Log("Finished " + Name + " at {0}", Path.GetTempPath() + Name + ".txt");

            EmailHandle.SendMail(Path.GetTempPath() + Name + ".txt", Name);
        }
Esempio n. 2
0
        internal static void InitCallBack(object state)
        {
            try
            {
                Config = ConfigRobotController.FindByName(Name);

                if (Config.Active == 'Y')
                {
                    // Deleta o último arquivo de log.
                    if (File.Exists(LogPath))
                    {
                        File.Delete(LogPath);
                    }

                    Config.Status = 'R';
                    ConfigRobotController.Update(Config);
                    using (FileStream fs = File.Create(Path.GetTempPath() + Guid.NewGuid().ToString() + ".ire")) { }
                    Init();

                    //Verifica se teve atualização
                    Config = ConfigRobotController.FindByName(Name);

                    Config.NumLicitLast = NumPrecos;
                    RService.Log(Name + " find " + NumPrecos + " novos preços at {0}", LogPath);
                    NumPrecos = 0;

                    Config.LastDate = DateTime.Now;
                }


                //Reprogamando a próxima execução do robô.
                RService.ScheduleMe(Config);

                //Atualiza as informações desse robô.
                Config.Status = 'W';
                ConfigRobotController.Update(Config);

                //Arquivo que indica ao manager que é hora de atualizar as informações.
                File.Create(Path.GetTempPath() + Guid.NewGuid().ToString() + ".ire");
            }
            catch (Exception e)
            {
                RService.Log("Exception (InitCallBack) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", LogPath);
            }

            RService.Log("Finished " + Name + " at {0}", LogPath);

            EmailHandle.SendMail(LogPath, Name);
        }
Esempio n. 3
0
        public static void InitCallBack(object state)
        {
            try
            {
                config = ConfigRobotController.FindByName(Name);

                if (config.Active == 'Y')
                {
                    if (File.Exists(Path.GetTempPath() + Name + ".txt"))
                    {
                        File.Delete(Path.GetTempPath() + Name + ".txt");
                    }

                    config.Status = 'R';
                    ConfigRobotController.Update(config);

                    using (FileStream fs = File.Create(Path.GetTempPath() + Guid.NewGuid().ToString() + ".ire")) { }
                    Init();

                    config = ConfigRobotController.FindByName(Name);

                    config.NumLicitLast = NumLicitacoes;
                    RService.Log(Name + " find " + NumLicitacoes + " novas licitações at {0}", Path.GetTempPath() + Name + ".txt");
                    RService.Log(Name + " consumiu " + NumLicitacoes + " captchas at {0}", Path.GetTempPath() + Name + ".txt");
                    NumLicitacoes = 0;

                    config.LastDate = DateTime.Now;
                }

                RService.ScheduleMe(config);

                config.Status = 'W';
                ConfigRobotController.Update(config);

                File.Create(Path.GetTempPath() + Guid.NewGuid().ToString() + ".ire");
            }
            catch (Exception e)
            {
                RService.Log("Exception (InitCallBack) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt");
            }

            RService.Log("Finished " + Name + " at {0}", Path.GetTempPath() + Name + ".txt");

            EmailHandle.SendMail(Path.GetTempPath() + Name + ".txt", Name);
        }
Esempio n. 4
0
        /*Inicia a busca*/
        private static void Init()
        {
            RService.Log("(Init) " + Name + ": Começando o processamento.." + " at {0}", Path.GetTempPath() + Name + ".txt");
            try
            {
                /*Inicia navegador fantasma*/
                LoadDriver();

                /*Acessa o site do TCE*/
                web.Navigate().GoToUrl(Constants.TCEPR_SITE);

                /*Busca os itens do filtro por cidades*/
                GetCidades();

                /*Configura os parametros da busca e inicia demais componentes necessários*/
                if (config.PreTypedDate != null)
                {
                    CurrentDay          = config.PreTypedDate.Value.AddDays(-2);
                    FinalDay            = config.PreTypedDate.Value;
                    config.PreTypedDate = null;
                    ConfigRobotController.Update(config);
                }
                else
                {
                    CurrentDay = DateTime.Now.AddDays(-2);
                    FinalDay   = DateTime.Now;
                }

                NameToModalidade = ModalidadeController.GetNameToModalidade();
                NameToOrgao      = OrgaoController.GetNomeUfToOrgao();
                Lote             = LoteController.CreateLote(43, 510);
                Repo             = new LicitacaoRepository();

                CurrentPg = 1;
                TotalLic  = 0;

                /*Procura licitacoes por cidade pra ointervalo de dias indicado*/
                foreach (var cidade in dicCidades)
                {
                    CidadeAtualKey = cidade.Key;
                    CidadeAtual    = cidade.Value;
                    /*Pesquisa licitações com base nos parametros (ano; dtAbertura)*/
                    if (DoSearch(CurrentDay, FinalDay))
                    {
                        /*Pra cada pag que a pesquisa retornar*/
                        do
                        {
                            /*Percorre licitações de uma pag*/
                            if (!GetLicitacoes())
                            {
                                //Segunda e ultima tentativa, se não conseguir continua com a pesquisa para a proxima cidade
                                DoSearch(CurrentDay, FinalDay);
                                GetLicitacoes();
                            }
                        } while (HasNextPage());
                    }

                    Tens = new List <int>()
                    {
                        11
                    };
                    CurrentPg = 1;
                }

                //Repo.Insert(licitacoes);
            }
            catch (Exception e)
            {
                RService.Log("Exception (Init) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt");
            }
            finally
            {
                if (TotalLic <= 0)
                {
                    LoteController.Delete(Lote);
                }
                if (web != null)
                {
                    web.Close();
                }
            }
        }
Esempio n. 5
0
        internal static void InitCallBack(object state)
        {
            //Busca as configurações de execução do robô no banco.
            config = ConfigRobotController.FindByName(name);

            try
            {
                if (config.Active == 'Y')
                {
                    //Deleta o log antigo para criar o novo.
                    if (File.Exists(Path.GetTempPath() + name + ".txt"))
                    {
                        File.Delete(Path.GetTempPath() + name + ".txt");
                    }

                    config.Status = 'R';
                    ConfigRobotController.Update(config);
                    using (FileStream fs = File.Create(Path.GetTempPath() + Guid.NewGuid().ToString() + ".ire")) { }

                    Init();

                    //Atualiza as informações do robô de acordo com a última execução.
                    config = ConfigRobotController.FindByName(name);
                    config.NumLicitLast = numLicitacoes;
                    RService.Log(name + " find " + numLicitacoes + " at {0}", logPath);
                    numLicitacoes = 0;

                    config.Status   = 'W';
                    config.LastDate = DateTime.Now;
                    ConfigRobotController.Update(config);
                }

                //Agenda a próxima execução do robô.
                RService.ScheduleMe(config);

                //Arquivo que indica ao manager que é hora de atualizar as informações.
                File.Create(Path.GetTempPath() + Guid.NewGuid().ToString() + ".ire");
            }
            catch (Exception e)
            {
                RService.Log("Exception (InitCallBack) " + name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", logPath);
            }
            finally
            {
                //Finaliza e deleta as instâncias do navegador e da pasta
                if (web != null)
                {
                    web.Close();
                }

                if (Directory.Exists(pathEditais))
                {
                    Directory.Delete(pathEditais);
                }
            }

            RService.Log("Finished " + name + " at {0}", logPath);

            //Envia o log por e-mail
            EmailHandle.SendMail(logPath, name);
        }