public void Synchronize()
        {
            if (_communicationService != null)
            {
                CommunicationContactPart master = _communicationService.EnsureMasterContact();
                _transactionManager.RequireNew();

                // assegna un contact a ogni device
                int idmaster            = master.Id;
                var notificationrecords = _pushNotificationRepository.Fetch(x => x.Produzione && x.Validated).ToList();
                foreach (PushNotificationRecord rec in notificationrecords)
                {
                    rec.MobileContactPartRecord_Id = EnsureContactId(rec.UUIdentifier, idmaster);
                    _pushNotificationRepository.Update(rec);
                    _transactionManager.RequireNew();
                }
                _pushNotificationRepository.Flush();
                _notifier.Add(NotifyType.Information, T("Linked {0} device To Master contact", notificationrecords.Count().ToString()));
                string message = string.Format("Linked {0} device To Master contact", notificationrecords.Count().ToString());
                Logger.Log(OrchardLogging.LogLevel.Information, null, message, null);

                _transactionManager.RequireNew();

                // elimina gli userDevice riferiti a utenti inesistenti (perché cancellati)
                UserPart user = null;
                List <UserDeviceRecord> elencoUdr = _userDeviceRecord.Fetch(x => x.UserPartRecord.Id > 0).ToList();
                foreach (UserDeviceRecord udr in elencoUdr)
                {
                    user = _orchardServices.ContentManager.Get <UserPart>(udr.UserPartRecord.Id);
                    if (user == null)
                    {
                        _userDeviceRecord.Delete(udr);
                        _transactionManager.RequireNew();
                    }
                }
                _userDeviceRecord.Flush();
                _transactionManager.RequireNew();

                // elimina gli userDevice duplicati (con lo stesso UUIdentifier) e tiene il più recente (in base all'Id del record)
                string uuidPrecedente = "";
                elencoUdr = _userDeviceRecord.Fetch(x => x.UUIdentifier != null).OrderBy(y => y.UUIdentifier).OrderByDescending(z => z.Id).ToList();
                foreach (UserDeviceRecord udr in elencoUdr)
                {
                    if (udr.UUIdentifier == uuidPrecedente)
                    {
                        _userDeviceRecord.Delete(udr);
                        _transactionManager.RequireNew();
                    }
                    else
                    {
                        uuidPrecedente = udr.UUIdentifier;
                    }
                }
                _userDeviceRecord.Flush();
                _transactionManager.RequireNew();
            }
        }
Ejemplo n.º 2
0
        public CommunicationContactPart TryEnsureContact(int userId)
        {
            CommunicationContactPart contact = null;
            var user = _orchardServices.ContentManager.Get(userId).As <IUser>();

            if (user != null)
            {
                UserToContact(user);
                contact = GetContactFromUser(userId);
            }
            return(contact);
        }
Ejemplo n.º 3
0
 public void Synchronize()
 {
     #region lego tutti gli sms
     var alluser = _orchardServices.ContentManager.Query <UserPart, UserPartRecord>().Where(x => x.RegistrationStatus == UserStatus.Approved);
     if (alluser.List().FirstOrDefault().As <UserPwdRecoveryPart>() != null)
     {
         var allusercol = alluser.List().Where(x => !string.IsNullOrEmpty(x.ContentItem.As <UserPwdRecoveryPart>().PhoneNumber)).ToList();
         foreach (IContent user in allusercol)
         {
             string pref = user.ContentItem.As <UserPwdRecoveryPart>().InternationalPrefix;
             string num  = user.ContentItem.As <UserPwdRecoveryPart>().PhoneNumber;
             CommunicationSmsRecord   csr             = _repositoryCommunicationSmsRecord.Fetch(x => x.Sms == num && x.Prefix == pref).FirstOrDefault();
             CommunicationContactPart ciCommunication = _orchardServices.ContentManager.Query <CommunicationContactPart, CommunicationContactPartRecord>().Where(x => x.UserPartRecord_Id == user.Id).List().FirstOrDefault();
             if (ciCommunication == null)
             {
                 // Una contact part dovrebbe esserci in quanto questo codice viene eseguito dopo la sincronizzazione utenti
                 // Se non vi è una contartpart deduco che il dato sia sporco (es: UUid di un utente che è stato cancellato quindi non sincronizzo il dato con contactpart, verrà legato come se fosse scollegato al contentitem che raggruppa tutti i scollegati)
                 //throw new Exception("Utente senza associazione alla profilazione");
             }
             else
             {
                 if (csr == null)
                 {
                     CommunicationSmsRecord newsms = new CommunicationSmsRecord();
                     newsms.Prefix = pref;
                     newsms.Sms    = num;
                     newsms.SmsContactPartRecord_Id = ciCommunication.ContentItem.Id;
                     newsms.Id              = 0;
                     newsms.Validated       = true;
                     newsms.DataInserimento = DateTime.Now;
                     newsms.DataModifica    = DateTime.Now;
                     newsms.Produzione      = true;
                     _repositoryCommunicationSmsRecord.Create(newsms);
                     _repositoryCommunicationSmsRecord.Flush();
                 }
                 else
                 {
                     if (csr.SmsContactPartRecord_Id != ciCommunication.ContentItem.Id)
                     {
                         csr.SmsContactPartRecord_Id = ciCommunication.ContentItem.Id;
                         csr.DataModifica            = DateTime.Now;
                         _repositoryCommunicationSmsRecord.Update(csr);
                         _repositoryCommunicationSmsRecord.Flush();
                     }
                 }
             }
         }
     }
     #endregion
 }
Ejemplo n.º 4
0
 public void AddSmsToContact(string pref, string num, ContentItem contact, bool overridexisting = true)
 {
     if (!string.IsNullOrEmpty(num))
     {
         CommunicationContactPart ciCommunication = contact.As <CommunicationContactPart>();
         if (ciCommunication != null)
         {
             CommunicationSmsRecord csr = _repositoryCommunicationSmsRecord.Fetch(x => x.SmsContactPartRecord_Id == ciCommunication.ContentItem.Id).FirstOrDefault();
             if (csr == null)
             {
                 CommunicationSmsRecord newsms = new CommunicationSmsRecord();
                 newsms.Prefix = pref;
                 newsms.Sms    = num;
                 newsms.SmsContactPartRecord_Id = ciCommunication.ContentItem.Id;
                 newsms.Id              = 0;
                 newsms.Validated       = true;
                 newsms.DataInserimento = DateTime.Now;
                 newsms.DataModifica    = DateTime.Now;
                 newsms.Produzione      = true;
                 _repositoryCommunicationSmsRecord.Create(newsms);
                 _repositoryCommunicationSmsRecord.Flush();
             }
             else
             {
                 if (overridexisting)
                 {
                     csr.Prefix = pref;
                     csr.Sms    = num;
                     csr.SmsContactPartRecord_Id = ciCommunication.ContentItem.Id;
                     csr.DataModifica            = DateTime.Now;
                     _repositoryCommunicationSmsRecord.Update(csr);
                     _repositoryCommunicationSmsRecord.Flush();
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
        public CommunicationContactPart EnsureMasterContact()
        {
            CommunicationContactPart master             = null;
            List <ContentItem>       mastersToBeDeleted = new List <ContentItem>();
            // cerca tutti i master contact attivi presenti nel sistema e sceglie il più recente
            var activeMasters = _orchardServices.ContentManager.Query <CommunicationContactPart, CommunicationContactPartRecord>().Where(y => y.Master).OrderByDescending(y => y.Id).List();

            foreach (var contact in activeMasters)
            {
                if (master == null)
                {
                    master = contact;
                }
                else
                {
                    mastersToBeDeleted.Add(contact.ContentItem);
                }
            }

            // se non c'è nessun master contact lo crea
            if (master == null)
            {
                var Contact = _orchardServices.ContentManager.Create("CommunicationContact");
                Contact.As <TitlePart>().Title = "Master Contact";
                Contact.As <CommunicationContactPart>().Master = true;
                master = Contact.As <CommunicationContactPart>();
                _notifier.Add(NotifyType.Information, T("Master Contact Created"));
            }

            // elimina i master contact in eccesso
            foreach (var contact in mastersToBeDeleted)
            {
                _orchardServices.ContentManager.Remove(contact);
            }
            return(master);
        }
Ejemplo n.º 6
0
        public void PolicyChanged(PolicyEventViewModel policyData)
        {
            try {
                // recupera l'item (user o contact) che ha accettato le policy
                if (policyData.ItemPolicyPartRecordId == 0)
                {
                    var loggedUser = _workContext.GetContext().CurrentUser;
                    if (loggedUser == null)
                    {
                        // queste policy non si riferiscono a nessun item (user o contact, per esempio) e non c'è un utente loggato
                        // quindi non fare nulla
                        return;
                    }
                    else
                    {
                        policyData.ItemPolicyPartRecordId = loggedUser.Id;
                    }
                }
                // recupera il contatto
                CommunicationContactPart contactPart = null;
                var item = _contentManager.Get(policyData.ItemPolicyPartRecordId);
                if (item.ContentType == "User")
                {
                    contactPart = _contentManager.Query <CommunicationContactPart, CommunicationContactPartRecord>().Where(w => w.UserPartRecord_Id == item.Id).List().FirstOrDefault();
                }
                else if (item.ContentType == "CommunicationContact")
                {
                    contactPart = item.As <CommunicationContactPart>();
                }
                else
                {
                    // non fa nulla perché non è né uno user né un contatto
                    return;
                }
                // imposta i flag su email e sms
                if (policyData.policyType == PolicyTypeOptions.CommercialUse)
                {
                    EmailContactPart emailPart = contactPart.As <EmailContactPart>();
                    if (emailPart != null)
                    {
                        foreach (CommunicationEmailRecord emailContact in emailPart.EmailRecord)
                        {
                            emailContact.AccettatoUsoCommerciale = policyData.accepted;
                            _emailRepository.Update(emailContact);
                        }
                    }

                    SmsContactPart smsPart = contactPart.As <SmsContactPart>();
                    if (smsPart != null)
                    {
                        foreach (CommunicationSmsRecord smsContact in smsPart.SmsRecord)
                        {
                            smsContact.AccettatoUsoCommerciale = policyData.accepted;
                            _smsRepository.Update(smsContact);
                        }
                    }
                }

                if (policyData.policyType == PolicyTypeOptions.ThirdParty)
                {
                    EmailContactPart emailPart = contactPart.As <EmailContactPart>();
                    if (emailPart != null)
                    {
                        foreach (CommunicationEmailRecord emailContact in emailPart.EmailRecord)
                        {
                            emailContact.AutorizzatoTerzeParti = policyData.accepted;
                            _emailRepository.Update(emailContact);
                        }
                    }

                    SmsContactPart smsPart = contactPart.As <SmsContactPart>();
                    if (smsPart != null)
                    {
                        foreach (CommunicationSmsRecord smsContact in smsPart.SmsRecord)
                        {
                            smsContact.AutorizzatoTerzeParti = policyData.accepted;
                            _smsRepository.Update(smsContact);
                        }
                    }
                }
            }
            catch { }
        }