private addSubscriber GetSubscriberFromFetchXml(MailrelayInformation information, string email)
        {
            Dictionary <string, string> customFields = information.GetCustomFields();

            List <int> groups = new List <int>()
            {
                information.campaign_new_mailrelaygroupid.Value
            };

            addSubscriber add = new addSubscriber()
            {
                customFields = customFields,
                email        = email,
                name         = information.fullname,
                groups       = groups,
            };

            return(add);
        }
        private bool FindNewCustomFields(MailrelayInformation information, getSubscribersReply ExistingSubscriber, Dictionary <string, string> customFieldsResult)
        {
            Dictionary <string, string> customFieldsInInformation        = information.GetCustomFields();
            Dictionary <string, string> customFieldsInExistingSubscriber = ExistingSubscriber.fields;

            List <string> allKeys = customFieldsInInformation.Keys.Union(customFieldsInExistingSubscriber.Keys).ToList();

            bool isChanged = false;

            foreach (string key in allKeys)
            {
                if (customFieldsInExistingSubscriber.ContainsKey(key))
                {
                    customFieldsResult.Add(key, customFieldsInExistingSubscriber[key]);
                    continue;
                }
                isChanged = true;
                customFieldsResult.Add(key, customFieldsInInformation[key]);
            }

            return(isChanged);
        }
        private UpdateResultEnum AddToMailrelay(DynamicsCrmConnection dynamicsCrmConnection, MailrelayInformation mailrelayInformation, int groupId)
        {
            if (mailrelayInformation.new_mailrelaysubscriberid != null)
            {
                return(UpdateResultEnum.AlreadyUpToDate);
            }

            Subscriber subscriber = new Subscriber(_mailrelayConnection);

            try
            {
                getSubscribersReply reply = subscriber.GetMailrelaySubscribers(mailrelayInformation.emailaddress1);

                if (reply == null)
                {
                    mailrelayInformation.new_mailrelaysubscriberid = subscriber.AddNewSubscriber(mailrelayInformation.fullname, mailrelayInformation.emailaddress1, new List <int>()
                    {
                        groupId
                    }, mailrelayInformation.GetCustomFields());
                }
                else
                {
                    reply.groups.Add(groupId.ToString());

                    subscriber.UpdateFromReply(reply);

                    mailrelayInformation.new_mailrelaysubscriberid = int.Parse(reply.id);
                }
            }
            catch (Exception exception)
            {
                Log.Write(Connection, exception.Message, typeof(ExportContactToMailrelay), exception.StackTrace, DataLayer.MongoData.Config.LogLevelEnum.OptionError);
                return(UpdateResultEnum.Failed);
            }

            mailrelayInformation.UpdateContactMailrelaySubscriberid(dynamicsCrmConnection);

            return(UpdateResultEnum.Updated);
        }
        private void UpdateIfNeeded(DynamicsCrmConnection dynamicsCrmConnection, MailrelayInformation information, UpdateReport <int> report)
        {
            bool needsUpdate = information.RecalculateContactCheck();
            int  id          = information.new_mailrelaysubscriberid.Value;

            if (needsUpdate == false)
            {
                report.CollectUpdate(UpdateResultEnum.AlreadyUpToDate, id);
                return;
            }

            information.UpdateContactMailrelaycheck(dynamicsCrmConnection);

            Subscriber       subscriber = new Subscriber(_mailrelayConnection);
            UpdateResultEnum result     = subscriber.UpdateIfNeeded(id, information.fullname, information.emailaddress1, information.GetCustomFields());

            report.CollectUpdate(result, id);
        }
Ejemplo n.º 5
0
        private void AddToMailrelayGroup(DynamicsCrmConnection dynamicsCrmConnection, UpdateReport <int> report, Subscriber subscriber, List <KeyValueEntity <Guid, int?> > crmIdsAndSubscriberIds, int groupInCrm)
        {
            foreach (KeyValueEntity <Guid, int?> idPair in crmIdsAndSubscriberIds)
            {
                MailrelayInformation mailrelayInformation = MailrelayInformation.GetMailrelayFromContact(dynamicsCrmConnection, Config.GetResourcePath, new PagingInformation(), 1, idPair.key).Single();

                UpdateResultEnum result = subscriber.UpdateIfNeeded(idPair.value.Value, mailrelayInformation.fullname, mailrelayInformation.emailaddress1, mailrelayInformation.GetCustomFields(), groupInCrm);

                report.CollectUpdate(result, idPair.value.Value);
            }
        }