/// <summary>
        /// The get content.
        /// </summary>
        /// <param name="emailCargo">
        /// The email Job.
        /// </param>
        /// <returns>
        /// The <see cref="EmailContent"/>.
        /// </returns>
        /// <exception cref="TemplateRenderException">
        /// error while rendering the template
        /// </exception>
        public EmailData GetContent(object emailCargo)
        {
            EmailData          emailData          = null;
            CampaignEmailCargo campaignEmailCargo = emailCargo as CampaignEmailCargo;

            if (campaignEmailCargo != null)
            {
                string locationId = campaignEmailCargo.LocationId;
                CampaignTemplateData campaignTemplateData = new CampaignTemplateData
                {
                    EmailAddress         = campaignEmailCargo.EmailAddress,
                    UnsubscribeUrl       = campaignEmailCargo.UnsubscribeUrl,
                    LocationId           = locationId,
                    Content              = campaignEmailCargo.Content,
                    IncludeBusinessNames = campaignEmailCargo.IncludeBusinessNames
                };

                var model = this._templateModelCreator.GenerateModel(campaignTemplateData);
                if (model != null)
                {
                    EmailRenderingClient <CampaignDataContract> emailRenderingClient = new EmailRenderingClient
                                                                                       <CampaignDataContract>
                    {
                        EmailRenderingServiceUrl = campaignEmailCargo.EmailRenderingServiceAddress
                    };
                    emailData = new EmailData
                    {
                        Subject  = campaignEmailCargo.Subject,
                        HtmlBody = emailRenderingClient.RenderHtml(model)
                    };
                }
            }

            return(emailData);
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EmailContentCreatorFactory"/> class.
        /// </summary>
        /// <param name="dealsServerBaseAddress">
        /// The deals server base address.
        /// </param>
        public EmailContentCreatorFactory(Uri dealsServerBaseAddress)
        {
            DailyDealsTemplateCreator mockModelContentCreator = new DailyDealsTemplateCreator();
            DealsClient    dealsClient   = new DealsClient(dealsServerBaseAddress, ClientName);
            IDealsSelector dealsSelector = new NaiveDealsSelector(dealsClient);
            IEmailRenderingClient <DailyDealsContract> renderingClient = new EmailRenderingClient();

            this.contentCreator = new EmailContentCreator <DailyDealsContract>(dealsSelector, renderingClient, mockModelContentCreator);
        }
Beispiel #3
0
        /// <summary>
        /// Returns the emaildata for merchant transaction report
        /// </summary>
        /// <param name="merchantReportEmailCargo">The Merchant report email cargo</param>
        /// <param name="analyticsReponse">Response from analytics for merchant transaction call</param>
        /// <returns>Emaildata for merchant transaction report</returns>
        private EmailData GetEmailData(MerchantReportEmailCargo merchantReportEmailCargo, string analyticsReponse)
        {
            MerchantReportContract merchantReportContract;
            Dictionary <string, List <RedemptionContract> > redemptionsByMerchant = new Dictionary <string, List <RedemptionContract> >();

            if (!string.IsNullOrEmpty(analyticsReponse))
            {
                JArray jresponse = JArray.Parse(analyticsReponse);
                if (jresponse.Count > 0)
                {
                    RedemptionContract[] redemptions = new RedemptionContract[jresponse.Count];
                    for (int i = 0; i < jresponse.Count; i++)
                    {
                        var redemption = jresponse[i].ToObject <RedemptionContract>();
                        if (redemption != null)
                        {
                            redemptions[i] = redemption;
                        }
                    }
                    var groupedItems = redemptions.GroupBy(redemption => redemption.MerchantId);
                    foreach (var groupItem in groupedItems)
                    {
                        redemptionsByMerchant[groupItem.Key.ToString()] = groupItem.OrderBy(redemption => redemption.AuthorizationDateTimeLocal).ToList();
                    }
                }
            }

            MerchantTemplateData merchantTemplateData = new MerchantTemplateData
            {
                EmailAddress          = merchantReportEmailCargo.EmailAddress,
                FromDate              = merchantReportEmailCargo.FromDate,
                ToDate                = merchantReportEmailCargo.ToDate,
                ScheduleType          = merchantReportEmailCargo.ScheduleType,
                RedemptionsByMerchant = redemptionsByMerchant,
                MerchantPortalUrl     = _merchantPortalUrl,
                UnsubscribeUrl        = merchantReportEmailCargo.UnsubscribeUrl
            };

            Log.Verbose("Calling model creator to create the data contract for the job : {0}", merchantReportEmailCargo.ToString());
            merchantReportContract = _templateModelCreator.GenerateModel(merchantTemplateData);
            EmailRenderingClient <MerchantReportContract> emailRenderingClient = new EmailRenderingClient <MerchantReportContract>
            {
                EmailRenderingServiceUrl = _merchantTemplateUrl
            };

            EmailData emailData = new EmailData
            {
                Subject  = merchantReportEmailCargo.Subject,
                HtmlBody = emailRenderingClient.RenderHtml(merchantReportContract),
                TextBody = string.Empty
            };

            Log.Verbose("Ready to send the email for the job : {0}", merchantReportEmailCargo.ToString());

            return(emailData);
        }
Beispiel #4
0
        /// <summary>
        /// Returns the email content for add card remainder email
        /// </summary>
        /// <param name="remainderEmailCargo">Remainder email cargo</param>
        /// <returns>EmailData for add card remainder email</returns>
        private EmailData GetContentForCompleteSignup(PromotionalEmailCargo remainderEmailCargo)
        {
            EmailData emailData;
            EmailRenderingClient <object> emailRenderingClient = new EmailRenderingClient <object>
            {
                EmailRenderingServiceUrl = remainderEmailCargo.EmailRenderingServiceAddress
            };

            emailData = new EmailData
            {
                Subject  = remainderEmailCargo.Subject,
                HtmlBody = emailRenderingClient.RenderHtml(),
                TextBody = string.Empty
            };

            return(emailData);
        }
Beispiel #5
0
        /// <summary>
        /// Executes the confirmation email job
        /// </summary>
        /// <param name="priorityEmailCargo">Cargo for confirmation email</param>
        public void Handle(PriorityEmailCargo priorityEmailCargo)
        {
            ConfirmationEmailCargo confirmationEmailCargo = priorityEmailCargo as ConfirmationEmailCargo;

            if (confirmationEmailCargo != null)
            {
                Log.Verbose("Starting Confirmation email job : {0}", confirmationEmailCargo.ToString());
                EnvironmentType azureEnvironment;
                if (Enum.TryParse(_environment, true, out azureEnvironment))
                {
                    EmailConfirmationContract emailConfirmationContract = new EmailConfirmationContract();
                    EmailRenderingClient <EmailConfirmationContract> emailRenderingClient = new EmailRenderingClient <EmailConfirmationContract>();
                    switch (confirmationEmailCargo.EntityType)
                    {
                    case EntityType.AuthenticatedEmailAddress:
                        emailConfirmationContract.ConfirmationUrl     = ConfirmationLinkGenerator.GetLink(confirmationEmailCargo.UserIdHash, confirmationEmailCargo.ConfirmationCode, EntityType.AuthenticatedEmailAddress, azureEnvironment).AbsoluteUri;
                        emailRenderingClient.EmailRenderingServiceUrl = this._authenticatedEmailConfirmationTemplateUrl;
                        break;

                    case EntityType.UnAuthenticatedEmailAddress:
                        emailConfirmationContract.ConfirmationUrl     = ConfirmationLinkGenerator.GetLink(confirmationEmailCargo.UserIdHash, confirmationEmailCargo.ConfirmationCode, EntityType.UnAuthenticatedEmailAddress, azureEnvironment).AbsoluteUri;
                        emailRenderingClient.EmailRenderingServiceUrl = this._unauthenticatedEmailConfirmationTemplateUrl;
                        break;

                    case EntityType.AccountLink:
                        emailConfirmationContract.ConfirmationUrl     = ConfirmationLinkGenerator.GetLink(confirmationEmailCargo.UserIdHash, confirmationEmailCargo.ConfirmationCode, EntityType.AccountLink, azureEnvironment).AbsoluteUri;
                        emailRenderingClient.EmailRenderingServiceUrl = this._linkEmailAccountTemplateUrl;
                        break;

                    default:
                        throw new InvalidEntityTypeException("Unknown entity type in Confirmation Emailcargo");
                    }
                    EmailContent emailContent = new EmailContent
                    {
                        From        = this._confirmationFromAddress,
                        FromDisplay = this._confirmationFromDisplayName,
                        Subject     = confirmationEmailCargo.EntityType == EntityType.AccountLink ? this._alinkConfirmationSubject : this._confirmationEmailSubject,
                        HtmlBody    = emailRenderingClient.RenderHtml(emailConfirmationContract),
                        Category    = this._confirmationEmailCategory
                    };
                    SendEmailRequest request = new SendEmailRequest
                    {
                        Content = emailContent,
                        ToList  = new List <string> {
                            confirmationEmailCargo.EmailAddress
                        }
                    };

                    Log.Verbose("Sending email for the email job : {0}", confirmationEmailCargo.ToString());

                    // Send the email
                    this._userServicesClient.SendEmail(confirmationEmailCargo.Id, request, null);

                    Log.Verbose("Successfully sent email for the email job : {0}", confirmationEmailCargo.ToString());
                }
            }
            else
            {
                Log.Error("Error in executing confirmation email job : Invalid priority email cargo");
            }
        }
        /// <summary>
        /// The get content.
        /// </summary>
        /// <param name="emailCargo">
        /// The email Job.
        /// </param>
        /// <returns>
        /// The <see cref="EmailContent"/>.
        /// </returns>
        /// <exception cref="TemplateRenderException">
        /// error while rendering the template
        /// </exception>
        public EmailData GetContent(object emailCargo)
        {
            EmailData       emailData       = null;
            DealsEmailCargo dealsEmailCargo = emailCargo as DealsEmailCargo;

            if (dealsEmailCargo != null)
            {
                string locationId            = dealsEmailCargo.LocationId;
                bool   isSendTimeWindowValid = true;
                IEnumerable <UserEmailEntity> emailHistoryEntities = null;

                //If this is not a test email, check the history to make sure we are not sending the email to the same user within the sendtime window.
                if (!dealsEmailCargo.Hints.IsTestEmail)
                {
                    emailHistoryEntities  = this.userHistoryStorage.GetUserEmailEntities(dealsEmailCargo.UserId, mailHistoryLookback).ToList();
                    isSendTimeWindowValid = this.IsSendTimeWindowValid(emailHistoryEntities.FirstOrDefault(elem => elem.LocationId == locationId), dealsEmailCargo);
                }
                if (isSendTimeWindowValid)
                {
                    IEnumerable <Guid> dealsToExclude = null;
                    //if dealids are not included the cargo, we have to select random deals. Need to check in the history to make sure we are excluding deals that have
                    //already been sent in the past few weeks (based on the mail history lookback settings)
                    if (emailHistoryEntities != null && dealsEmailCargo.DealIds == null)
                    {
                        dealsToExclude = this.GetDealsToExclude(emailHistoryEntities);
                    }

                    EmailRenderingClient <DailyDealsContract> emailRenderingClient = new EmailRenderingClient <DailyDealsContract>
                    {
                        EmailRenderingServiceUrl = dealsEmailCargo.EmailRenderingServiceAddress
                    };
                    IEnumerable <Deal> deals = null;
                    if (dealsEmailCargo.Hints != null && dealsEmailCargo.Hints.IncludeDeals)
                    {
                        deals = this.dealsSelector.GetDeals(emailCargo as DealsEmailCargo, dealsToExclude).ToList();
                    }
                    if (deals != null && deals.Any())
                    {
                        DealsTemplateData dailyDealsTemplateData = new DealsTemplateData
                        {
                            EmailAddress   = dealsEmailCargo.EmailAddress,
                            UnsubscribeUrl = dealsEmailCargo.UnsubscribeUrl,
                            LocationId     = locationId,
                            Deals          = deals,
                            DealEmailType  =
                                dealsEmailCargo.DealIds != null && dealsEmailCargo.DealIds.Any()
                                        ? DealEmailType.TrendingDeal
                                        : DealEmailType.WeeklyDeal
                        };

                        var model = this.templateModelCreator.GenerateModel(dailyDealsTemplateData);
                        emailData = new EmailData
                        {
                            Subject = !string.IsNullOrEmpty(dealsEmailCargo.Subject)
                                              ? dealsEmailCargo.Subject
                                              : this.RenderSubject(model),
                            HtmlBody = emailRenderingClient.RenderHtml(model),
                            TextBody = string.Empty,
                            DealIds  = deals.Select(elem => new Guid(elem.Id)).ToList()
                        };
                    }
                    else
                    {
                        int dealsCount = deals != null?deals.Count() : 0;

                        throw new ModelContentException(string.Format("Number of deals is: {0}. This is insufficient for email model creation", dealsCount));
                    }
                }
            }

            return(emailData);
        }