Beispiel #1
0
        public InfoMessaggioUI(InfoSpedizioneMessaggioDTO infoMessaggio)
        {
            InitializeComponent(); 
            infoSpedizioneMessaggioDTOBindingSource.DataSource = infoMessaggio;

            persistWindowComponent1.UserName = Security.Login.Instance.CurrentLogin().LoginName;
            nominativoMittente.Text = getIndirizzo(infoMessaggio.Mittente);
            nominativoDestinatario.Text = getIndirizzo(infoMessaggio.Destinatario);
        }
Beispiel #2
0
        public IList<InfoSpedizioneMessaggioDTO> GetInfoMessaggio(int? idAzienda, IList<int> idMessaggi)
        {
            try
            {
                var result = new List<InfoSpedizioneMessaggioDTO>();
                var idAziende = new List<int>();
                if(idAzienda != null)
                    idAziende.Add(idAzienda.GetValueOrDefault());
                else
                {
                    var aziende = _daoFactory.GetAziendaDao().GetAll();
                    idAziende.AddRange(aziende.Select(azienda => azienda.ID));
                }

                var service = new Reports { Timeout = 999999999 };
                var userService = new Users();
                foreach (var id in idAziende)
                {
                    var credenziali = _configurationService.GetLoginInfo(id);

                    if (credenziali != null && !string.IsNullOrEmpty(credenziali.Value.Utente) && !string.IsNullOrEmpty(credenziali.Value.Password))
                    {
                        bool success;
                        try
                        {
                            var resultUsers = userService.Login(credenziali.Value.Utente, credenziali.Value.Password, null);
                            success = resultUsers.success;
                        }
                        catch (Exception ex)
                        {
                            _log.WarnFormat("Errore durante il controllo delle credenziali - {0} - username:{1} - password:{2}", ex, Utility.GetMethodDescription(), credenziali.Value.Utente, credenziali.Value.Password);
                            success = false;
                        }

                        if (success)
                        {
                            var date = getDataInizialeFinale(idMessaggi);
                            var dataIniziale = date[0];
                            var dataFinale = date[1];

                            eMessageResultReportFax report;
                            try
                            {
                                report = service.GetFaxList(credenziali.Value.Utente, credenziali.Value.Password, dataIniziale, dataFinale, null);
                            }
                            catch (System.Web.Services.Protocols.SoapException ex)
                            {
                                _log.WarnFormat("Errore nella lettura del report - {0} - utente:{1} - password:{2} - dataIniziale:{3} - dataFinale:{4} - azienda:{5}", ex, Utility.GetMethodDescription(), credenziali.Value.Utente, credenziali.Value.Password, dataIniziale, dataFinale, id);
                                continue;
                            }
                            catch (Exception ex)
                            {
                                _log.ErrorFormat("Errore nella lettura del report - {0} - utente:{1} - password:{2} - dataIniziale:{3} - dataFinale:{4} - azienbda:{5}", ex, Utility.GetMethodDescription(), credenziali.Value.Utente, credenziali.Value.Password, dataIniziale, dataFinale, id);
                                throw;
                            }

                            foreach (var fax in report.FaxList)
                            {
                                try
                                {
                                    var info = new InfoSpedizioneMessaggioDTO
                                    {
                                        CodiceMessaggio = fax.FaxCode,
                                        Costo = Convert.ToDecimal(fax.FaxCost),
                                        DataRicezione = fax.NotificationDate,
                                        Destinatario = new List<string> { fax.ParamTo },
                                        FineSpedizione = fax.JobFinished,
                                        InizioSpedizione = fax.JobInserted,
                                        Mittente = new List<string> { fax.NomeAmministratore },
                                        NumeroMittente = fax.FAXAmministratore,
                                        RisultatoSpedizione = fax.RetVal,
                                        StatoMessaggio = fax.NotificationResult
                                    };

                                    if (idMessaggi != null && idMessaggi.Count > 0)
                                    {
                                        var messaggi = getMessaggi(idMessaggi);
                                        var messaggio = messaggi.FirstOrDefault(item => item.CodiceMessaggio == fax.FaxCode);
                                        if (messaggio != null)
                                            info.Id = messaggio.ID;
                                    }
                                    else
                                    {
                                        if (!string.IsNullOrEmpty(fax.FaxCode) && !string.IsNullOrEmpty(fax.FaxCode.Trim()))
                                        {
                                            var messaggi = _daoFactory.GetStoricoMessaggioDao().GetByCodiceMessaggio(fax.FaxCode).Count > 0 ? _daoFactory.GetStoricoMessaggioDao().GetByCodiceMessaggio(fax.FaxCode) : _daoFactory.GetStoricoMessaggioDao().GetByCodiceInvio(fax.FaxCode);
                                            foreach (var storicoMessaggio in messaggi)
                                            {
                                                try
                                                {
                                                    storicoMessaggio.Costo = Convert.ToDecimal(fax.FaxCost);
                                                    storicoMessaggio.DataElaborazione = fax.JobFinished;
                                                    storicoMessaggio.DataRicezione = fax.NotificationDate;
                                                    if (!string.IsNullOrEmpty(fax.RetVal))
                                                    {
                                                        if (fax.RetVal.StartsWith("OK"))
                                                            storicoMessaggio.Stato = StatoMessaggio.Ricevuto;
                                                        else if (fax.RetVal.StartsWith("KO"))
                                                            storicoMessaggio.Stato = StatoMessaggio.Fallito;
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    _log.ErrorFormat("Errore nell'aggiornamento del messaggio - SINGOLO MESSAGGIO - {0} - id:{1}", ex, Utility.GetMethodDescription(), storicoMessaggio.ID);
                                                    throw;
                                                }
                                            }
                                        }
                                    }

                                    result.Add(info);

                                }
                                catch (Exception ex)
                                {
                                    _log.ErrorFormat("Errore nell'aggiornamento del messaggio - SINGOLO FAX - {0} - fax:{1}", ex, Utility.GetMethodDescription(), fax.FaxCode);
                                    throw;
                                }
                            }                            
                        }
                        else
                        {
                            _log.WarnFormat("Credenziali non valide - {0} - username:{1} - password:{2}", Utility.GetMethodDescription(), credenziali.Value.Utente, credenziali.Value.Password);
                        }
                    }                        
                }

                return result;
            }
            catch (Exception ex)
            {
                _log.ErrorFormat("Errore inaspettato durante il controllo dello stato del messaggio - {0}", ex, Utility.GetMethodDescription());
                throw;
            }
        }
Beispiel #3
0
        public IList<InfoSpedizioneMessaggioDTO> GetInfoMessaggio(int? idAzienda, IList<int> idMessaggi)
        {
            try
            {
                var result = new List<InfoSpedizioneMessaggioDTO>();
                var idAziende = new List<int>();
                if (idAzienda != null)
                    idAziende.Add(idAzienda.GetValueOrDefault());
                else
                {
                    var aziende = _daoFactory.GetAziendaDao().GetAll();
                    idAziende.AddRange(aziende.Select(azienda => azienda.ID));
                }

                var service = new it.emessage.reports.Reports { Timeout = 999999999 };
                var userService = new it.emessage.users.Users();
                foreach (var id in idAziende)
                {
                    try
                    {
                        var credenziali = _configurationService.GetLoginInfo(id);
                        if (credenziali != null && !string.IsNullOrEmpty(credenziali.Value.Utente) && !string.IsNullOrEmpty(credenziali.Value.Password))
                        {
                            var success = false;
                            try
                            {
                                var resultUsers = userService.Login(credenziali.Value.Utente, credenziali.Value.Password, null);
                                success = resultUsers.success;
                            }
                            catch (Exception ex)
                            {
                                _log.WarnFormat("Errore durante il controllo delle credenziali - {0} - username:{1} - password:{2} - azienda:{3}", ex, Library.Utility.GetMethodDescription(), credenziali.Value.Utente, credenziali.Value.Password, Security.Login.Instance.CurrentLogin().Azienda);
                            }
                            if (success)
                            {
                                var date = getDataInizialeFinale(idMessaggi);
                                var dataIniziale = date[0];
                                var dataFinale = date[1];

                                var report = new it.emessage.reports.eMessageResultReportSms();
                                try
                                {
                                    report = service.GetSmsList(credenziali.Value.Utente, credenziali.Value.Password, dataIniziale, dataFinale, null);
                                }
                                catch (Exception ex)
                                {
                                    _log.ErrorFormat("Errore durante la lettura del report di invio degli sms - {0} - username:{1} - password:{2} - dataIniziale:{3} - dataFinale:{4} - azienda:{5}", ex, Library.Utility.GetMethodDescription(), credenziali.Value.Utente, credenziali.Value.Password, dataIniziale, dataFinale, id);
                                }

                                if (report != null && report.SmsList != null)
                                {
                                    foreach (var sms in report.SmsList)
                                    {
                                        try
                                        {
                                            var info = new InfoSpedizioneMessaggioDTO
                                            {
                                                CodiceMessaggio = sms.SmsCode,
                                                Costo = Convert.ToDecimal(sms.SmsCost),
                                                DataRicezione = sms.NotificationTime,
                                                Destinatario = new List<string> { sms.ParamTo },
                                                FineSpedizione = sms.JobFinished,
                                                InizioSpedizione = sms.JobInserted,
                                                Mittente = new List<string> { sms.ParamFrom },
                                                RisultatoSpedizione = sms.RetVal,
                                                StatoMessaggio = sms.NotificationStatus,
                                                TipoSpedizione = sms.Quality.ToString(),
                                                NumeroMessaggi = sms.NumberOfSms
                                            };

                                            if (idMessaggi != null && idMessaggi.Count > 0)
                                            {
                                                var messaggi = getMessaggi(idMessaggi);
                                                var messaggio = messaggi.FirstOrDefault(item => item.CodiceMessaggio == sms.SmsCode || item.CodiceInvio == sms.NotificationCode);
                                                if (messaggio != null)
                                                    info.Id = messaggio.ID;
                                            }
                                            else
                                            {
                                                if (!string.IsNullOrEmpty(sms.SmsCode) && !string.IsNullOrEmpty(sms.SmsCode.Trim()))
                                                {
                                                    var messaggi = _daoFactory.GetStoricoMessaggioDao().GetByCodiceMessaggio(sms.SmsCode);
                                                    if (!string.IsNullOrEmpty(sms.NotificationCode))
                                                    {
                                                        var messaggiByCodiceInvio = _daoFactory.GetStoricoMessaggioDao().GetByCodiceInvio(sms.NotificationCode);
                                                        foreach (var storicoMessaggio in messaggiByCodiceInvio)
                                                            messaggi.Add(storicoMessaggio);
                                                    }
                                                    foreach (var storicoMessaggio in messaggi)
                                                    {
                                                        storicoMessaggio.Costo = Convert.ToDecimal(sms.SmsCost);
                                                        storicoMessaggio.Quantita = sms.NumberOfSms;
                                                        storicoMessaggio.DataElaborazione = sms.JobFinished;
                                                        storicoMessaggio.DataRicezione = sms.NotificationTime;
                                                        if (!string.IsNullOrEmpty(sms.RetVal))
                                                        {
                                                            if (sms.RetVal.StartsWith("OK"))
                                                                storicoMessaggio.Stato = StatoMessaggio.Ricevuto;
                                                            else if (sms.RetVal.StartsWith("KO"))
                                                                storicoMessaggio.Stato = StatoMessaggio.Fallito;
                                                        }
                                                    }
                                                }
                                            }

                                            result.Add(info);

                                        }
                                        catch (Exception ex)
                                        {
                                            _log.ErrorFormat("Errore inaspettato durante il controllo dello stato del messaggio - SINGOLO MESSSAGGIO - {0} - smsCode:{1} - notificationCode:{2} - azienda:{3}", ex, Library.Utility.GetMethodDescription(), sms.SmsCode, sms.NotificationCode, id);
                                            throw;
                                        }
                                    }                                    
                                }

                            }
                            else
                            {
                                _log.WarnFormat("Credenziali non valide - {0} - username:{1} - password:{2} - azienda:{3}", Library.Utility.GetMethodDescription(), credenziali.Value.Utente, credenziali.Value.Password, Security.Login.Instance.CurrentLogin().Azienda);
                            }
                        }

                    }
                    catch (Exception ex)
                    {
                        _log.ErrorFormat("Errore inaspettato durante il controllo dello stato del messaggio - SINGOLA AZIENDA - {0} - azienda:{1}", ex, Library.Utility.GetMethodDescription(), id);
                        throw;
                    }
                }

                return result;
            }
            catch (Exception ex)
            {
                _log.ErrorFormat("Errore inaspettato durante il controllo dello stato del messaggio - {0}", ex, Library.Utility.GetMethodDescription());
                throw;
            }
        }
        public IList<InfoSpedizioneMessaggioDTO> GetInfoMessaggio(int? idAzienda, IList<int> idMessaggi)
        {
            try
            {
                var result = new List<InfoSpedizioneMessaggioDTO>();
                var idAziende = new List<int>();
                if (idAzienda != null)
                    idAziende.Add(idAzienda.GetValueOrDefault());
                else
                {
                    var aziende = _daoFactory.GetAziendaDao().GetAll();
                    idAziende.AddRange(aziende.Select(azienda => azienda.ID));
                }

                var service = new Reports { Timeout = 999999999 };
                var userService = new it.emessage.users.Users();                
                foreach (var id in idAziende)
                {
                    var credenziali = _configurationService.GetLoginInfo(id);

                    if (credenziali != null && !string.IsNullOrEmpty(credenziali.Value.Utente) && !string.IsNullOrEmpty(credenziali.Value.Password))
                    {

                        var success = false;
                        try
                        {
                            var resultUsers = userService.Login(credenziali.Value.Utente, credenziali.Value.Password, null);
                            success = resultUsers.success;
                        }
                        catch (Exception ex)
                        {
                            _log.WarnFormat("Errore durante il controllo delle credenziali - {0} - username:{1} - password:{2} - azienda:{3}", ex, Library.Utility.GetMethodDescription(), credenziali.Value.Utente, credenziali.Value.Password, id);
                        }
                        if (success)
                        {
                            var date = getDataInizialeFinale(idMessaggi);
                            var dataIniziale = date[0];
                            var dataFinale = date[1];

                            eMessageResultReportLetter report;
                            try
                            {
                                report = service.GetLetterList(credenziali.Value.Utente, credenziali.Value.Password, dataIniziale, dataFinale, null);
                            }
                            catch (System.Web.Services.Protocols.SoapException ex)
                            {
                                _log.WarnFormat("Errore nella lettura del report - {0} - utente:{1} - password:{2} - dataIniziale:{3} - dataFinale:{4} - azienda:{5}", ex, Library.Utility.GetMethodDescription(), credenziali.Value.Utente, credenziali.Value.Password, dataIniziale, dataFinale, id);
                                continue;
                            }
                            catch (Exception ex)
                            {
                                _log.ErrorFormat("Errore nella lettura del report - {0} - utente:{1} - password:{2} - dataIniziale:{3} - dataFinale:{4} - azienbda:{5}", ex, Library.Utility.GetMethodDescription(), credenziali.Value.Utente, credenziali.Value.Password, dataIniziale, dataFinale, id);
                                throw;
                            }
                            
                            foreach (var letter in report.LetterList)
                            {
                                try
                                {
                                    var info = new InfoSpedizioneMessaggioDTO
                                    {
                                        CodiceMessaggio = letter.LetterCode,
                                        CodiceInvio = letter.JobCode,
                                        Costo = Convert.ToDecimal(letter.ServicePrice),
                                        CostoFisso = Convert.ToDecimal(letter.StampPrice),
                                        Destinatario = getIndirizzo(letter.ParamTo, new[] { "to/contatto", "to" }),
                                        DataRicezione = letter.JobDeliveredToPT,
                                        FineSpedizione = letter.JobReady,
                                        InizioSpedizione = letter.JobInserted,
                                        Mittente = getIndirizzo(letter.ParamFrom, new[] { "from/contatto", "from" }),
                                        RisultatoSpedizione = letter.RetVal,
                                        TipoSpedizione = letter.StampType.ToString(),
                                        NumeroMessaggi = letter.NumbersOfPages,
                                        NumeroSpedizioni = letter.NumbersOfLetters
                                    };

                                    if (idMessaggi != null && idMessaggi.Count > 0)
                                    {
                                        var messaggi = getMessaggi(idMessaggi);
                                        var messaggio = messaggi.FirstOrDefault(item => item.CodiceMessaggio == letter.LetterCode || item.CodiceInvio == letter.JobCode);
                                        if (messaggio != null)
                                            info.Id = messaggio.ID;
                                    }
                                    else
                                    {
                                        if (!string.IsNullOrEmpty(letter.LetterCode) && !string.IsNullOrEmpty(letter.LetterCode.Trim()))
                                        {
                                            var messaggio = _daoFactory.GetStoricoMessaggioDao().GetByCodiceMessaggio(letter.LetterCode).Count > 0 ? _daoFactory.GetStoricoMessaggioDao().GetByCodiceMessaggio(letter.LetterCode) : _daoFactory.GetStoricoMessaggioDao().GetByCodiceInvio(letter.JobCode);
                                            foreach (var storicoMessaggio in messaggio)
                                            {
                                                try
                                                {
                                                    storicoMessaggio.Costo = Convert.ToDecimal(letter.ServicePrice);
                                                    storicoMessaggio.CostoFisso = Convert.ToDecimal(letter.StampPrice);
                                                    storicoMessaggio.Quantita = letter.NumbersOfLetters;
                                                    storicoMessaggio.DataElaborazione = letter.JobReady;
                                                    storicoMessaggio.DataRicezione = letter.JobDeliveredToPT;
                                                    if (!string.IsNullOrEmpty(letter.RetVal))
                                                    {
                                                        if (letter.RetVal.StartsWith("OK"))
                                                            storicoMessaggio.Stato = StatoMessaggio.Ricevuto;
                                                        else if (letter.RetVal.StartsWith("KO"))
                                                            storicoMessaggio.Stato = StatoMessaggio.Fallito;
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    _log.ErrorFormat("Errore nell'aggiornamento del messaggio - SINGOLO MESSAGGIO - {0} - id:{1}", ex, Library.Utility.GetMethodDescription(), storicoMessaggio.ID);
                                                    throw;
                                                }
                                            }
                                        }
                                    }

                                    result.Add(info);

                                }
                                catch (Exception ex)
                                {
                                    _log.ErrorFormat("Errore nell'aggiornamento del messaggio - SINGOLA LETTERA - {0} - letter:{1} - jobcode:{2}", ex, Library.Utility.GetMethodDescription(), letter.LetterCode, letter.JobCode);
                                    throw;
                                }
                            }
                        }
                        else
                        {
                            _log.WarnFormat("Credenziali non valide - {0} - username:{1} - password:{2}", Library.Utility.GetMethodDescription(), credenziali.Value.Utente, credenziali.Value.Password);
                        }
                    }
                }

                return result;
            }
            catch (Exception ex)
            {
                _log.ErrorFormat("Errore inaspettato durante il controllo dello stato del messaggio - {0}", ex, Library.Utility.GetMethodDescription());
                throw;
            }
        }
Beispiel #5
0
        public IList<InfoSpedizioneMessaggioDTO> GetInfoMessaggio(int? idAzienda, IList<int> idMessaggi)
        {
            try
            {
                var result = new List<InfoSpedizioneMessaggioDTO>();
                var messaggi = _daoFactory.GetStoricoMessaggioDao().GetByTipoIdentificativi(idMessaggi, TipoMessaggio.Email);
                if (messaggi.Count > 0)
                {
                    var references = messaggi.Select(item => item.CodiceMessaggio).ToList();
                    var deliveryMessages = _daoFactory.GetDeliveryMessagePoDao().GetByReferenceId(references);
                    foreach (var deliveryMessagePo in deliveryMessages)
                    {
                        try
                        {
                            var info = new InfoSpedizioneMessaggioDTO
                            {
                                CodiceInvio = deliveryMessagePo.ReferenceId,
                                CodiceMessaggio = deliveryMessagePo.ReferenceId,
                                InizioSpedizione = deliveryMessagePo.SendingDate,
                                FineSpedizione = deliveryMessagePo.SendingDate,
                                Destinatario = new[] {
                                    $"{deliveryMessagePo.RecipientName} ({deliveryMessagePo.RecipientEmail})"
                                },
                                RisultatoSpedizione = !string.IsNullOrEmpty(deliveryMessagePo.Smtp) ?
                                    $"Spedito tramite smtp: {deliveryMessagePo.Smtp} il {deliveryMessagePo.SendingDate} - tentativo:{deliveryMessagePo.AttemptNumber}"
                                    : deliveryMessagePo.Exception
                            };

                            result.Add(info);

                            var messaggio = messaggi.SingleOrDefault(item => item.CodiceMessaggio == deliveryMessagePo.ReferenceId);
                            if (messaggio != null)
                            {
                                info.Id = messaggio.ID;
                                info.NumeroMittente = messaggio.Mittente;
                                info.Mittente = new []{ messaggio.Mittente};
                                info.Destinatario = new[] {
                                    $"{deliveryMessagePo.RecipientName} ({deliveryMessagePo.RecipientEmail})"
                                };
                                if (deliveryMessagePo.SendingDate != null)
                                {
                                    if (messaggio.Stato != StatoMessaggio.Ricevuto)
                                    {
                                        messaggio.Stato = StatoMessaggio.Spedito;
                                    }
                                    messaggio.DataElaborazione = deliveryMessagePo.SendingDate.Value;
                                }
                                else if (((DeliveryPo)deliveryMessagePo.Delivery).State == StatoDelivery.Bloccato)
                                {
                                    messaggio.Stato = StatoMessaggio.Fallito;
                                    messaggio.DataElaborazione = deliveryMessagePo.SendingDate != null ? deliveryMessagePo.SendingDate.GetValueOrDefault() : ((DeliveryPo)deliveryMessagePo.Delivery).EndSendingDate.GetValueOrDefault();
                                }

                                info.DataRicezione = messaggio.DataRicezione;
                                info.StatoMessaggio = messaggio.Stato.ToString();
                            }
                        }
                        catch (Exception ex)
                        {
                            _log.ErrorFormat("Errore nel controllo delle info email- SINGOLO MESSAGGIO - {0} - messaggio:{1} - azienda:{2}", ex, Utility.GetMethodDescription(), deliveryMessagePo.Id, idAzienda);
                            throw;
                        }
                    }
                }

                return result;
            }
            catch (Exception ex)
            {
                _log.ErrorFormat("Errore nel controllo delle info email - {0} - azienda:{1}", ex, Utility.GetMethodDescription(), idAzienda);                
                throw;
            }
        }