コード例 #1
0
ファイル: TestBase.cs プロジェクト: kirkenskorshaer/crm
        public void SetUp()
        {
            Connection.CleanDatabase();

            if (Config.Exists(Connection) == false)
            {
                Config config = new Config()
                {
                    EmailPassword = "******",
                    Email         = "testEmail",
                    EmailSmtpPort = 0,
                    EmailSmtpHost = "testHost",
                };

                config.Insert(Connection);
            }

            UrlLogin urlLogin = UrlLogin.GetUrlLogin(Connection, "test");

            DynamicsCrmConnection = DynamicsCrmConnection.GetConnection(urlLogin.Url, urlLogin.Username, urlLogin.Password);

            _mailrelayConnectionTester   = new MailrelayConnectionTester();
            _dynamicsCrmConnectionTester = new DynamicsCrmConnectionTester();
            _random = new Random();
        }
コード例 #2
0
        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;
        }
コード例 #3
0
ファイル: GroupTest.cs プロジェクト: kirkenskorshaer/crm
        public void SetUp()
        {
            MongoConnection connection = MongoConnection.GetConnection("test");
            UrlLogin        login      = UrlLogin.GetUrlLogin(connection, "test");

            _connection = DynamicsCrmConnection.GetConnection(login.Url, login.Username, login.Password);
        }
コード例 #4
0
        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;
        }
コード例 #5
0
        public override void ExecuteOption(OptionReport report)
        {
            string           urlLoginName           = _databaseCreateImportFromStub.urlLoginName;
            DatabaseSchedule ImportFromStubSchedule = _databaseCreateImportFromStub.ImportFromStubSchedule;

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

            List <Campaign> campaigns = Campaign.ReadCampaignsToImportStubDataTo(dynamicsCrmConnection);

            foreach (Campaign campaign in campaigns)
            {
                DatabaseWebCampaign webCampaign = ReadOrCreateWebCampaign(campaign);

                bool importExists = DatabaseImportFromStub.ReadByWebCampaign(Connection, webCampaign).Any();
                if (importExists == false)
                {
                    DatabaseImportFromStub.Create(Connection, webCampaign._id, urlLoginName, campaign.name, ImportFromStubSchedule);
                }
            }

            report.Success = true;

            return;
        }
コード例 #6
0
 protected void SetDynamicsCrmConnectionIfEmpty(string urlLoginName)
 {
     if (_dynamicsCrmConnection == null)
     {
         DatabaseUrlLogin login = DatabaseUrlLogin.GetUrlLogin(Connection, urlLoginName);
         _dynamicsCrmConnection = DynamicsCrmConnection.GetConnection(login.Url, login.Username, login.Password);
     }
 }
コード例 #7
0
ファイル: TestBase.cs プロジェクト: kirkenskorshaer/crm
 public void TestFixtureSetUp()
 {
     _mongoConnection       = MongoConnection.GetConnection("test");
     _urlLogin              = UrlLogin.GetUrlLogin(_mongoConnection, "test");
     _dynamicsCrmConnection = DynamicsCrmConnection.GetConnection(_urlLogin.Url, _urlLogin.Username, _urlLogin.Password);
     _config = Config.GetConfig(_mongoConnection);
     _mailrelayConnection = new MailrelayConnection(_config.MailrelayUrl, _config.MailrelayApiKey);
 }
コード例 #8
0
        protected void SetDynamicsCrmConnectionIfEmpty()
        {
            if (_dynamicsCrmConnection == null)
            {
                string dynamicsCrmUrl      = Config.DynamicsCrmUrl;
                string dynamicsCrmUsername = Config.DynamicsCrmUsername;
                string dynamicsCrmPassword = Config.DynamicsCrmPassword;

                _dynamicsCrmConnection = DynamicsCrmConnection.GetConnection(dynamicsCrmUrl, dynamicsCrmUsername, dynamicsCrmPassword);
            }
        }
コード例 #9
0
        public override void ExecuteOption(OptionReport report)
        {
            string urlLoginName            = _databaseMaterialeBehovAssignment.urlLoginName;
            int    updateProgressFrequency = _databaseMaterialeBehovAssignment.updateProgressFrequency;

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

            Materiale materiale = Materiale.ReadCalculationNeed(dynamicsCrmConnection, Config.GetResourcePath);

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

            materiale.FindBehovDefinitioner(Config.GetResourcePath);

            int total = CountTotalAccountsToUpdate(dynamicsCrmConnection, materiale);
            int staleMaterialeBehovCount = materiale.CountStaleMaterialeBehov(Config.GetResourcePath);

            total += staleMaterialeBehovCount;

            materiale.new_beregningsstatus = 0;
            materiale.Update();

            materiale.RemoveStaleMaterialeBehov(Config.GetResourcePath, currentProgress => updateProgress(materiale, currentProgress, total), updateProgressFrequency);

            int progress = staleMaterialeBehovCount;
            int materialeAddedCurrent = -1;

            MaterialeProcessState state = new MaterialeProcessState();

            state.pagingInformation  = new PagingInformation();
            state.owningbusinessunit = materiale.owningbusinessunitGuid.Value;

            while (materialeAddedCurrent != 0)
            {
                materiale.AddMissingMateriale(state, Config.GetResourcePath);
                materialeAddedCurrent = state.AccountsProcessed;
                progress += materialeAddedCurrent;
                updateProgress(materiale, progress, total);
            }
            materialeAddedCurrent = -1;

            materiale.behovsberegning      = Materiale.behovsberegningEnum.Afsluttet;
            materiale.new_beregningsstatus = null;
            materiale.Update();

            report.Success = true;
            return;
        }
コード例 #10
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;
            }
        }
コード例 #11
0
        public override void ExecuteOption(OptionReport report)
        {
            string urlLoginName = _databaseExposeData.urlLoginName;
            string fetchXmlPath = _databaseExposeData.fetchXmlPath;
            string exposePath   = _databaseExposeData.exposePath;
            string exposeName   = _databaseExposeData.exposeName;

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

            string fullFetchXmlPath = Config.GetResourcePath(fetchXmlPath);
            string fullExposePath   = Config.GetResourcePath(exposePath);

            List <dynamic> dataList = DynamicFetch.ReadFromFetchXml(dynamicsCrmConnection, fullFetchXmlPath, new PagingInformation());

            JsonSerializerSettings settings = new JsonSerializerSettings()
            {
                NullValueHandling    = NullValueHandling.Ignore,
                StringEscapeHandling = StringEscapeHandling.EscapeNonAscii,
            };

            string json = JsonConvert.SerializeObject(dataList, Formatting.None, settings);

            json = json.Replace("\\r\\n", "\\n");

            if (Directory.Exists(fullExposePath) == false)
            {
                Directory.CreateDirectory(fullExposePath);
            }

            File.WriteAllText(fullExposePath + "/" + exposeName, json, Encoding.UTF8);

            report.Success = true;

            return;
        }
コード例 #12
0
        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;
        }