예제 #1
0
        private static void DispatchTrendingDeals(UsersDal usersDal, JobsQueue <EmailCargo> emailJobsQueue, bool includeList, List <Guid> userIds, string emailRenderingUrl, string campaignName, IEnumerable <Guid> dealIds)
        {
            string subject = ConfigurationManager.AppSettings["LoMo.TrendingDeals.Subject"];

            if (includeList)
            {
                foreach (Guid userId in userIds)
                {
                    Record(string.Format("Start dispatching. User Id={0}", userId));
                    var subscriptions = usersDal.GetEmailSubscriptionsByUserId(userId, true, SubscriptionType.WeeklyDeals.ToString());
                    foreach (EmailSubscription emailSubscription in subscriptions)
                    {
                        if (emailSubscription.LocationId.Contains("us:postal:"))
                        {
                            if (CloHelper.IsCloRegion(emailSubscription.LocationId).Item1)
                            {
                                DispatchEmailJob(emailSubscription, usersDal, emailJobsQueue, campaignName, emailRenderingUrl, true, null, dealIds: dealIds, subject: subject);
                            }
                        }
                    }
                }
            }
            else
            {
                object continuationContext = null;
                bool   hasMore             = true;
                while (hasMore)
                {
                    EmailsSubscriptionsBatchResponse response = usersDal.GetNextEmailSubscriptionsBatch(10000, true, continuationContext, SubscriptionType.WeeklyDeals);
                    if (response.EmailSubscriptions != null)
                    {
                        foreach (EmailSubscription emailSubscription in response.EmailSubscriptions)
                        {
                            if (userIds != null && userIds.Contains(emailSubscription.UserId))
                            {
                                Record(string.Format("User With Id {0} is excluded from this run.", emailSubscription.UserId));
                            }
                            else
                            {
                                if (emailSubscription.LocationId.Contains("us:postal:") && CloHelper.IsCloRegion(emailSubscription.LocationId).Item1)
                                {
                                    DispatchEmailJob(emailSubscription, usersDal, emailJobsQueue, campaignName, emailRenderingUrl, true, null, dealIds: dealIds, subject: subject);
                                }
                            }
                        }
                    }
                    hasMore             = response.HasMore;
                    continuationContext = response.ContinuationContext;
                }
            }
        }
예제 #2
0
        private static void CalculateEmailStatistics(UsersDal usersDal, string location)
        {
            object continuationContext = null;
            bool   hasMore             = true;
            string accessToken         = GetAnalyticsAccessToken();
            int    loggedIn            = 0;
            int    notLoggedIn         = 0;
            int    signedUp            = 0;
            int    addedCard           = 0;

            while (hasMore)
            {
                EmailsSubscriptionsBatchResponse response = usersDal.GetNextEmailSubscriptionsBatch(10000, true, continuationContext, SubscriptionType.WeeklyDeals);
                if (response.EmailSubscriptions != null)
                {
                    foreach (EmailSubscription emailSubscription in response.EmailSubscriptions)
                    {
                        if (emailSubscription.LocationId.Contains("us:postal:"))
                        {
                            Tuple <bool, string> tuple = CloHelper.IsCloRegion(emailSubscription.LocationId);
                            if (tuple.Item1 && String.Compare(location, tuple.Item2, StringComparison.CurrentCultureIgnoreCase) == 0)
                            {
                                User user = usersDal.GetUserByUserId(emailSubscription.UserId);
                                if (!String.IsNullOrEmpty(user.MsId))
                                {
                                    loggedIn++;
                                    Tuple <DateTime?, DateTime?> tuple1 = GetCloInfo(user.Id, accessToken);
                                    if (tuple1.Item1 != null)
                                    {
                                        signedUp++;
                                    }
                                    if (tuple1.Item2 != null)
                                    {
                                        addedCard++;
                                    }
                                }
                                else
                                {
                                    notLoggedIn++;
                                }
                            }
                        }
                    }
                }

                hasMore             = response.HasMore;
                continuationContext = response.ContinuationContext;
            }

            Debug.WriteLine("Total users {0}, Logged in {1}, Not Logged in {2}, Signed up {3}, Added card {4}", (loggedIn + notLoggedIn), loggedIn, notLoggedIn, signedUp, addedCard);
        }
예제 #3
0
        private static void DispatchWeeklyDeals(UsersDal usersDal, JobsQueue <EmailCargo> emailJobsQueue, bool includeList, List <Guid> userIds, string emailRenderingUrl, string campaignName, bool isClo)
        {
            int cloUser    = 0;
            int nonCloUser = 0;

            if (includeList)
            {
                foreach (Guid userId in userIds)
                {
                    Record(string.Format("Start dispatching. User Id={0}", userId));
                    var subscriptions = usersDal.GetEmailSubscriptionsByUserId(userId, true, SubscriptionType.WeeklyDeals.ToString());
                    foreach (EmailSubscription emailSubscription in subscriptions)
                    {
                        if (emailSubscription.LocationId.Contains("us:postal:"))
                        {
                            if (CloHelper.IsCloRegion(emailSubscription.LocationId).Item1)
                            {
                                DispatchEmailJob(emailSubscription, usersDal, emailJobsQueue, campaignName, emailRenderingUrl, true, null);
                                cloUser++;
                            }
                            else
                            {
                                DispatchEmailJob(emailSubscription, usersDal, emailJobsQueue, campaignName, emailRenderingUrl, false, null);
                                nonCloUser++;
                            }
                        }
                    }
                }

                Record(string.Format("Total {0} mails sent : {1}", isClo ? "CLO" : "Non CLO", isClo ? cloUser : nonCloUser));
            }
            else
            {
                // List of excluded users
                object continuationContext = null;
                bool   hasMore             = true;
                while (hasMore)
                {
                    EmailsSubscriptionsBatchResponse response = usersDal.GetNextEmailSubscriptionsBatch(10000, true, continuationContext, SubscriptionType.WeeklyDeals);
                    if (response.EmailSubscriptions != null)
                    {
                        foreach (EmailSubscription emailSubscription in response.EmailSubscriptions)
                        {
                            if (userIds != null && userIds.Contains(emailSubscription.UserId))
                            {
                                Record(string.Format("User With Id {0} is excluded from this run.", emailSubscription.UserId));
                            }
                            else
                            {
                                if (emailSubscription.LocationId.Contains("us:postal:"))
                                {
                                    if (isClo)
                                    {
                                        if (CloHelper.IsCloRegion(emailSubscription.LocationId).Item1)
                                        {
                                            DispatchEmailJob(emailSubscription, usersDal, emailJobsQueue,
                                                             campaignName, emailRenderingUrl,
                                                             true, null);
                                            cloUser++;
                                        }
                                    }
                                    else
                                    {
                                        if (!CloHelper.IsCloRegion(emailSubscription.LocationId).Item1)
                                        {
                                            DispatchEmailJob(emailSubscription, usersDal, emailJobsQueue,
                                                             campaignName,
                                                             emailRenderingUrl, false, null);
                                            nonCloUser++;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    hasMore             = response.HasMore;
                    continuationContext = response.ContinuationContext;
                }

                Record(string.Format("Total {0} mails sent : {1}", isClo ? "CLO" : "Non CLO", isClo ? cloUser : nonCloUser));
            }
        }
예제 #4
0
        private static void DispatchCampaignMails()
        {
            object continuationContext = null;
            bool   hasMore             = true;
            string analyticsToken      = GetAnalyticsAccessToken();

            CampaignRenderingServiceURL = ConfigurationManager.AppSettings["LoMo.StarbucksEmailRenderingServiceUrl"];

            IDictionary <string, string> campaignData = new Dictionary <string, string>();

            campaignData.Add("Seattle+unauth", "1");
            campaignData.Add("Seattle+auth", "2");
            campaignData.Add("Phoenix+unauth", "3");
            campaignData.Add("Phoenix+auth", "4");
            campaignData.Add("Boston+unauth", "5");
            campaignData.Add("Boston+auth", "6");
            string             campaignId         = null;
            CampaignEmailCargo campaignEmailCargo = new CampaignEmailCargo();

            while (hasMore)
            {
                EmailsSubscriptionsBatchResponse response = usersDal.GetNextEmailSubscriptionsBatch(1, true, continuationContext, SubscriptionType.WeeklyDeals);
                if (response.EmailSubscriptions != null)
                {
                    foreach (EmailSubscription emailSubscription in response.EmailSubscriptions)
                    {
                        if (emailSubscription.LocationId.Contains("us:postal:"))
                        {
                            Tuple <bool, string> cloRegionInfo = CloHelper.IsCloRegion(emailSubscription.LocationId);
                            if (cloRegionInfo.Item1)
                            {
                                User user = usersDal.GetUserByUserId(emailSubscription.UserId);
                                bool sendEmail;
                                int  mode = 0;
                                if (!string.IsNullOrEmpty(user.MsId))
                                {
                                    Tuple <DateTime?, DateTime?> cloInfo = GetCloInfo(user.Id, analyticsToken);
                                    if (cloInfo.Item1 == null)
                                    {
                                        sendEmail  = true;
                                        campaignId = campaignData[string.Format("{0}+{1}", cloRegionInfo.Item2, "auth")];
                                        mode       = 5;
                                        campaignEmailCargo.Content = "http://www.bing-exp.com/offers/card-linked-signup/?bor=BO_EMAIL&bof=be_sgc&boab=5";
                                    }
                                    else
                                    {
                                        sendEmail = false;
                                    }
                                }
                                else
                                {
                                    sendEmail  = true;
                                    campaignId = campaignData[string.Format("{0}+{1}", cloRegionInfo.Item2, "unauth")];
                                    mode       = 6;
                                    campaignEmailCargo.Content = "http://www.bing-exp.com/offers/card-linked-signup/?bor=BO_EMAIL&bof=be_sgc&boab=6";
                                }
                                if (sendEmail && mode != 0)
                                {
                                    campaignEmailCargo.Campaign     = string.Format("{0},be_sgc", campaignId);
                                    campaignEmailCargo.Content      = string.Format("http://www.bing-exp.com/offers/card-linked-signup/?bor=BO_EMAIL&bof={0}&boab={1}", campaignEmailCargo.Campaign, mode);
                                    campaignEmailCargo.EmailAddress = "*****@*****.**";
                                    campaignEmailCargo.EmailRenderingServiceAddress = string.Format(CampaignRenderingServiceURL, campaignEmailCargo.Campaign);
                                    campaignEmailCargo.LocationId     = emailSubscription.LocationId;
                                    campaignEmailCargo.Id             = campaignEmailCargo.UserId = user.Id;
                                    campaignEmailCargo.Subject        = ConfigurationManager.AppSettings["LoMo.StartBucksCampaign.Subject"];
                                    campaignEmailCargo.UnsubscribeUrl = usersDal.GetUnsubscribeUrlInfo(user.Id).UnsubscribeUrl;
                                    emailJobsQueue.Enqueue(campaignEmailCargo);
                                }
                            }
                        }
                    }
                }

                hasMore             = response.HasMore;
                continuationContext = response.ContinuationContext;
            }
        }