Exemplo n.º 1
0
        private static void DispatchRemainderEmail(JobsQueue <EmailCargo> emailJobsQueue, User user, string campaign)
        {
            PromotionalEmailCargo remainderEmailCargo = new PromotionalEmailCargo
            {
                Id           = Guid.NewGuid(),
                EmailAddress = user.Email,
                Campaign     = campaign,
                UserId       = user.Id,
                EmailRenderingServiceAddress = ConfigurationManager.AppSettings["LoMo.RemainderEmailRenderingServiceUrl"],
                PromotionalEmailType         = PromotionalEmailType.CompleteSignup.ToString(),
                Subject = ConfigurationManager.AppSettings["LoMo.RemainderEmail.Subject"]
            };

            emailJobsQueue.Enqueue(remainderEmailCargo);
            Record(string.Format("Email Job Enqueued. JobInfo = {0}", remainderEmailCargo));
        }
Exemplo n.º 2
0
        private static void DispatchEmailJob(EmailSubscription emailSubscription, UsersDal usersDal, JobsQueue <EmailCargo> emailJobsQueue, string campaign, string emailRenderingUrl,
                                             bool isCloDeal, string[] categories, bool includeDeals = true, bool useTestAccount = false, string subject = null, IEnumerable <Guid> dealIds = null)
        {
            try
            {
                User   user           = usersDal.GetUserByUserId(emailSubscription.UserId);
                string unsubscribeUrl = usersDal.GetUnsubscribeUrlInfo(user.Id).UnsubscribeUrl;
                if (string.IsNullOrEmpty(user.Email))
                {
                    Record(string.Format("can't dispatch email job for user without emil address. User Id={0}", user.Id));

                    return;
                }
                if (string.IsNullOrEmpty(unsubscribeUrl))
                {
                    Record(string.Format("can't dispatch email job for user without unsubscribe url. User Id={0}", user.Id));

                    return;
                }

                DealsEmailCargo dealsEmailCargo = new DealsEmailCargo
                {
                    Id           = Guid.NewGuid(),
                    EmailAddress = user.Email,
                    Campaign     = campaign,
                    Hints        = new EmailJobHints {
                        IsTest = useTestAccount, IncludeDeals = includeDeals
                    },
                    LocationId     = emailSubscription.LocationId,
                    UnsubscribeUrl = unsubscribeUrl,
                    UserId         = user.Id,
                    DealIds        = dealIds,
                    IsCloDeal      = isCloDeal,
                    EmailRenderingServiceAddress = emailRenderingUrl
                };

                if (categories != null && categories.Any())
                {
                    List <Guid> lstGuid = new List <Guid>();
                    foreach (string category in categories)
                    {
                        lstGuid.Add(GetCategoryGuid(category));
                    }
                    dealsEmailCargo.Categories = lstGuid;
                }
                else
                {
                    dealsEmailCargo.Categories = (user.Info != null && user.Info.Preferences != null) ? user.Info.Preferences.Categories : null;
                }

                if (dealsEmailCargo.Hints.IncludeDeals && !string.IsNullOrEmpty(user.MsId) && !user.MsId.StartsWith("fb"))
                {
                    dealsEmailCargo.Anid = AnidIdentityProvider.Instance.DeriveIdentity(user.MsId.ToUpper());
                }
                if (!string.IsNullOrEmpty(subject))
                {
                    dealsEmailCargo.Subject = subject;
                }
                emailJobsQueue.Enqueue(dealsEmailCargo);
                Record(string.Format("Email Job Enqueued. Id={0}; LocationId={1};UnsubscribeUrl={2};UserId={3};CategoriesCount={4}",
                                     dealsEmailCargo.Id,
                                     dealsEmailCargo.LocationId,
                                     dealsEmailCargo.UnsubscribeUrl,
                                     dealsEmailCargo.UserId,
                                     dealsEmailCargo.Categories == null ? 0 : dealsEmailCargo.Categories.Count()));
            }
            catch (Exception e)
            {
                Log.Error("Error while dispathing email job. User Id={0}; Location Id={1}; Error={2}", emailSubscription.UserId, emailSubscription.LocationId, e);
            }
        }
Exemplo n.º 3
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;
            }
        }