当前位置: 首页>>代码示例>>C#>>正文


C# Messages.QueuedEmail类代码示例

本文整理汇总了C#中Nop.Core.Domain.Messages.QueuedEmail的典型用法代码示例。如果您正苦于以下问题:C# QueuedEmail类的具体用法?C# QueuedEmail怎么用?C# QueuedEmail使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


QueuedEmail类属于Nop.Core.Domain.Messages命名空间,在下文中一共展示了QueuedEmail类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendSms

        /// <summary>
        /// Sends SMS
        /// </summary>
        /// <param name="text">SMS text</param>
        /// <returns>Result</returns>
        public bool SendSms(string text)
        {
            try
            {
                var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
                if (emailAccount == null)
                    emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault();
                if (emailAccount == null)
                    throw new Exception("No email account could be loaded");

                var queuedEmail = new QueuedEmail()
                {
                    Priority = 5,
                    From = emailAccount.Email,
                    FromName = emailAccount.DisplayName,
                    To = _verizonSettings.Email,
                    ToName = string.Empty,
                    Subject = _storeContext.CurrentStore.Name,
                    Body = text,
                    CreatedOnUtc = DateTime.UtcNow,
                    EmailAccountId = emailAccount.Id
                };

                _queuedEmailService.InsertQueuedEmail(queuedEmail);

                return true;
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message, ex);
                return false;
            }
        }
开发者ID:haithemChkel,项目名称:nopCommerce_33,代码行数:38,代码来源:VerizonSMSProvider.cs

示例2: Can_save_and_load_queuedEmail

        public void Can_save_and_load_queuedEmail()
        {
            var qe = new QueuedEmail
            {
                PriorityId = 5,
                From = "From",
                FromName = "FromName",
                To = "To",
                ToName = "ToName",
                ReplyTo = "ReplyTo",
                ReplyToName = "ReplyToName",
                CC = "CC",
                Bcc = "Bcc",
                Subject = "Subject",
                Body = "Body",
                AttachmentFilePath = "some file path",
                AttachmentFileName = "some file name",
                AttachedDownloadId = 3,
                CreatedOnUtc = new DateTime(2010, 01, 01),
                SentTries = 5,
                SentOnUtc = new DateTime(2010, 02, 02),
                DontSendBeforeDateUtc = new DateTime(2016, 2 , 23),
                EmailAccount = new EmailAccount
                {
                    Email = "[email protected]",
                    DisplayName = "Administrator",
                    Host = "127.0.0.1",
                    Port = 125,
                    Username = "John",
                    Password = "111",
                    EnableSsl = true,
                    UseDefaultCredentials = true
                }

            };

            var fromDb = SaveAndLoadEntity(qe);
            fromDb.ShouldNotBeNull();
            fromDb.PriorityId.ShouldEqual(5);
            fromDb.From.ShouldEqual("From");
            fromDb.FromName.ShouldEqual("FromName");
            fromDb.To.ShouldEqual("To");
            fromDb.ToName.ShouldEqual("ToName");
            fromDb.ReplyTo.ShouldEqual("ReplyTo");
            fromDb.ReplyToName.ShouldEqual("ReplyToName");
            fromDb.CC.ShouldEqual("CC");
            fromDb.Bcc.ShouldEqual("Bcc");
            fromDb.Subject.ShouldEqual("Subject");
            fromDb.Body.ShouldEqual("Body");
            fromDb.AttachmentFilePath.ShouldEqual("some file path");
            fromDb.AttachmentFileName.ShouldEqual("some file name");
            fromDb.AttachedDownloadId.ShouldEqual(3);
            fromDb.CreatedOnUtc.ShouldEqual(new DateTime(2010, 01, 01));
            fromDb.SentTries.ShouldEqual(5);
            fromDb.SentOnUtc.ShouldNotBeNull();
            fromDb.SentOnUtc.Value.ShouldEqual(new DateTime(2010, 02, 02));
            fromDb.DontSendBeforeDateUtc.ShouldEqual(new DateTime(2016, 2, 23));
            fromDb.EmailAccount.ShouldNotBeNull();
            fromDb.EmailAccount.DisplayName.ShouldEqual("Administrator");
        }
开发者ID:RobinHoody,项目名称:nopCommerce,代码行数:60,代码来源:QueuedEmailPersistenceTests.cs

示例3: SendNotification

        private int SendNotification(MessageTemplate messageTemplate, 
            EmailAccount emailAccount, int languageId, IEnumerable<Token> tokens,
            string toEmailAddress, string toName)
        {
            //retrieve localized message template data
            var bcc = messageTemplate.GetLocalized((mt) => mt.BccEmailAddresses, languageId);
            var subject = messageTemplate.GetLocalized((mt) => mt.Subject, languageId);
            var body = messageTemplate.GetLocalized((mt) => mt.Body, languageId);

            //Replace subject and body tokens 
            var subjectReplaced = _tokenizer.Replace(subject, tokens, false);
            var bodyReplaced = _tokenizer.Replace(body, tokens, true);
            
            var email = new QueuedEmail()
            {
                Priority = 5,
                From = emailAccount.Email,
                FromName = emailAccount.DisplayName,
                To = toEmailAddress,
                ToName = toName,
                CC = string.Empty,
                Bcc = bcc,
                Subject = subjectReplaced,
                Body = bodyReplaced,
                CreatedOnUtc = DateTime.UtcNow,
                EmailAccountId = emailAccount.Id
            };

            _queuedEmailService.InsertQueuedEmail(email);
            return email.Id;
        }
开发者ID:CCSW,项目名称:desnivell.libraries,代码行数:31,代码来源:WorkflowMessageService.cs

示例4: DeleteQueuedEmail

        /// <summary>
        /// Deleted a queued email
        /// </summary>
        /// <param name="queuedEmail">Queued email</param>
        public virtual void DeleteQueuedEmail(QueuedEmail queuedEmail)
        {
            if (queuedEmail == null)
                throw new ArgumentNullException("queuedEmail");

            _queuedEmailRepository.Delete(queuedEmail);

            //event notification
            _eventPublisher.EntityDeleted(queuedEmail);
        }
开发者ID:btolbert,项目名称:test-commerce,代码行数:14,代码来源:QueuedEmailService.cs

示例5: Can_save_and_load_queuedEmail

        public void Can_save_and_load_queuedEmail()
        {
            var qe = new QueuedEmail()
            {
                Priority = 1,
                From = "From",
                FromName = "FromName",
                To = "To",
                ToName = "ToName",
                CC = "CC",
                Bcc = "Bcc",
                Subject = "Subject",
                Body = "Body",
                CreatedOnUtc = new DateTime(2010, 01, 01),
                SentTries = 5,
                SentOnUtc = new DateTime(2010, 02, 02),
                EmailAccount = new EmailAccount
                {
                    Email = "[email protected]",
                    DisplayName = "Administrator",
                    Host = "127.0.0.1",
                    Port = 125,
                    Username = "John",
                    Password = "111",
                    EnableSsl = true,
                    UseDefaultCredentials = true
                }

            };

            var fromDb = SaveAndLoadEntity(qe);
            fromDb.ShouldNotBeNull();
            fromDb.Priority.ShouldEqual(1);
            fromDb.From.ShouldEqual("From");
            fromDb.FromName.ShouldEqual("FromName");
            fromDb.To.ShouldEqual("To");
            fromDb.ToName.ShouldEqual("ToName");
            fromDb.CC.ShouldEqual("CC");
            fromDb.Bcc.ShouldEqual("Bcc");
            fromDb.Subject.ShouldEqual("Subject");
            fromDb.Body.ShouldEqual("Body");
            fromDb.CreatedOnUtc.ShouldEqual(new DateTime(2010, 01, 01));
            fromDb.SentTries.ShouldEqual(5);
            fromDb.SentOnUtc.Value.ShouldEqual(new DateTime(2010, 02, 02));

            fromDb.EmailAccount.ShouldNotBeNull();
            fromDb.EmailAccount.DisplayName.ShouldEqual("Administrator");
        }
开发者ID:emretiryaki,项目名称:paymill-nopcommerce,代码行数:48,代码来源:QueuedEmailPersistenceTests.cs

示例6: EmailOperationsManager

        private void EmailOperationsManager(string emailSubject)
        {
            //***************************************************************************************************************
            //* Get the people with roles of Operations Manager so you can email them
            //***************************************************************************************************************
            int omRoleId = _consignorService.GetIdForRole("OperationsManager");
            int[] customerRoleIds = new int[1];

            if (omRoleId != 0)
            {
                customerRoleIds[0] = omRoleId;
            }
            else
            {
                customerRoleIds[0] = 0;  //CustomerRole table begins with 1
                _logger.Warning(string.Format("ApplyMaximums Task could not find a Customer with Operations Manager Role to email results at {0} (UTC {1})",
                    DateTime.Now, DateTime.UtcNow));
                return;
            }

            //this will only find customers with the Operations Manager role
            var omCustomers = _customerService.GetAllCustomers(
                    customerRoleIds: customerRoleIds,
                    pageIndex: 0,
                    pageSize: 500);


            var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
            if (emailAccount == null)
                emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault();
            if (emailAccount == null)
            {
                _logger.Warning(string.Format("ApplyMaximums Task  could not find an email account to email notifications at {0} (UTC {1})",
                    DateTime.Now, DateTime.UtcNow));
                return;
            }

            //************************************************************************************************************
            //* GET THE EMAILACCOUNT TO USE
            //***********************************************************************************************************

            var email = new QueuedEmail
               {
                   Priority = QueuedEmailPriority.High,
                   EmailAccountId = emailAccount.Id,
                   FromName = emailAccount.DisplayName,
                   From = emailAccount.Email,
               };


            if (emailAccount != null)  //can only send emails if an smtp account is set up
            {
                foreach (var c in omCustomers)  //send sale awarded email to all Operations Managers
                {
                    try
                    {
                        if (String.IsNullOrWhiteSpace(c.Email))
                            _logger.Warning(string.Format("ApplyMaximums Task Operations Manager does not have an email to send ApplyMaximums fatal notification - customer id: {0} at {1} (UTC {2})",
                                c.Id, DateTime.Now, DateTime.UtcNow));
                        if (!CommonHelper.IsValidEmail(c.Email))
                            _logger.Warning(string.Format("ApplyMaximums Task Operations Manager does not have a valid email to send ApplyMaximums fatal notification - customer id: {0} at {1} (UTC {2})",
                                c.Id, DateTime.Now, DateTime.UtcNow));

                        email.ToName = c.GetFullName();
                        email.To = c.Email;
                        email.Subject = emailSubject;
                        email.Body = "The body of this email will hold other important statistics in the future";
                        email.CreatedOnUtc = DateTime.UtcNow;

                        _queuedEmailService.InsertQueuedEmail(email);
                        //SuccessNotification(_localizationService.GetResource("Admin.Customers.Customers.SendEmail.Queued"));
                    }
                    catch (Exception exc)
                    {
                        //_logger.Warning(string.Format("AwardInternetSaleTask Operations Manager email failed!  - customer id: {0} sale: {1} store: {2} at {3} (UTC {4}): Exception Message: {5}",
                        //    c.Id, s.AUSaleID, s.SaleStoreID, DateTime.Now, DateTime.UtcNow, exc.Message));

                        _logger.Warning(string.Format("ApplyMaximums Task Operations Manager email failed for id {0} subject {1} time {2}",
                             c.Id, emailSubject,  DateTime.Now));

                    }
                }
            }

        }
开发者ID:HumanSystems,项目名称:nopcommerce-dev,代码行数:85,代码来源:ApplyMaximumsTask.cs

示例7: Requeue

        public ActionResult Requeue(QueuedEmailModel queuedEmailModel)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMessageQueue))
                return AccessDeniedView();

            var queuedEmail = _queuedEmailService.GetQueuedEmailById(queuedEmailModel.Id);
            if (queuedEmail == null)
                //No email found with the specified id
                return RedirectToAction("List");

            var requeuedEmail = new QueuedEmail
            {
                PriorityId = queuedEmail.PriorityId,
                From = queuedEmail.From,
                FromName = queuedEmail.FromName,
                To = queuedEmail.To,
                ToName = queuedEmail.ToName,
                ReplyTo = queuedEmail.ReplyTo,
                ReplyToName = queuedEmail.ReplyToName,
                CC = queuedEmail.CC,
                Bcc = queuedEmail.Bcc,
                Subject = queuedEmail.Subject,
                Body = queuedEmail.Body,
                AttachmentFilePath = queuedEmail.AttachmentFilePath,
                AttachmentFileName = queuedEmail.AttachmentFileName,
                AttachedDownloadId = queuedEmail.AttachedDownloadId,
                CreatedOnUtc = DateTime.UtcNow,
                EmailAccountId = queuedEmail.EmailAccountId
            };
            _queuedEmailService.InsertQueuedEmail(requeuedEmail);

            SuccessNotification(_localizationService.GetResource("Admin.System.QueuedEmails.Requeued"));
            return RedirectToAction("Edit", new { id = requeuedEmail.Id });
        }
开发者ID:491134648,项目名称:nopCommerce,代码行数:34,代码来源:QueuedEmailController.cs

示例8: SendCampaign

        /// <summary>
        /// Sends a campaign to specified emails
        /// </summary>
        /// <param name="campaign">Campaign</param>
        /// <param name="emailAccount">Email account</param>
        /// <param name="subscriptions">Subscriptions</param>
        /// <returns>Total emails sent</returns>
        public virtual int SendCampaign(Campaign campaign, EmailAccount emailAccount,
            IEnumerable<NewsLetterSubscription> subscriptions)
        {
            if (campaign == null)
                throw new ArgumentNullException("campaign");

            if (emailAccount == null)
                throw new ArgumentNullException("emailAccount");

            int totalEmailsSent = 0;

            foreach (var subscription in subscriptions)
            {
                var tokens = new List<Token>();
                _messageTokenProvider.AddStoreTokens(tokens);
                _messageTokenProvider.AddNewsLetterSubscriptionTokens(tokens, subscription);

                string subject = _tokenizer.Replace(campaign.Subject, tokens, false);
                string body = _tokenizer.Replace(campaign.Body, tokens, true);

                var email = new QueuedEmail()
                {
                    Priority = 3,
                    From = emailAccount.Email,
                    FromName = emailAccount.DisplayName,
                    To = subscription.Email,
                    Subject = subject,
                    Body = body,
                    CreatedOnUtc = DateTime.UtcNow,
                    EmailAccountId = emailAccount.Id
                };
                _queuedEmailService.InsertQueuedEmail(email);
                totalEmailsSent++;
            }
            return totalEmailsSent;
        }
开发者ID:pquic,项目名称:qCommerce,代码行数:43,代码来源:CampaignService.cs

示例9: SendEmail

        public ActionResult SendEmail(CustomerModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers))
                return AccessDeniedView();

            var customer = _customerService.GetCustomerById(model.Id);
            if (customer == null)
                //No customer found with the specified id
                return RedirectToAction("List");

            try
            {
                if (String.IsNullOrWhiteSpace(customer.Email))
                    throw new NopException("Customer email is empty");
                if (!CommonHelper.IsValidEmail(customer.Email))
                    throw new NopException("Customer email is not valid");
                if (String.IsNullOrWhiteSpace(model.SendEmail.Subject))
                    throw new NopException("Email subject is empty");
                if (String.IsNullOrWhiteSpace(model.SendEmail.Body))
                    throw new NopException("Email body is empty");

                var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
                if (emailAccount == null)
                    emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault();
                if (emailAccount == null)
                    throw new NopException("Email account can't be loaded");

                var email = new QueuedEmail
                {
                    Priority = 5,
                    EmailAccountId = emailAccount.Id,
                    FromName = emailAccount.DisplayName,
                    From = emailAccount.Email,
                    ToName = customer.GetFullName(),
                    To = customer.Email,
                    Subject = model.SendEmail.Subject,
                    Body = model.SendEmail.Body,
                    CreatedOnUtc = DateTime.UtcNow,
                };
                _queuedEmailService.InsertQueuedEmail(email);
                SuccessNotification(_localizationService.GetResource("Admin.Customers.Customers.SendEmail.Queued"));
            }
            catch (Exception exc)
            {
                ErrorNotification(exc.Message);
            }

            return RedirectToAction("Edit", new { id = customer.Id });
        }
开发者ID:LaOrigin,项目名称:Leorigin,代码行数:49,代码来源:CustomerController.cs

示例10: SendNotification

        protected virtual int SendNotification(MessageTemplate messageTemplate, 
            EmailAccount emailAccount, int languageId, IEnumerable<Token> tokens,
            string toEmailAddress, string toName,
            string attachmentFilePath = null, string attachmentFileName = null,
            string replyToEmailAddress = null, string replyToName = null)
        {
            //retrieve localized message template data
            var bcc = messageTemplate.GetLocalized(mt => mt.BccEmailAddresses, languageId);
            var subject = messageTemplate.GetLocalized(mt => mt.Subject, languageId);
            var body = messageTemplate.GetLocalized(mt => mt.Body, languageId);

            //Replace subject and body tokens 
            var subjectReplaced = _tokenizer.Replace(subject, tokens, false);
            var bodyReplaced = _tokenizer.Replace(body, tokens, true);
            
            var email = new QueuedEmail
            {
                Priority = QueuedEmailPriority.High,
                From = emailAccount.Email,
                FromName = emailAccount.DisplayName,
                To = toEmailAddress,
                ToName = toName,
                ReplyTo = replyToEmailAddress,
                ReplyToName = replyToName,
                CC = string.Empty,
                Bcc = bcc,
                Subject = subjectReplaced,
                Body = bodyReplaced,
                AttachmentFilePath = attachmentFilePath,
                AttachmentFileName = attachmentFileName,
                AttachedDownloadId = messageTemplate.AttachedDownloadId,
                CreatedOnUtc = DateTime.UtcNow,
                EmailAccountId = emailAccount.Id
            };

            _queuedEmailService.InsertQueuedEmail(email);
            return email.Id;
        }
开发者ID:rajendra1809,项目名称:nopCommerce,代码行数:38,代码来源:WorkflowMessageService.cs

示例11: ToEntity

 public static QueuedEmail ToEntity(this QueuedEmailModel model, QueuedEmail destination)
 {
     return Mapper.Map(model, destination);
 }
开发者ID:nguyentu1982,项目名称:quancu,代码行数:4,代码来源:MappingExtensions.cs

示例12: SendNotification

        protected virtual int SendNotification(MessageTemplate messageTemplate, 
            EmailAccount emailAccount, int languageId, IEnumerable<Token> tokens,
            string toEmailAddress, string toName,
            string attachmentFilePath = null, string attachmentFileName = null,
            string replyToEmailAddress = null, string replyToName = null)
        {
            if (messageTemplate == null)
                throw new ArgumentNullException("messageTemplate");
            if (emailAccount == null)
                throw new ArgumentNullException("emailAccount");

            //retrieve localized message template data
            var bcc = messageTemplate.GetLocalized(mt => mt.BccEmailAddresses, languageId);
            var subject = messageTemplate.GetLocalized(mt => mt.Subject, languageId);
            var body = messageTemplate.GetLocalized(mt => mt.Body, languageId);

            //Replace subject and body tokens 
            var subjectReplaced = _tokenizer.Replace(subject, tokens, false);
            var bodyReplaced = _tokenizer.Replace(body, tokens, true);

            //limit name length
            toName = CommonHelper.EnsureMaximumLength(toName, 300);
            
            var email = new QueuedEmail
            {
                Priority = QueuedEmailPriority.High,
                From = emailAccount.Email,
                FromName = emailAccount.DisplayName,
                To = toEmailAddress,
                ToName = toName,
                ReplyTo = replyToEmailAddress,
                ReplyToName = replyToName,
                CC = string.Empty,
                Bcc = bcc,
                Subject = subjectReplaced,
                Body = bodyReplaced,
                AttachmentFilePath = attachmentFilePath,
                AttachmentFileName = attachmentFileName,
                AttachedDownloadId = messageTemplate.AttachedDownloadId,
                CreatedOnUtc = DateTime.UtcNow,
                EmailAccountId = emailAccount.Id,
                DontSendBeforeDateUtc = !messageTemplate.DelayBeforeSend.HasValue ? null
                    : (DateTime?)(DateTime.UtcNow + TimeSpan.FromHours(messageTemplate.DelayPeriod.ToHours(messageTemplate.DelayBeforeSend.Value)))
            };

            _queuedEmailService.InsertQueuedEmail(email);
            return email.Id;
        }
开发者ID:RobinHoody,项目名称:nopCommerce,代码行数:48,代码来源:WorkflowMessageService.cs

示例13: SendCampaign

        /// <summary>
        /// Sends a campaign to specified emails
        /// </summary>
        /// <param name="campaign">Campaign</param>
        /// <param name="emailAccount">Email account</param>
        /// <param name="subscriptions">Subscriptions</param>
        /// <returns>Total emails sent</returns>
        public virtual int SendCampaign(Campaign campaign, EmailAccount emailAccount,
            IEnumerable<NewsLetterSubscription> subscriptions)
        {
            if (campaign == null)
                throw new ArgumentNullException("campaign");

            if (emailAccount == null)
                throw new ArgumentNullException("emailAccount");

            int totalEmailsSent = 0;

            foreach (var subscription in subscriptions)
            {
                var customer = _customerService.GetCustomerByEmail(subscription.Email);
                //ignore deleted or inactive customers when sending newsletter campaigns
                if (customer != null && (!customer.Active || customer.Deleted))
                    continue;

                var tokens = new List<Token>();
                _messageTokenProvider.AddStoreTokens(tokens, _storeContext.CurrentStore, emailAccount);
                _messageTokenProvider.AddNewsLetterSubscriptionTokens(tokens, subscription);
                if (customer != null)
                    _messageTokenProvider.AddCustomerTokens(tokens, customer);

                string subject = _tokenizer.Replace(campaign.Subject, tokens, false);
                string body = _tokenizer.Replace(campaign.Body, tokens, true);

                var email = new QueuedEmail
                {
                    Priority = QueuedEmailPriority.Low,
                    From = emailAccount.Email,
                    FromName = emailAccount.DisplayName,
                    To = subscription.Email,
                    Subject = subject,
                    Body = body,
                    CreatedOnUtc = DateTime.UtcNow,
                    EmailAccountId = emailAccount.Id
                };
                _queuedEmailService.InsertQueuedEmail(email);
                totalEmailsSent++;
            }
            return totalEmailsSent;
        }
开发者ID:rajendra1809,项目名称:nopCommerce,代码行数:50,代码来源:CampaignService.cs

示例14: Requeue

        public ActionResult Requeue(QueuedEmailModel queuedEmailModel)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMessageQueue))
                return AccessDeniedView();

            var queuedEmail = _queuedEmailService.GetQueuedEmailById(queuedEmailModel.Id);
            if (queuedEmail != null)
            {
                var requeuedEmail = new QueuedEmail()
                {
                    Priority = queuedEmail.Priority,
                    From = queuedEmail.From,
                    FromName = queuedEmail.FromName,
                    To = queuedEmail.To,
                    ToName = queuedEmail.ToName,
                    CC = queuedEmail.CC,
                    Bcc = queuedEmail.Bcc,
                    Subject = queuedEmail.Subject,
                    Body = queuedEmail.Body,
                    CreatedOnUtc = DateTime.UtcNow,
                    EmailAccountId = queuedEmail.EmailAccountId
                };
                _queuedEmailService.InsertQueuedEmail(requeuedEmail);

                SuccessNotification(_localizationService.GetResource("Admin.System.QueuedEmails.Requeued"));
                return RedirectToAction("Edit", requeuedEmail.Id);
            }
            else
                return RedirectToAction("List");
        }
开发者ID:cmcginn,项目名称:StoreFront,代码行数:30,代码来源:QueuedEmailController.cs

示例15: Execute

        /// <summary>
        /// Executes a task
        /// </summary>
        public void Execute()
        {
            //60*24 = 1 day
            //var olderThanMinutes = 1440; //TODO move to settings
            //Do not delete more than 1000 records per time. This way the system is not slowed down
            //_customerService.DeleteGuestCustomers(null, DateTime.UtcNow.AddMinutes(-olderThanMinutes), true);

            //sales = _saleRepo.GetById(SaleId);




            //******************************************************************************************************************
            //* AWARD ANY INTERNET SALE THAT IS NOW PAST IS CLOSING TIME THAT IS NOT ALREADY CLOSED. NOTE THAT LIVE SALES WILL NOT BE
            //* BE AUTO-AWARDED - THEY WILL GRADUALLY CLOSE AS THE LIVE AUCTION IS RUN
            //******************************************************************************************************************
            DateTime currTime = DateTime.UtcNow;

            var query = _saleRepo.Table ;
            query = query.Where(c => c.SaleIsActive == false);                           //double check to make sure the sale is not already active
//            query = query.Where(c => c.SaleType == AUSaleTypeEnum.InternetAuction);     // Right now any future saletype will be activated
            query = query.Where(c => c.SaleStartDateTime <= currTime);                    //Make sure the Internet sale is over

            var futureSales = query.ToList();

            if (futureSales == null)  //no sales to award -get outta here
                return;

            //***************************************************************************************************************
            //* There is a sale to award - get the people with roles of Operations Manager so you can notify them of results
            //***************************************************************************************************************
            int omRoleId = _consignorService.GetIdForRole("OperationsManager");
            int[] customerRoleIds = new int[1];
            
            if (omRoleId != 0)
            {
                customerRoleIds[0] = omRoleId;
            }
            else
            {
                customerRoleIds[0] = 0;  //CustomerRole table begins with 1
                _logger.Warning(string.Format("ActivateSale Task could not find a Customer with Operations Manager Role to email results at {0} (UTC {1})",
                    DateTime.Now, DateTime.UtcNow));
            }

            //this will only find customers with the Operations Manager role
            var omCustomers = _customerService.GetAllCustomers(
                    customerRoleIds: customerRoleIds,
                    pageIndex: 0,
                    pageSize: 500);
           

            var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
            if (emailAccount == null)
                emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault();
            if (emailAccount == null)
                _logger.Warning(string.Format("ActivateSale Task could not find an email account to email sale award notifications at {0} (UTC {1})",
                    DateTime.Now, DateTime.UtcNow));

            //************************************************************************************************************
            //* GET THE EMAILACCOUNT TO USE
            //***********************************************************************************************************
           
            
             var email = new QueuedEmail
                {
                    Priority = QueuedEmailPriority.High,
                    EmailAccountId = emailAccount.Id,
                    FromName = emailAccount.DisplayName,
                    From = emailAccount.Email,
                    
                };
           
            foreach (var s in futureSales)
            {
                _consignorService.ActivateSale(s.AUSaleID, s.SaleStoreID);
                _logger.Information(string.Format("ActivateSaleTask activated sale {0} in store {1} at {2} (UTC {3})",
                    s.AUSaleNbr, s.SaleStoreID, DateTime.Now, DateTime.UtcNow));

                if (emailAccount != null)  //can only send emails if an smtp account is set up
                {
                    foreach (var c in omCustomers)  //send sale awarded email to all Operations Managers
                    {
                        try
                        {
                            if (String.IsNullOrWhiteSpace(c.Email))
                                _logger.Warning(string.Format("ActivateSaleTask Operations Manager does not have an email to send sale activation notification - customer id: {0} sale: {1} store: {2} at {3} (UTC {4})",
                                    c.Id, s.AUSaleID, s.SaleStoreID, DateTime.Now, DateTime.UtcNow));
                            if (!CommonHelper.IsValidEmail(c.Email))
                                _logger.Warning(string.Format("ActivateSaleTask Operations Manager does not have a valid email to send sale activation notification - customer id: {0} sale: {1} store: {2} at {3} (UTC {4})",
                                    c.Id, s.AUSaleID, s.SaleStoreID, DateTime.Now, DateTime.UtcNow));

                            email.ToName = c.GetFullName();
                            email.To = c.Email;
                            email.Subject = "Sale has been activated: " + s.AUSaleNbr + ":" + s.SaleTitle;
                            email.Body = "The body of this email will hold other important statistics in the future";
                            email.CreatedOnUtc = DateTime.UtcNow;
//.........这里部分代码省略.........
开发者ID:HumanSystems,项目名称:nopcommerce-dev,代码行数:101,代码来源:ActivateSaleTask.cs


注:本文中的Nop.Core.Domain.Messages.QueuedEmail类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。