public override void ExecuteOption(OptionReport report)
        {
            string urlLoginName = _databaseExportContactToMailrelay.urlLoginName;

            Guid?crmListId = _databaseExportContactToMailrelay.listId;

            DatabaseUrlLogin      login = DatabaseUrlLogin.GetUrlLogin(Connection, urlLoginName);
            DynamicsCrmConnection dynamicsCrmConnection = DynamicsCrmConnection.GetConnection(login.Url, login.Username, login.Password);

            PagingInformation pagingInformation = new PagingInformation();

            while (pagingInformation.FirstRun || pagingInformation.MoreRecords)
            {
                MarketingList marketingList = MarketingList.GetListForMailrelayUpdate(dynamicsCrmConnection, pagingInformation, crmListId);

                if (marketingList != null)
                {
                    UpdateReport <Guid> result = ExportMailrelayContactFromList(dynamicsCrmConnection, marketingList);
                    Log.Write(Connection, result.AsLogText($"ExportContactToMailrelay {marketingList.new_mailrelaygroupid.Value}"), typeof(ExportContactToMailrelay), DataLayer.MongoData.Config.LogLevelEnum.OptionReport);
                }
            }

            report.Success = true;

            return;
        }
        public override void ExecuteOption(OptionReport report)
        {
            string urlLoginName = _databaseUpdateMailrelayFromContact.urlLoginName;
            int    pageSize     = _databaseUpdateMailrelayFromContact.pageSize;
            Guid?  contactId    = _databaseUpdateMailrelayFromContact.contactId;

            DatabaseUrlLogin      login = DatabaseUrlLogin.GetUrlLogin(Connection, urlLoginName);
            DynamicsCrmConnection dynamicsCrmConnection = DynamicsCrmConnection.GetConnection(login.Url, login.Username, login.Password);

            PagingInformation pagingInformation = new PagingInformation();

            List <MailrelayInformation> mailrelayInformations = new List <MailrelayInformation>();

            UpdateReport <int> intReport = new UpdateReport <int>();

            while (pagingInformation.FirstRun || pagingInformation.MoreRecords)
            {
                mailrelayInformations = MailrelayInformation.GetMailrelayFromContact(dynamicsCrmConnection, Config.GetResourcePath, pagingInformation, pageSize, contactId);
                mailrelayInformations.ForEach(information => UpdateIfNeeded(dynamicsCrmConnection, information, intReport));
            }

            Log.Write(Connection, intReport.AsLogText("UpdateMailrelayFromContact"), typeof(UpdateMailrelayFromContact), DataLayer.MongoData.Config.LogLevelEnum.OptionReport);

            report.Success = true;
            return;
        }
Ejemplo n.º 3
0
 protected void SetDynamicsCrmConnectionIfEmpty(string urlLoginName)
 {
     if (_dynamicsCrmConnection == null)
     {
         DatabaseUrlLogin login = DatabaseUrlLogin.GetUrlLogin(Connection, urlLoginName);
         _dynamicsCrmConnection = DynamicsCrmConnection.GetConnection(login.Url, login.Username, login.Password);
     }
 }
Ejemplo n.º 4
0
        public override void ExecuteOption(OptionReport report)
        {
            string urlLoginName = _databaseImportFromStub.urlLoginName;

            DatabaseUrlLogin      login = DatabaseUrlLogin.GetUrlLogin(Connection, urlLoginName);
            DynamicsCrmConnection dynamicsCrmConnection = DynamicsCrmConnection.GetConnection(login.Url, login.Username, login.Password);

            DatabaseWebCampaign webCampaign = DatabaseWebCampaign.ReadByIdBytesSingleOrDefault(Connection, _databaseImportFromStub.WebCampaignIdValue());

            DatabaseWebCampaign.CollectTypeEnum collectType;
            DatabaseStub stub;

            if (webCampaign == null)
            {
                collectType = DatabaseWebCampaign.CollectTypeEnum.Lead;
                stub        = DatabaseStub.ReadFirst(Connection);
            }
            else
            {
                collectType = webCampaign.CollectType;
                stub        = DatabaseStub.ReadFirst(Connection, webCampaign);
            }

            if (stub == null)
            {
                report.Success = true;
                return;
            }

            try
            {
                ImportStub(dynamicsCrmConnection, stub, webCampaign, collectType);
                stub.Delete(Connection);
                report.Success = true;
                return;
            }
            catch (Exception exception)
            {
                Log.Write(Connection, exception.Message, typeof(ImportFromStub), exception.StackTrace, DataLayer.MongoData.Config.LogLevelEnum.OptionError);
                stub.ImportAttempt++;
                stub.Update(Connection);
                report.Success = false;
                return;
            }
        }
        public override void ExecuteOption(OptionReport report)
        {
            string urlLoginName = _databaseAddMailrelaySubscriberFromLead.urlLoginName;
            string email        = _databaseAddMailrelaySubscriberFromLead.email;
            Guid   leadId       = _databaseAddMailrelaySubscriberFromLead.leadId;

            DatabaseUrlLogin      login = DatabaseUrlLogin.GetUrlLogin(Connection, urlLoginName);
            DynamicsCrmConnection dynamicsCrmConnection = DynamicsCrmConnection.GetConnection(login.Url, login.Username, login.Password);

            DatabaseWebCampaign webCampaign = DatabaseWebCampaign.ReadByIdBytesSingleOrDefault(Connection, _databaseAddMailrelaySubscriberFromLead.WebCampaignIdValue());

            if (webCampaign == null)
            {
                Log.Write(Connection, $"Could not find campaign for {_databaseAddMailrelaySubscriberFromLead.Name}", typeof(AddMailrelaySubscriberFromLead), DataLayer.MongoData.Config.LogLevelEnum.OptionError);
                report.Success = false;
                return;
            }

            MailrelayInformation information = GetInformationFromFetchXml(dynamicsCrmConnection, webCampaign, email);

            if (information == null)
            {
                Log.Write(Connection, $"Information for lead {leadId} on {email} could not be found", typeof(AddMailrelaySubscriberFromLead), DataLayer.MongoData.Config.LogLevelEnum.OptionMessage);
                report.Success = true;
                return;
            }

            if (information.campaign_new_mailrelaygroupid.HasValue == false)
            {
                Log.Write(Connection, $"Subscriber not added, campaign {webCampaign.FormId} has no group", typeof(AddMailrelaySubscriberFromLead), DataLayer.MongoData.Config.LogLevelEnum.OptionMessage);
                report.Success = true;
                return;
            }

            getSubscribersReply ExistingSubscriber = GetExistingSubscribers(email);

            int subscriberId;

            if (ExistingSubscriber == null)
            {
                addSubscriber add = GetSubscriberFromFetchXml(information, email);

                subscriberId = SendSubscriberToMailrelay(add);
            }
            else
            {
                subscriberId = int.Parse(ExistingSubscriber.id);
                UdpateExistingSubscriberIfNeeded(information, ExistingSubscriber, email, subscriberId);
            }

            try
            {
                Lead.UpdateSubscriberId(dynamicsCrmConnection, leadId, subscriberId);
            }
            catch (Exception exception)
            {
                Log.Write(Connection, exception.Message, typeof(AddMailrelaySubscriberFromLead), exception.StackTrace, DataLayer.MongoData.Config.LogLevelEnum.OptionError);
            }

            report.Success = true;
        }