Beispiel #1
0
        public void ProcessEmailPath(string path, FileWatcherConfigItem cfg)
        {
            try
            {
                StringBuilder sbAlert = new StringBuilder();
                _composeMessageAlert(ref sbAlert, "Diretorio a processar: " + path, 1);

                // Buscando os emails
                Dictionary <int, List <string> > dicEmails = new Dictionary <int, List <string> >();
                logger.Info("Buscando Emails: " + cfg.Exchange);
                switch (cfg.Type)
                {
                case TypeWatcher.BMF:
                    dicEmails = new DbEmailOracle().BuscarClienteBmf();
                    break;

                case TypeWatcher.BOVESPA:
                    dicEmails = new DbEmailOracle().BuscarClienteBovespa();
                    break;

                case TypeWatcher.POSICAO_BMF:
                    dicEmails = new DbEmail().BuscarPosicaoClienteEmail();
                    break;
                }
                if (dicEmails == null || dicEmails.Count == 0)
                {
                    logger.Error("Problemas na consulta dos emails dos clientes...");
                    return;
                }
                logger.InfoFormat("Fim busca Emails. Tipo [{0}]. Accounts: [{1}] ", cfg.NameType, dicEmails.Count);



                // Ler o diretorio com os arquivos
                if (Directory.Exists(path))
                {
                    string[] arqNames = Directory.GetFiles(path);
                    logger.Info("Numero de Arquivos: " + arqNames.Length);
                    foreach (string arqName in arqNames)
                    {
                        int idClient = this._extractIdCliente(arqName);
                        if (idClient == 0)
                        {
                            _composeMessageAlert(ref sbAlert, "ERRO. Não foi possivel extrair  IdCliente", 2);
                            logger.Error("ERRO. Impossivel buscar cliente");
                            continue;
                        }

                        string emailTo = string.Empty;
                        if (!this._getEmail(idClient, dicEmails, ref emailTo))
                        {
                            _composeMessageAlert(ref sbAlert, "Email inexistente para cliente :" + idClient, 2);
                        }
                        else
                        {
                            string msg = string.Format("FileName: [{0}] IdCliente: [{1}] Email: [{2}]", arqName, idClient.ToString("D8"), emailTo);
                            _composeMessageAlert(ref sbAlert, msg, 1);
                            TOEmail toMsg = _composeEmailMsg(_emailFrom, emailTo, arqName, cfg.Exchange, idClient.ToString(), cfg, dicEmails);
                            this.AddEmail(toMsg);
                        }
                    }
                }
                else
                {
                    _composeMessageAlert(ref sbAlert, "Diretorio nao existe!!", 2);
                }

                // Gerando mensagem de processamento
                TOEmail toEmailAlert = this._composeEmailAlert(_emailFrom, _emailAlert, _emailCc,
                                                               _emailCco, string.Format("{0} - Processamento de Arquivo", cfg.NameType));
                toEmailAlert.Msg.Body = sbAlert.ToString();
                this.AddEmail(toEmailAlert);
            }
            catch (Exception ex)
            {
                logger.Error("Problemas no processamento do diretorio de arquivos: " + path + " " + ex.Message, ex);
            }
        }
Beispiel #2
0
        private TOEmail _composeEmailMsg(string emailFrom, string emailTo, string file, string exchange, string idCliente, FileWatcherConfigItem cfg, Dictionary <int, List <string> > dicEmails = null)
        {
            TOEmail ret = new TOEmail();

            try
            {
                string subjectBrokerage;
                if (!string.IsNullOrEmpty(cfg.TemplateFile) && string.IsNullOrEmpty(_templateContent))
                {
                    _templateContent = File.ReadAllText(cfg.TemplateFile);
                }
                subjectBrokerage   = cfg.SubjectEmail.Replace("#clientid#", idCliente);
                ret.IdCliente      = idCliente;
                ret.Exchange       = exchange;
                ret.Msg.From       = emailFrom;
                ret.Msg.To         = emailTo;
                ret.Msg.FileAttach = file;
                ret.Msg.Subject    = subjectBrokerage;
                if (!string.IsNullOrEmpty(_templateContent))
                {
                    ret.Msg.Body       = _templateContent;
                    ret.Msg.IsBodyHtml = true;
                }

                logger.DebugFormat("===> Email Message Compose: From:[{0}] To:[{1}] Subject:[{2}]", ret.Msg.From, ret.Msg.To, ret.Msg.Subject);

                // Verificacao do ClientID com Assunto, anexo e emails gerados.
                if (cfg.ClientIdCheck)
                {
                    int aux;
                    if (int.TryParse(ret.IdCliente, out aux))
                    {
                        if (aux != 0)
                        {
                            // Verificar se IdCliente esta presente no assunto
                            if (ret.Msg.Subject.IndexOf(ret.IdCliente) < 0)
                            {
                                throw new Exception("Client ID is not present at email subject");
                            }

                            // Verificar se IdCliente esta no anexo
                            string fileAux = ret.Msg.FileAttach.Substring(ret.Msg.FileAttach.LastIndexOf("\\"));
                            if (fileAux.IndexOf(ret.IdCliente) < 0)
                            {
                                throw new Exception("Client ID is not present at file name");
                            }

                            // Verificar se os emails da mensagem correspondem ao cliente
                            if (dicEmails == null)
                            {
                                throw new Exception("Email collection is null");
                            }

                            List <string> lst = null;
                            if (dicEmails.TryGetValue(aux, out lst))
                            {
                                foreach (string email in lst)
                                {
                                    if (ret.Msg.To.IndexOf(email, StringComparison.CurrentCultureIgnoreCase) < 0)
                                    {
                                        throw new Exception("Email differs from collection");
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("Unable to parse ClientId to int to proceed check");
                    }
                }



                // Verificacao de testes: se os parametros destinatarios de emails estao definidos no config do servico, irao
                // sobrescrever os sets vindo dos parametros
                if (!string.IsNullOrEmpty(_emailTo))
                {
                    ret.Msg.Subject = string.Format("{0} - [{1}]", ret.Msg.Subject, ret.Msg.To);
                    ret.Msg.To      = _emailTo;
                }
                if (!string.IsNullOrEmpty(_emailCc))
                {
                    ret.Msg.Cc = _emailCc;
                }
                if (!string.IsNullOrEmpty(_emailCco))
                {
                    ret.Msg.Cco = _emailCco;
                }

                ret.Status = StatusInfo.OK;
            }
            catch (Exception ex)
            {
                logger.Error("Problemas na composicao da mensagem de Nota de Corretagem: " + ex.Message, ex);
                ret = null;
            }
            return(ret);
        }
Beispiel #3
0
 public TOArqPdf()
 {
     this.FileName = string.Empty;
     this.Config   = null;
 }