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


C# YafTemplateEmail.CreateWatch方法代码示例

本文整理汇总了C#中YAF.Core.Services.YafTemplateEmail.CreateWatch方法的典型用法代码示例。如果您正苦于以下问题:C# YafTemplateEmail.CreateWatch方法的具体用法?C# YafTemplateEmail.CreateWatch怎么用?C# YafTemplateEmail.CreateWatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在YAF.Core.Services.YafTemplateEmail的用法示例。


在下文中一共展示了YafTemplateEmail.CreateWatch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ToWatchingUsers

        /// <summary>
        /// The to watching users.
        /// </summary>
        /// <param name="newMessageId">
        /// The new message id.
        /// </param>
        public void ToWatchingUsers(int newMessageId)
        {
            IList<User> usersWithAll = new List<User>();

            if (this.BoardSettings.AllowNotificationAllPostsAllTopics)
            {
                usersWithAll = this.GetRepository<User>()
                    .FindUserTyped(filter: false, notificationType: UserNotificationSetting.AllTopics.ToInt());
            }

            // TODO : Rewrite Watch Topic code to allow watch mails in the users language, as workaround send all messages in the default board language
            var languageFile = this.BoardSettings.Language;
            var boardName = this.BoardSettings.Name;
            var forumEmail = this.BoardSettings.ForumEmail;

            var message = LegacyDb.MessageList(newMessageId).FirstOrDefault();

            var messageAuthorUserID = message.UserID ?? 0;

            var watchEmail = new YafTemplateEmail("TOPICPOST") { TemplateLanguageFile = languageFile };

            // cleaned body as text...
            var bodyText =
                BBCodeHelper.StripBBCode(HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString(message.Message)))
                    .RemoveMultipleWhitespace();

            // Send track mails
            var subject =
                this.Get<ILocalization>()
                    .GetText("COMMON", "TOPIC_NOTIFICATION_SUBJECT", languageFile)
                    .FormatWith(boardName);

            watchEmail.TemplateParams["{forumname}"] = boardName;
            watchEmail.TemplateParams["{topic}"] = HttpUtility.HtmlDecode(message.Topic);
            watchEmail.TemplateParams["{postedby}"] = UserMembershipHelper.GetDisplayNameFromID(messageAuthorUserID);
            watchEmail.TemplateParams["{body}"] = bodyText;
            watchEmail.TemplateParams["{bodytruncated}"] = bodyText.Truncate(160);
            watchEmail.TemplateParams["{link}"] = YafBuildLink.GetLinkNotEscaped(
                ForumPages.posts,
                true,
                "m={0}#post{0}",
                newMessageId);

            watchEmail.CreateWatch(
                message.TopicID ?? 0,
                messageAuthorUserID,
                new MailAddress(forumEmail, boardName),
                subject);

            // create individual watch emails for all users who have All Posts on...
            foreach (var user in usersWithAll.Where(x => x.UserID != messageAuthorUserID && x.ProviderUserKey != null))
            {
                var membershipUser = UserMembershipHelper.GetUser(user.Name);

                if (membershipUser == null || membershipUser.Email.IsNotSet())
                {
                    continue;
                }

                watchEmail.TemplateLanguageFile = user.LanguageFile.IsSet()
                                                      ? user.LanguageFile
                                                      : this.Get<ILocalization>().LanguageFileName;
                watchEmail.SendEmail(
                    new MailAddress(forumEmail, boardName),
                    new MailAddress(membershipUser.Email, membershipUser.UserName),
                    subject,
                    true);
            }
        }
开发者ID:viniciustodesco,项目名称:YAFNET,代码行数:75,代码来源:YafSendNotification.cs

示例2: ToWatchingUsers

        /// <summary>
        /// The to watching users.
        /// </summary>
        /// <param name="newMessageId">
        /// The new message id.
        /// </param>
        public void ToWatchingUsers(int newMessageId)
        {
            IEnumerable<TypedUserFind> usersWithAll = new List<TypedUserFind>();

            if (this.Get<YafBoardSettings>().AllowNotificationAllPostsAllTopics)
            {
                // TODO: validate permissions!
                usersWithAll = CommonDb.UserFind(YafContext.Current.PageModuleID, YafContext.Current.PageBoardID,
                    false,
                    null,
                    null,
                    null,
                    UserNotificationSetting.AllTopics.ToInt(),
                    null);
            }

            // TODO : Rewrite Watch Topic code to allow watch mails in the users language, as workaround send all messages in the default board language
            var languageFile =  this.Get<YafBoardSettings>().Language;

            foreach (var message in CommonDb.MessageList(YafContext.Current.PageModuleID, newMessageId))
            {
                int userId = message.UserID ?? 0;

                var watchEmail = new YafTemplateEmail("TOPICPOST") { TemplateLanguageFile = languageFile };

                // cleaned body as text...
                var bodyText =
                    StringExtensions.RemoveMultipleWhitespace(
                        BBCodeHelper.StripBBCode(HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString(message.Message))));

                // Send track mails
                var subject =
                    this.Get<ILocalization>().GetText("COMMON", "TOPIC_NOTIFICATION_SUBJECT", languageFile).FormatWith(
                        this.Get<YafBoardSettings>().Name);

                watchEmail.TemplateParams["{forumname}"] = this.Get<YafBoardSettings>().Name;
                watchEmail.TemplateParams["{topic}"] = HttpUtility.HtmlDecode(message.Topic);
                watchEmail.TemplateParams["{postedby}"] = UserMembershipHelper.GetDisplayNameFromID(userId);
                watchEmail.TemplateParams["{body}"] = bodyText;
                watchEmail.TemplateParams["{bodytruncated}"] = bodyText.Truncate(160);
                watchEmail.TemplateParams["{link}"] = YafBuildLink.GetLinkNotEscaped(
                    ForumPages.posts, true, "m={0}#post{0}", newMessageId);

                watchEmail.CreateWatch(
                    message.TopicID ?? 0,
                    userId,
                    new MailAddress(this.Get<YafBoardSettings>().ForumEmail, this.Get<YafBoardSettings>().Name),
                    subject);

                // create individual watch emails for all users who have All Posts on...
                foreach (var user in usersWithAll.Where(x => x.UserID.HasValue && x.UserID.Value != userId))
                {
                    // Make sure its not a guest
                    if (user.ProviderUserKey == null)
                    {
                        continue;
                    }

                    var membershipUser = UserMembershipHelper.GetUser(user.ProviderUserKey);

                    if (!membershipUser.Email.IsSet())
                    {
                        continue;
                    }

                    watchEmail.TemplateLanguageFile = !string.IsNullOrEmpty(user.LanguageFile)
                                                          ? user.LanguageFile
                                                          : this.Get<ILocalization>().LanguageFileName;
                    watchEmail.SendEmail(
                        new MailAddress(this.Get<YafBoardSettings>().ForumEmail, this.Get<YafBoardSettings>().Name),
                        new MailAddress(membershipUser.Email, membershipUser.UserName),
                        subject,
                        true);
                }
            }
        }
开发者ID:vzrus,项目名称:VZF,代码行数:82,代码来源:YafSendNotification.cs


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