/*Inicia o processamento do robot*/
        private static void Init()
        {
            RService.Log("(Init) " + Name + ": Começando o processamento..." + " at {0}", Path.GetTempPath() + Name + ".txt");
            try
            {
                NumAlteracoes = 0;
                repo          = new FontePesquisaRepository();
                //fontePesquisa = repo.FindByActiveRobot();
                fontePesquisa = repo.FindByRegex();


                //Para debug descomentar o código abaixo

                /*FontePesquisa fp = repo.FindById(1750);
                 * fontePesquisa = new List<FontePesquisa>();
                 * fontePesquisa.Add(fp);*/

                foreach (FontePesquisa f in fontePesquisa)
                {
                    RService.Log("(Init) " + Name + ": Consultando fonte: " + f.Nome + " at {0}", Path.GetTempPath() + Name + ".txt");
                    try
                    {
                        HtmlDocument html = new HtmlDocument();

                        html = SitesComCodigoFrame(f);

                        if (string.IsNullOrEmpty(html.DocumentNode.InnerText))
                        {
                            html = WebHandle.HtmlParaObjeto(f.Link, Encoding.UTF8);
                            if (html.DocumentNode.InnerHtml.Contains("�"))
                            {
                                html = WebHandle.HtmlParaObjeto(f.Link, Encoding.GetEncoding("ISO-8859-1"));
                            }
                        }

                        RegistrarConsulta(html, f);
                    }
                    catch (Exception e)
                    {
                        RService.Log("Exception (Init)" + 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");
            }
        }
        private static void GetHistoricos(Licitacao l, string Historic)
        {
            try
            {
                string num        = Regex.Replace(l.Num, @"[^\d+]", "");
                string parametros = string.Format(@"coduasg={0}&modprp=5&numprp={1}", l.Uasg, num);

                HtmlDocument htmlDocument = WebHandle.HtmlParaObjeto(Constants.CN_HISTORICO_LINK + parametros, Encoding.GetEncoding("ISO-8859-1"));

                if (htmlDocument.DocumentNode.LastChild == null)
                {
                    return;
                }

                if (!Regex.IsMatch(htmlDocument.DocumentNode.InnerHtml, @"rico de eventos "))
                {
                    string          expRegular = "<tr bgcolor=\"#ffffff\" class=\"tex3a\">(.+?)</tr>";
                    MatchCollection matches    = Regex.Matches(Regex.Replace(htmlDocument.DocumentNode.InnerHtml, "\n", "").Replace("\r", ""), expRegular);

                    if (matches.Count > 0)
                    {
                        RService.Log("(GetHistoricos) " + Historic + ": Buscando histórico da licitação: " + l.IdLicitacaoFonte + " at {0}", Path.GetTempPath() + Historic + ".txt");

                        for (int i = 0; i < matches.Count; i++)
                        {
                            LicitacaoHistorico historico = new LicitacaoHistorico();
                            historico.IdLicitacao = l.Id;

                            var      helper    = Regex.Match(matches[i].Value, @"\d{2}/\d{2}/\d{4}( +)\d{2}\:\d{2}\:\d{2}").Value;
                            DateTime valorData = new DateTime();
                            historico.DataCadastro = DateTime.TryParse(helper, out valorData) ? valorData : new DateTime();

                            helper = Regex.Match(matches[i].Value, "<td align=\"left\">(.+?)</td>").Value;
                            helper = Regex.Replace(helper, @"&nbsp", " ");
                            helper = Regex.Replace(helper, "<td align=\"left\">", "");
                            helper = Regex.Replace(helper, "</td>", "");
                            historico.Historico = helper.Trim();

                            if (LicitacaoHistoricoController.Insert(historico))
                            {
                                RService.Log("(ConsultaAtaPregao) " + Historic + ": Histórico registrado com sucesso" + " at {0}", Path.GetTempPath() + Historic + ".txt");
                                NumHistoricos++;
                            }
                        }

                        if (matches.Count == 1)
                        {
                            RService.Log("(GetHistoricos) " + Historic + ": Encontrado 1 item de histórico at {0}", Path.GetTempPath() + Historic + ".txt");
                        }
                        else if (matches.Count > 1)
                        {
                            RService.Log("(GetHistoricos) " + Historic + ": Encontrados " + matches.Count + " itens de histórico at {0}", Path.GetTempPath() + Historic + ".txt");
                        }
                        else
                        {
                            RService.Log("(GetHistoricos) " + Historic + ": Não foram encontrados novos itens de histórico at {0}", Path.GetTempPath() + Historic + ".txt");
                        }
                    }
                    else
                    {
                        RService.Log("(GetHistoricos) " + Historic + ": Não foram encontrados itens de histórico at {0}", Path.GetTempPath() + Historic + ".txt");
                    }
                }
            }
            catch (Exception e)
            {
                RService.Log("Exception (GetHistoricos) " + Historic + " para licitação " + l.IdLicitacaoFonte + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Historic + ".txt");
            }
        }