/// <summary>
        /// Faz o pré procesamento de notas e frequeências que estão na fila para o novo fechamento
        /// </summary>
        public static void ExecJOB_ProcessamentoNotaFrequenciaFechamentoAsync(bool limpacache = true)
        {
            using (DataTable dt = new GestaoEscolarServicoDAO().ExecJOB_ProcessamentoNotaFrequenciaFechamentoAsync())
            {
                if (limpacache)
                {
                    if (dt.Rows.Count > 0)
                    {
                        List <sChavesCacheFechamento> ltChave = (from DataRow dr in dt.Rows
                                                                 select(sChavesCacheFechamento) GestaoEscolarUtilBO.DataRowToEntity(dr, new sChavesCacheFechamento())).ToList();

                        // Informações da configuracao.
                        IDictionary <string, ICFG_Configuracao> configuracao;
                        CFG_ConfiguracaoBO.Consultar(eConfig.Academico, out configuracao);
                        string ips = configuracao["AppEnderecoIPRaizHandlerLimpaCache"].cfg_valor;

                        string[] listaIps = ips.Split('|');

                        foreach (string ip in listaIps)
                        {
                            string handler = ip + "/Configuracao/Conteudo/LimpaCache.ashx?tipoCache=1";
                            handler += "&tur_ids=" + string.Join(";", ltChave.Select(p => p.tur_id));
                            handler += "&tud_ids=" + string.Join(";", ltChave.Select(p => p.tud_id));
                            handler += "&fav_ids=" + string.Join(";", ltChave.Select(p => p.fav_id));
                            handler += "&ava_ids=" + string.Join(";", ltChave.Select(p => p.ava_id));
                            handler += "&tpc_ids=" + string.Join(";", ltChave.Select(p => p.tpc_id));

                            HttpWebRequest  request  = WebRequest.Create(handler) as HttpWebRequest;
                            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Retorna a expressão de configuração de acordo com o nome do trigger.
        /// </summary>
        /// <param name="trigger">Nome do trigger.</param>
        /// <param name="expressao">Expressão de configuração.</param>
        /// <returns>Verdadeiro se encontrou uma expressão para o trigger.</returns>
        public static bool SelecionaExpressaoPorTrigger(string trigger, out string expressao)
        {
            expressao = string.Empty;

            GestaoEscolarServicoDAO dao = new GestaoEscolarServicoDAO();

            DataTable dt = dao.SelecionaExpressaoPorTrigger(trigger);

            if (dt.Rows.Count > 0)
            {
                expressao = dt.Rows[0]["cron_expression"].ToString();
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Processa o alerta de alunos com baixa frequência.
        /// </summary>
        public static void ExecJOB_AlertaAlunosBaixaFrequencia()
        {
            CFG_Alerta alerta = CFG_AlertaBO.GetEntity(new CFG_Alerta {
                cfa_id = (byte)CFG_AlertaBO.eChaveAlertas.AlertaAlunosBaixaFrequencia
            });

            if (alerta.cfa_periodoAnalise > 0 && !string.IsNullOrEmpty(alerta.cfa_assunto))
            {
                // Busca os usuários para envio da notificação
                DataTable dt = new GestaoEscolarServicoDAO().ExecJOB_AlertaAlunosBaixaFrequencia();
                List <sAlertaAlunosBaixaFrequencia> lstUsuarios = (from DataRow dr in dt.Rows
                                                                   select(sAlertaAlunosBaixaFrequencia) GestaoEscolarUtilBO.DataRowToEntity(dr, new sAlertaAlunosBaixaFrequencia())).ToList();
                List <int> lstEscolas = lstUsuarios.Select(p => p.esc_id).Distinct().ToList();
                DateTime   dataAtual  = DateTime.UtcNow;
                lstEscolas.ForEach(e =>
                {
                    NotificacaoDTO notificacao          = new NotificacaoDTO();
                    notificacao.SenderName              = "SGP";
                    notificacao.Recipient               = new DestinatarioNotificacao();
                    notificacao.Recipient.UserRecipient = new List <string>();
                    notificacao.MessageType             = 3;
                    notificacao.DateStartNotification   = string.Format("{0:yyyy-MM-ddTHH:mm:ss.0000000-00:00}", dataAtual);
                    notificacao.DateEndNotification     = alerta.cfa_periodoValidade > 0 ? string.Format("{0:yyyy-MM-ddTHH:mm:ss.0000000-00:00}", dataAtual.AddHours(alerta.cfa_periodoValidade)) : null;
                    notificacao.Title = alerta.cfa_nome;
                    List <sAlertaAlunosBaixaFrequencia> lstUsuariosEscola = lstUsuarios.FindAll(u => u.esc_id == e);
                    notificacao.Message = alerta.cfa_assunto
                                          .Replace("[NomeEscola]", lstUsuariosEscola.First().esc_nome.ToString())
                                          .Replace("[PercentualMinimoFrequencia]", lstUsuariosEscola.First().percentualBaixaFrequencia.ToString())
                                          .Replace("[Dias]", alerta.cfa_periodoAnalise.ToString())
                                          .Replace("[PulaLinha]", "<br/>");
                    lstUsuariosEscola.ForEach(ue => notificacao.Recipient.UserRecipient.Add(ue.usu_id.ToString()));
                    if (EnviarNotificacao(notificacao))
                    {
                        List <LOG_AlertaAlunosBaixaFrequencia> lstLog = new List <LOG_AlertaAlunosBaixaFrequencia>();
                        notificacao.Recipient.UserRecipient.ForEach(ur => lstLog.Add(new LOG_AlertaAlunosBaixaFrequencia {
                            usu_id = new Guid(ur), esc_id = e, lbf_dataEnvio = DateTime.Now
                        }));
                        LOG_AlertaAlunosBaixaFrequenciaBO.SalvarEmLote(lstLog);
                    }
                }
                                   );
            }
        }
        /// <summary>
        /// Faz o pré procesamento do relatório pendências por disciplinas e alunos
        /// </summary>
        public static void ExecJOB_ProcessamentoRelatorioDisciplinasAlunosPendenciasAsync(bool limpacache = true)
        {
            using (DataTable dt = new GestaoEscolarServicoDAO().ExecJOB_ProcessamentoRelatorioDisciplinasAlunosPendenciasAsync())
            {
                if (dt.Rows.Count > 0)
                {
                    List <sChaveCachePendenciaFechamento> ltChave = (from DataRow dr in dt.Rows
                                                                     select(sChaveCachePendenciaFechamento) GestaoEscolarUtilBO.DataRowToEntity(dr, new sChaveCachePendenciaFechamento())).ToList();

                    if (limpacache)
                    {
                        // Informações do e-mail.
                        IDictionary <string, ICFG_Configuracao> configuracao;
                        CFG_ConfiguracaoBO.Consultar(eConfig.Academico, out configuracao);
                        string ips = configuracao["AppEnderecoIPRaizHandlerLimpaCache"].cfg_valor;

                        string[] listaIps = ips.Split('|');

                        foreach (string ip in listaIps)
                        {
                            string handler = ip + "/Configuracao/Conteudo/LimpaCache.ashx?tipoCache=2";
                            handler += "&esc_ids=" + string.Join(";", ltChave.Select(p => p.esc_id));
                            handler += "&uni_ids=" + string.Join(";", ltChave.Select(p => p.uni_id));
                            handler += "&cal_ids=" + string.Join(";", ltChave.Select(p => p.cal_id));
                            handler += "&tud_ids=" + string.Join(";", ltChave.Select(p => p.tud_id));

                            try
                            {
                                HttpWebRequest request = WebRequest.Create(handler) as HttpWebRequest;
                                request.GetResponseAsync();
                            }
                            catch
                            {
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Processa o alerta de preenchimento de frequência.
        /// </summary>
        public static void ExecJOB_AlertaPreenchimentoFrequencias()
        {
            CFG_Alerta alerta = CFG_AlertaBO.GetEntity(new CFG_Alerta {
                cfa_id = (byte)CFG_AlertaBO.eChaveAlertas.AlertaPreenchimentoFrequencia
            });

            if (!string.IsNullOrEmpty(alerta.cfa_assunto))
            {
                // Busca os usuários para envio da notificação
                DataTable dt = new GestaoEscolarServicoDAO().ExecJOB_AlertaPreenchimentoFrequencias();
                List <sAlertaPreenchimentoFrequencia> lstUsuarios = (from DataRow dr in dt.Rows
                                                                     select(sAlertaPreenchimentoFrequencia) GestaoEscolarUtilBO.DataRowToEntity(dr, new sAlertaPreenchimentoFrequencia())).ToList();
                if (lstUsuarios.Any())
                {
                    DateTime       dataAtual   = DateTime.UtcNow;
                    NotificacaoDTO notificacao = new NotificacaoDTO();
                    notificacao.SenderName = "SGP";
                    notificacao.Recipient  = new DestinatarioNotificacao();
                    notificacao.Recipient.UserRecipient = new List <string>();
                    notificacao.MessageType             = 3;
                    notificacao.DateStartNotification   = string.Format("{0:yyyy-MM-ddTHH:mm:ss.0000000-00:00}", dataAtual);
                    notificacao.DateEndNotification     = alerta.cfa_periodoValidade > 0 ? string.Format("{0:yyyy-MM-ddTHH:mm:ss.0000000-00:00}", dataAtual.AddHours(alerta.cfa_periodoValidade)) : null;
                    notificacao.Title   = alerta.cfa_nome;
                    notificacao.Message = alerta.cfa_assunto.Replace("[PulaLinha]", "<br/>");
                    lstUsuarios.ForEach(ue => notificacao.Recipient.UserRecipient.Add(ue.usu_id.ToString()));
                    if (EnviarNotificacao(notificacao))
                    {
                        List <LOG_AlertaPreenchimentoFrequencia> lstLog = new List <LOG_AlertaPreenchimentoFrequencia>();
                        notificacao.Recipient.UserRecipient.ForEach(ur => lstLog.Add(new LOG_AlertaPreenchimentoFrequencia {
                            usu_id = new Guid(ur), lpf_dataEnvio = DateTime.Now
                        }));
                        LOG_AlertaPreenchimentoFrequenciaBO.SalvarEmLote(lstLog);
                    }
                }
            }
        }
        /// <summary>
        /// Atualiza as informações pré-calculadas da tabela CLS_IndicadorFrequencia.
        /// </summary>
        public static void ExecJOB_AtualizaIndicadorFrequencia()
        {
            GestaoEscolarServicoDAO dao = new GestaoEscolarServicoDAO();

            dao.ExecJobAtualizaIndicadorFrequenciaAsync();
        }
        /// <summary>
        /// Atualiza as situaçoes das atribuiçoes esporádicas e das TurmaDocente geradas de acordo com a vigencia.
        /// </summary>
        public static void ExecJOB_AtualizaAtribuicoesEsporadicas()
        {
            GestaoEscolarServicoDAO dao = new GestaoEscolarServicoDAO();

            dao.ExecJobAtualizaAtribuicoesEsporadicasAsync();
        }
        public static void ExecJobArquivoExclusao()
        {
            GestaoEscolarServicoDAO dao = new GestaoEscolarServicoDAO();

            dao.ExecJobArquivoExclusaoAsync();
        }