Exemplo n.º 1
0
        internal static Model.ContactsApplicationMapping MapToContactsApplication(System.Data.Common.DbDataReader dr)
        {
            ContactsApplicationMapping cam = new ContactsApplicationMapping();

            cam.IdMap               = (long)dr.GetDecimal("ID_MAP");
            cam.IdTitolo            = (long)dr.GetDecimal("ID_TITOLO");
            cam.AppCode             = dr.GetString("APP_CODE");
            cam.Titolo              = dr.GetString("TITOLO");
            cam.TitoloCode          = dr.GetString("TITOLO_PROT_CODE");
            cam.IsTitoloActive      = Convert.ToBoolean(dr.GetDecimal("TITOLO_ACTIVE"));
            cam.IdSottotitolo       = (long)dr.GetDecimal("ID_SOTTOTITOLO");
            cam.Sottotitolo         = dr.GetString("SOTTOTITOLO");
            cam.SottotitoloCode     = dr.GetString("SOTTOTITOLO_PROT_CODE");
            cam.IsSottotitoloActive = Convert.ToBoolean(dr.GetDecimal("SOTTOTITOLO_ACTIVE"));
            cam.ComCode             = dr.GetString("COM_CODE");
            cam.IdContact           = (long)dr.GetDecimal("ID_CONTACT");
            cam.Mail          = dr.GetString("MAIL");
            cam.Fax           = dr.GetString("FAX");
            cam.Telefono      = dr.GetString("TELEFONO");
            cam.RefIdReferral = (long)dr.GetDecimal("REF_ID_REFERRAL");
            cam.IsPec         = Convert.ToBoolean(dr.GetDecimal("FLG_PEC"));
            cam.RefOrg        = (long)dr.GetDecimal("REF_ORG");
            cam.IdCanale      = (long)dr.GetDecimal("ID_CANALE");
            cam.Codice        = dr.GetString("CODICE");
            cam.IdBackend     = (long)dr.GetDecimal("ID_BACKEND");
            cam.BackendCode   = dr.GetString("BACKEND_CODE");
            cam.BackendDescr  = dr.GetString("BACKEND_DESCR");
            cam.Category      = dr.GetString("CATEGORY");
            cam.DescrPlus     = dr.GetString("DESCR_PLUS");
            return(cam);
        }
Exemplo n.º 2
0
        public ContactsApplicationMapping GetById(long id)
        {
            ContactsApplicationMapping app = null;

            try
            {
                using (var dbcontext = new FAXPECContext())
                {
                    var v = dbcontext.V_MAP_APPL_CONTATTI_NEW.Where(x => x.ID_MAP == id).First();
                    if (v != null)
                    {
                        app = AutoMapperConfiguration.MapToContactsApplicationModel(v);
                    }
                }
            }
            catch (Exception ex)
            {
                if (!ex.GetType().Equals(typeof(ManagedException)))
                {
                    ManagedException mEx = new ManagedException(ex.Message,
                                                                "ORA_ERR008", string.Empty, string.Empty, ex);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);
                    err.objectID = Convert.ToString(id);
                    _log.Error(err);
                    throw mEx;
                }
                else
                {
                    throw ex;
                }
            }
            return(app);
        }
Exemplo n.º 3
0
 private OracleParameter[] MapToOracleParameter(ContactsApplicationMapping map)
 {
     OracleParameter[] pars = new OracleParameter[4];
     pars[0] = new OracleParameter("pID_CANALE", OracleDbType.Decimal, map.IdCanale, ParameterDirection.Input);
     pars[1] = new OracleParameter("pID_BACKEND", OracleDbType.Decimal, map.IdBackend, ParameterDirection.Input);
     pars[2] = new OracleParameter("pID_CONTATTO", OracleDbType.Decimal, map.IdContact, ParameterDirection.Input);
     pars[3] = new OracleParameter("pID_TITOLO", OracleDbType.Decimal, map.IdTitolo, ParameterDirection.Input);
     return(pars);
 }
Exemplo n.º 4
0
 private ObjectParameter[] MapToOracleParameter(ContactsApplicationMapping map)
 {
     ObjectParameter[] pars = new ObjectParameter[4];
     pars[0] = new ObjectParameter("pID_CANALE", map.IdCanale);
     pars[1] = new ObjectParameter("pID_BACKEND", map.IdBackend);
     pars[2] = new ObjectParameter("pID_CONTATTO", map.IdContact);
     pars[3] = new ObjectParameter("pID_TITOLO", map.IdTitolo);
     return(pars);
 }
Exemplo n.º 5
0
        public ICollection <ContactsApplicationMapping> FindByDatiGenerici(ContactsApplicationMapping contact)
        {
            List <ContactsApplicationMapping> listContacts = null;

            using (IContactsApplicationMappingDao dao = getDaoContext().DaoImpl.ContactsApplicationMappingDao)
            {
                listContacts = (List <ContactsApplicationMapping>)dao.GetContactsByCriteria(BuildQueryByData(contact));
            }
            return(listContacts);
        }
Exemplo n.º 6
0
        public ICollection <ContactsApplicationMapping> FindByDatiGenerici(ContactsApplicationMapping contact)
        {
            List <ContactsApplicationMapping> listContacts = null;

            using (ContactsApplicationMappingSQLDb dao = new ContactsApplicationMappingSQLDb())
            {
                listContacts = (List <ContactsApplicationMapping>)dao.GetContactsByCriteria(BuildQueryByData(contact));
            }
            return(listContacts);
        }
Exemplo n.º 7
0
        public void Update(ContactsApplicationMapping entity)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("UPDATE RUBR_CONTATTI_BACKEND");
            sb.Append(" SET REF_ID_CANALE = :pID_CANALE");
            sb.Append(", REF_ID_BACKEND = :pID_BACKEND");
            sb.Append(", REF_ID_CONTATTO = :pID_CONTATTO");
            sb.Append(", REF_ID_TITOLO = :pID_TITOLO");
            sb.Append(" WHERE ID_MAP = :pID_MAP");

            try
            {
                using (OracleCommand cmd = CurrentConnection.CreateCommand())
                {
                    cmd.CommandText = sb.ToString();
                    cmd.BindByName  = true;
                    cmd.Parameters.AddRange(MapToOracleParameter(entity));
                    cmd.Parameters.Add("pID_MAP", OracleDbType.Decimal, entity.IdMap, ParameterDirection.Input);
                    int risp = cmd.ExecuteNonQuery();
                    if (risp != 1)
                    {
                        throw new InvalidOperationException("Aggiornamento non effettuato");
                    }
                }
            }
            catch (Exception ex)
            {
                //TASK: Allineamento log - Ciro
                if (!ex.GetType().Equals(typeof(ManagedException)))
                {
                    ManagedException mEx = new ManagedException(ex.Message,
                                                                "ORA_ERR009", string.Empty, string.Empty, ex);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);
                    err.objectID = Convert.ToString(entity.RefIdReferral);
                    _log.Error(err);
                    throw mEx;
                }
                else
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 8
0
        private SingleClause BuildSingleClause(ContactsApplicationMapping c, PropertyInfo pi)
        {
            SingleClause sc = new SingleClause();

            object[] pa = pi.GetCustomAttributes(typeof(DatabaseFieldAttribute), true);
            if (pa != null && pa.Length == 1)
            {
                DatabaseFieldAttribute dba = (DatabaseFieldAttribute)(pa[0]);
                if (dba != null && dba.FieldName.Length > 0)
                {
                    sc.PropertyName = dba.FieldName;
                }
            }

            sc.Value = pi.GetValue(c, null);

            switch (sc.PropertyName)
            {
            case "APP_CODE":
            case "MAIL":
            case "FAX":
            case "TELEFONO":
            case "CODICE":
            case "BACKEND_CODE":
            case "CATEGORY":
            case "COM_CODE":
            case "SOTTOTITOLO_ACTIVE":
            case "TITOLO_ACTIVE":
                sc.Operator = CriteriaOperator.Equal;
                break;

            case "CONTACT_REF":
                sc.Operator = CriteriaOperator.StartsWith;
                break;

            case "BACKEND_DESCR":
            case "DESCR_PLUS":
                sc.Operator = CriteriaOperator.Like;
                break;
            }

            return(sc);
        }
Exemplo n.º 9
0
        public void Insert(ContactsApplicationMapping entity)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("INSERT INTO RUBR_CONTATTI_BACKEND(");
            sb.Append("REF_ID_CANALE, REF_ID_BACKEND, REF_ID_CONTATTO, REF_ID_TITOLO");
            sb.Append(") VALUES (");
            sb.Append(":pID_CANALE, :pID_BACKEND, :pID_CONTATTO, :pID_TITOLO");
            sb.Append(")");
            sb.Append(" RETURNING ID_MAP INTO :pID_MAP");
            try
            {
                using (OracleCommand cmd = CurrentConnection.CreateCommand())
                {
                    cmd.CommandText = sb.ToString();
                    cmd.BindByName  = true;
                    cmd.Parameters.AddRange(MapToOracleParameter(entity));
                    cmd.Parameters.Add("pID_MAP", OracleDbType.Decimal, ParameterDirection.Output);
                    int risp = cmd.ExecuteNonQuery();
                    if (risp == 1)
                    {
                        entity.IdMap = (long)cmd.Parameters["pID_MAP"].Value;
                    }
                }
            }
            catch (Exception ex)
            {
                //TASK: Allineamento log - Ciro
                if (!ex.GetType().Equals(typeof(ManagedException)))
                {
                    ManagedException mEx = new ManagedException(ex.Message,
                                                                "ORA_ERR009", string.Empty, string.Empty, ex);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);
                    err.objectID = Convert.ToString(entity.RefIdReferral);
                    _log.Error(err);
                    throw mEx;
                }
                else
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 10
0
 public void Update(ContactsApplicationMapping entity)
 {
     try
     {
         using (var dbcontext = new FAXPECContext())
         {
             RUBR_CONTATTI_BACKEND vold = dbcontext.RUBR_CONTATTI_BACKEND.Where(x => x.ID_MAP == entity.IdMap).First();
             if (vold != null)
             {
                 vold.REF_ID_CANALE   = (int)entity.IdCanale;
                 vold.REF_ID_BACKEND  = (int)entity.IdBackend;
                 vold.REF_ID_CONTATTO = (int)entity.IdContact;
                 vold.REF_ID_TITOLO   = (int)entity.IdSottotitolo;
             }
             int risp = dbcontext.SaveChanges();
             if (risp != 1)
             {
                 throw new InvalidOperationException("Aggiornamento non effettuato");
             }
         }
     }
     catch (Exception ex)
     {
         if (!ex.GetType().Equals(typeof(ManagedException)))
         {
             ManagedException mEx = new ManagedException(ex.Message,
                                                         "ORA_ERR009", string.Empty, string.Empty, ex);
             ErrorLogInfo err = new ErrorLogInfo(mEx);
             err.objectID = Convert.ToString(entity.RefIdReferral);
             _log.Error(err);
             throw mEx;
         }
         else
         {
             throw ex;
         }
     }
 }
Exemplo n.º 11
0
        public void Insert(ContactsApplicationMapping entity)
        {
            int risp = 0;

            try
            {
                using (var dbcontext = new FAXPECContext())
                {
                    RUBR_CONTATTI_BACKEND r = new RUBR_CONTATTI_BACKEND();
                    r.REF_ID_CANALE   = (int)entity.IdCanale;
                    r.REF_ID_BACKEND  = (int)entity.IdBackend;
                    r.REF_ID_CONTATTO = (int)entity.IdContact;
                    r.REF_ID_TITOLO   = (int)entity.IdTitolo;
                    dbcontext.RUBR_CONTATTI_BACKEND.Add(r);
                    risp = dbcontext.SaveChanges();
                    if (risp == 1)
                    {
                        entity.IdMap = (long)r.ID_MAP;
                    }
                }
            }
            catch (Exception ex)
            {
                if (!ex.GetType().Equals(typeof(ManagedException)))
                {
                    ManagedException mEx = new ManagedException(ex.Message,
                                                                "ORA_ERR009", string.Empty, string.Empty, ex);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);
                    err.objectID = Convert.ToString(entity.RefIdReferral);
                    _log.Error(err);
                    throw mEx;
                }
                else
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 12
0
        public HttpResponseMessage Comunicazione(FormDataCollection formsValues)
        {
            string      regexMail = RegexUtils.EMAIL_REGEX.ToString();
            TitoliModel model     = new TitoliModel();

            try
            {
                List <ComAllegato> allegati = new List <ComAllegato>();
                SendMail.Model.ComunicazioniMapping.Comunicazioni comun = new SendMail.Model.ComunicazioniMapping.Comunicazioni();
                string destinatario = formsValues["Destinatario"];
                string conoscenza   = formsValues["Conoscenza"];
                string bcc          = formsValues["BCC"];
                string oggetto      = formsValues["Oggetto"];
                string testoMail    = formsValues["TestoMail"];
                string titolo       = formsValues["Titolo"];
                string sottotitolo  = formsValues["SottoTitolo"];
                string userid       = formsValues["SenderMail"];
                if (SessionManager <Dictionary <string, DTOFileUploadResult> > .exist(SessionKeys.DTO_FILE))
                {
                    Dictionary <string, DTOFileUploadResult> dictDto = SessionManager <Dictionary <string, DTOFileUploadResult> > .get(SessionKeys.DTO_FILE);

                    List <DTOFileUploadResult> dto = (List <DTOFileUploadResult>)dictDto.Values.ToList();
                    foreach (DTOFileUploadResult d in dto)
                    {
                        SendMail.Model.ComunicazioniMapping.ComAllegato allegato = new SendMail.Model.ComunicazioniMapping.ComAllegato();
                        allegato.AllegatoExt  = d.Extension;
                        allegato.AllegatoFile = d.CustomData;
                        allegato.AllegatoName = d.FileName;
                        allegato.AllegatoTpu  = "";
                        allegato.FlgInsProt   = AllegatoProtocolloStatus.FALSE;
                        allegato.FlgProtToUpl = AllegatoProtocolloStatus.FALSE;
                        allegati.Add(allegato);
                    }
                }
                comun.ComAllegati = allegati;
                string[] destinatari = destinatario.Split(';');
                for (int i = 0; i < destinatari.Length; i++)
                {
                    var match = Regex.Match(destinatari[i], regexMail, RegexOptions.IgnoreCase);
                    if (!match.Success)
                    {
                        model.success = "false";
                        model.message = "Attenzione mail destinatario non valida";
                        return(this.Request.CreateResponse <TitoliModel>(HttpStatusCode.OK, model));
                    }
                }
                // gestione destinatari
                ContactsApplicationMapping c = new ContactsApplicationMapping
                {
                    Mail          = destinatario,
                    IdSottotitolo = long.Parse(sottotitolo),
                    IdTitolo      = long.Parse(titolo)
                };
                Collection <ContactsApplicationMapping> en = new Collection <ContactsApplicationMapping>();
                en.Add(c);
                if (conoscenza != string.Empty)
                {
                    string[] conoscenze = conoscenza.Split(';');
                    for (int i = 0; i < conoscenze.Length; i++)
                    {
                        var match = Regex.Match(conoscenze[i], regexMail, RegexOptions.IgnoreCase);
                        if (!match.Success)
                        {
                            model.success = "false";
                            model.message = "Attenzione mail conoscenza non valida";
                            return(this.Request.CreateResponse <TitoliModel>(HttpStatusCode.OK, model));
                        }
                    }
                    ContactsApplicationMapping c1 = new ContactsApplicationMapping
                    {
                        Mail          = conoscenza,
                        IdSottotitolo = long.Parse(sottotitolo),
                        IdTitolo      = long.Parse(titolo)
                    };
                    Collection <ContactsApplicationMapping> en1 = new Collection <ContactsApplicationMapping>();
                    en1.Add(c1);
                    comun.SetMailDestinatari(en1, AddresseeType.CC);
                }
                if (bcc != string.Empty)
                {
                    string[] bccs = bcc.Split(';');
                    for (int i = 0; i < bcc.Length; i++)
                    {
                        var match = Regex.Match(bccs[i], regexMail, RegexOptions.IgnoreCase);
                        if (!match.Success)
                        {
                            model.success = "false";
                            model.message = "Attenzione mail destinatario nascosto non valido";
                            return(this.Request.CreateResponse <TitoliModel>(HttpStatusCode.OK, model));
                        }
                    }

                    ContactsApplicationMapping c2 = new ContactsApplicationMapping
                    {
                        Mail          = bcc,
                        IdSottotitolo = long.Parse(sottotitolo),
                        IdTitolo      = long.Parse(titolo)
                    };
                    Collection <ContactsApplicationMapping> en2 = new Collection <ContactsApplicationMapping>();
                    en2.Add(c2);
                    comun.SetMailDestinatari(en2, AddresseeType.CCN);
                }
                comun.SetMailDestinatari(en, AddresseeType.TO);
                // gestione body email
                MailContent content = new MailContent();
                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                string html = testoMail;
                HtmlAgilityPack.HtmlNode body = null;
                if (string.IsNullOrEmpty(html) == false)
                {
                    doc.LoadHtml(html);
                    doc.OptionAutoCloseOnEnd = true;
                    doc.OptionFixNestedTags  = true;
                    body = doc.DocumentNode.Descendants()
                           .Where(n => n.Name.Equals("body", StringComparison.InvariantCultureIgnoreCase))
                           .FirstOrDefault();
                }
                var ele = new HtmlAgilityPack.HtmlNode(HtmlAgilityPack.HtmlNodeType.Element, doc, 0);
                ele.Name            = "div";
                ele.InnerHtml       = testoMail;
                content.MailSubject = oggetto;
                content.MailText    = ele.OuterHtml;
                // gestione sender
                MailServerConfigFacade mailSCF = MailServerConfigFacade.GetInstance();
                MailUser mailuser = mailSCF.GetUserByUserId(decimal.Parse(userid));
                content.MailSender      = mailuser.EmailAddress;
                c.IdTitolo              = long.Parse(titolo);
                c.IdSottotitolo         = long.Parse(sottotitolo);
                comun.UtenteInserimento = MySecurityProvider.CurrentPrincipal.MyIdentity.UserName;
                comun.MailComunicazione = content;
                // da scommentare
                comun.FolderTipo = "O";
                comun.FolderId   = 2;
                ComunicazioniService com = new ComunicazioniService();
                com.InsertComunicazione(comun);
                model.success = "true";
                SessionManager <Dictionary <string, DTOFileUploadResult> > .del(SessionKeys.DTO_FILE);
            }
            catch (Exception ex)
            {
                if (ex.GetType() != typeof(ManagedException))
                {
                    ManagedException mEx = new ManagedException("Errore invio nuova mail. Dettaglio: " + ex.Message +
                                                                "StackTrace: " + ((ex.StackTrace != null) ? ex.StackTrace.ToString() : " vuoto "),
                                                                "ERR317",
                                                                string.Empty,
                                                                string.Empty,
                                                                ex.InnerException);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);
                    log.Error(err);
                    model.success = "false";
                    model.message = ex.Message;
                    return(this.Request.CreateResponse <TitoliModel>(HttpStatusCode.OK, model));
                }
            }
            return(this.Request.CreateResponse <TitoliModel>(HttpStatusCode.OK, model));
        }
Exemplo n.º 13
0
        private QueryCmp BuildQueryByData(ContactsApplicationMapping contact)
        {
            QueryCmp q = new QueryCmp();
            //prendo tutte le properties mappate su database
            IEnumerable <PropertyInfo> pi = contact.GetType()
                                            .GetProperties(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public)
                                            .Where(x => (x.GetCustomAttributes(typeof(DatabaseFieldAttribute), true) != null &&
                                                         x.GetCustomAttributes(typeof(DatabaseFieldAttribute), true).Length > 0));

            if (pi.All(x =>
            {
                Type pt = x.PropertyType;
                if (pt.IsValueType)
                {
                    return(x.GetValue(contact, null).Equals(Activator.CreateInstance(pt)));
                }
                else
                {
                    return(x.GetValue(contact, null) == null);
                }
            }))
            {
                return(q);
            }

            var validProps = pi.Where(x =>
            {
                Type pt = x.PropertyType;
                if (pt.IsValueType)
                {
                    return(!x.GetValue(contact, null).Equals(Activator.CreateInstance(pt)));
                }
                else
                {
                    return(x.GetValue(contact, null) != null);
                }
            });

            CombinedClause cc = new CombinedClause();

            q.WhereClause = cc;
            List <IClause> lc = new List <IClause>();

            cc.SubClauses = lc;

            if (validProps.Count() == 1)
            {
                cc.ClauseType = QueryOperator.Or;
                lc.Add(BuildSingleClause(contact, validProps.Single()));
                lc.Add(BuildNullClause(validProps.Single()));
            }
            else
            {
                cc.ClauseType = QueryOperator.And;
                foreach (var p in validProps)
                {
                    CombinedClause cc0 = new CombinedClause();
                    cc0.ClauseType = QueryOperator.Or;
                    List <IClause> lc0 = new List <IClause>();
                    cc0.SubClauses = lc0;
                    lc0.Add(BuildSingleClause(contact, p));
                    lc0.Add(BuildNullClause(p));
                    lc.Add(cc0);
                }
            }

            return(q);
        }
Exemplo n.º 14
0
        protected void btnSend_OnClick(object sender, EventArgs e)
        {
            if (HeaderNew.DestinatarioSelected != null && HeaderNew.DestinatarioSelected.Length > 0)
            {
                if (HeaderNew.SottoTitoloSelected != string.Empty && HeaderNew.TitoloSelected != "-- Selezionare un titolo --" && HeaderNew.SottoTitoloSelected.Length > 0)
                {
                    try
                    {
                        SendMail.Model.ComunicazioniMapping.Comunicazioni comun = new SendMail.Model.ComunicazioniMapping.Comunicazioni();
                        // gestione allegati
                        List <ComAllegato> allegati = new List <ComAllegato>();
                        if (SessionManager <Dictionary <string, DTOFileUploadResult> > .exist(SessionKeys.DTO_FILE))
                        {
                            Dictionary <string, DTOFileUploadResult> dictDto = SessionManager <Dictionary <string, DTOFileUploadResult> > .get(SessionKeys.DTO_FILE);

                            List <DTOFileUploadResult> dto = (List <DTOFileUploadResult>)dictDto.Values.ToList();
                            foreach (DTOFileUploadResult d in dto)
                            {
                                SendMail.Model.ComunicazioniMapping.ComAllegato allegato = new SendMail.Model.ComunicazioniMapping.ComAllegato();
                                allegato.AllegatoExt  = d.Extension;
                                allegato.AllegatoFile = d.CustomData;
                                allegato.AllegatoName = d.FileName;
                                allegato.AllegatoTpu  = "";
                                allegato.FlgInsProt   = AllegatoProtocolloStatus.FALSE;
                                allegato.FlgProtToUpl = AllegatoProtocolloStatus.FALSE;
                                allegati.Add(allegato);
                            }
                        }

                        comun.ComAllegati = allegati;
                        string[] destinatari = HeaderNew.DestinatarioSelected.Split(';');
                        for (int i = 0; i < destinatari.Length; i++)
                        {
                            var match = Regex.Match(destinatari[i], regexMail, RegexOptions.IgnoreCase);
                            if (!match.Success)
                            {
                                ((BasePage)this.Page).info.AddMessage("Attenzione mail destinatario non valida ", LivelloMessaggio.ERROR);
                                return;
                            }
                        }
                        // gestione destinatari
                        ContactsApplicationMapping c = new ContactsApplicationMapping
                        {
                            Mail          = HeaderNew.DestinatarioSelected,
                            IdSottotitolo = long.Parse(HeaderNew.SottoTitoloSelected),
                            IdTitolo      = long.Parse(HeaderNew.TitoloSelected)
                        };
                        Collection <ContactsApplicationMapping> en = new Collection <ContactsApplicationMapping>();
                        en.Add(c);
                        if (HeaderNew.ConoscenzaSelected != string.Empty)
                        {
                            string[] conoscenze = HeaderNew.ConoscenzaSelected.Split(';');
                            for (int i = 0; i < conoscenze.Length; i++)
                            {
                                var match = Regex.Match(conoscenze[i], regexMail, RegexOptions.IgnoreCase);
                                if (!match.Success)
                                {
                                    ((BasePage)this.Page).info.AddMessage("Attenzione mail conoscenza non valida ", LivelloMessaggio.ERROR);
                                    return;
                                }
                            }
                            ContactsApplicationMapping c1 = new ContactsApplicationMapping
                            {
                                Mail          = HeaderNew.ConoscenzaSelected,
                                IdSottotitolo = long.Parse(HeaderNew.SottoTitoloSelected),
                                IdTitolo      = long.Parse(HeaderNew.TitoloSelected)
                            };
                            Collection <ContactsApplicationMapping> en1 = new Collection <ContactsApplicationMapping>();
                            en1.Add(c1);
                            comun.SetMailDestinatari(en1, AddresseeType.CC);
                        }
                        if (HeaderNew.BCCSelected != string.Empty)
                        {
                            string[] bcc = HeaderNew.BCCSelected.Split(';');
                            for (int i = 0; i < bcc.Length; i++)
                            {
                                var match = Regex.Match(bcc[i], regexMail, RegexOptions.IgnoreCase);
                                if (!match.Success)
                                {
                                    ((BasePage)this.Page).info.AddMessage("Attenzione mail BCC non valida ", LivelloMessaggio.ERROR);
                                    return;
                                }
                            }

                            ContactsApplicationMapping c2 = new ContactsApplicationMapping
                            {
                                Mail          = HeaderNew.BCCSelected,
                                IdSottotitolo = long.Parse(HeaderNew.SottoTitoloSelected),
                                IdTitolo      = long.Parse(HeaderNew.TitoloSelected)
                            };
                            Collection <ContactsApplicationMapping> en2 = new Collection <ContactsApplicationMapping>();
                            en2.Add(c2);
                            comun.SetMailDestinatari(en2, AddresseeType.CCN);
                        }
                        comun.SetMailDestinatari(en, AddresseeType.TO);
                        // gestione body email
                        MailContent content = new MailContent();
                        HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                        string html = CacheManager <XmlDocument> .EmptyHtml;
                        HtmlAgilityPack.HtmlNode body = null;
                        if (string.IsNullOrEmpty(html) == false)
                        {
                            doc.LoadHtml(html);
                            doc.OptionAutoCloseOnEnd = true;
                            doc.OptionFixNestedTags  = true;
                            body = doc.DocumentNode.Descendants()
                                   .Where(n => n.Name.Equals("body", StringComparison.InvariantCultureIgnoreCase))
                                   .FirstOrDefault();
                        }
                        var ele = new HtmlAgilityPack.HtmlNode(HtmlAgilityPack.HtmlNodeType.Element, doc, 0);
                        ele.Name            = "div";
                        ele.InnerHtml       = HidHtml.Value;
                        content.MailSubject = HeaderNew.ObjectSelected;
                        content.MailText    = ele.OuterHtml;
                        // gestione sender
                        MailUser mailuser = WebMailClientManager.getAccount();
                        content.MailSender      = mailuser.EmailAddress;
                        c.IdTitolo              = long.Parse(HeaderNew.TitoloSelected);
                        c.IdSottotitolo         = long.Parse(HeaderNew.SottoTitoloSelected);
                        comun.UtenteInserimento = MySecurityProvider.CurrentPrincipal.MyIdentity.UserName;
                        comun.MailComunicazione = content;
                        // da scommentare
                        comun.FolderTipo = "O";
                        comun.FolderId   = 2;
                        ComunicazioniService com = new ComunicazioniService();
                        com.InsertComunicazione(comun);
                        // ((baseLayoutDelta.BasePage)this.Page).info.ClearMessage();
                        ((BasePage)this.Page).info.AddMessage("Email correttamente inviata", LivelloMessaggio.INFO);
                        btnSend.Visible = false;
                        SessionManager <Dictionary <string, DTOFileUploadResult> > .del(SessionKeys.DTO_FILE);
                    }
                    catch (Exception ex)
                    {
                        if (ex.GetType() != typeof(ManagedException))
                        {
                            ManagedException mEx = new ManagedException("Errore invio nuova mail. Dettaglio: " + ex.Message +
                                                                        "StackTrace: " + ((ex.StackTrace != null) ? ex.StackTrace.ToString() : " vuoto "),
                                                                        "ERR317",
                                                                        string.Empty,
                                                                        string.Empty,
                                                                        ex.InnerException);
                            ErrorLogInfo err = new ErrorLogInfo(mEx);
                            log.Error(err);
                        }
                        btnSend.Enabled = true;
                        ((BasePage)this.Page).info.AddMessage(/*error.logCode + */ " - Errore durante l'inserimento della mail:" + ex.Message, LivelloMessaggio.ERROR);
                    }
                    return;
                }
                ((BasePage)this.Page).info.AddMessage("Attenzione sottotitolo non selezionato ", LivelloMessaggio.ERROR);
                return;
            }
            else
            {
                ((BasePage)this.Page).info.AddMessage("Attenzione email destinatario non corretta ", LivelloMessaggio.ERROR);
                return;
            }
        }