/*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); }
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); }
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); }
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); }