public string Process(string body, string tenantTypeId, long associateId, long userId) { //解析at用户 AtUserService atUserService = new AtUserService(TenantTypeIds.Instance().BlogThread()); body = atUserService.ResolveBodyForDetail(body, associateId, userId, AtUserTagGenerate); AttachmentService attachmentService = new AttachmentService(tenantTypeId); IEnumerable <Attachment> attachments = attachmentService.GetsByAssociateId(associateId); if (attachments != null && attachments.Count() > 0) { IList <BBTag> bbTags = new List <BBTag>(); string htmlTemplate = "<div class=\"tn-annexinlaid\"><a href=\"javascript:;\" target=\"_blank\" menu=\"#attachement-artdialog-{4}\">{0}</a>(<em>{1}</em>{2},<em>下载次数:{3}</em>)</div>"; //解析文本中附件 IEnumerable <Attachment> attachmentsFiles = attachments.Where(n => n.MediaType != MediaType.Image); foreach (var attachment in attachmentsFiles) { bbTags.Add(AddBBTag(htmlTemplate, attachment)); } body = HtmlUtility.BBCodeToHtml(body, bbTags); } body = new EmotionService().EmoticonTransforms(body); body = DIContainer.Resolve <ParsedMediaService>().ResolveBodyForHtmlDetail(body, ParsedMediaTagGenerate); return(body); }
/// <summary> /// 内容处理 /// </summary> /// <param name="body">待处理内容</param> /// <param name="associateId">待处理相关项Id</param> /// <param name="userId">相关项作者</param> /// <param name="ownerId">拥有者Id</param> /// <returns></returns> public string Process(string body, string ownerTenantTypeId, long associateId, long userId, long ownerId) { string tenantTypeId = TenantTypeIds.Instance().Microblog(); AtUserService atUserService = new AtUserService(tenantTypeId); body = atUserService.ResolveBodyForDetail(body, associateId, userId, AtUserTagGenerate); TagService tagService = new TagService(tenantTypeId); Func <KeyValuePair <string, long>, long, string> topicTagGenerate = delegate(KeyValuePair <string, long> _tagNameWithId, long _ownerId) { return(string.Format("<a href=\"{1}\">#{0}#</a>", _tagNameWithId.Key, MicroblogUrlGetterFactory.Get(ownerTenantTypeId).TopicDetail(_tagNameWithId.Key.Trim(), _ownerId))); }; body = tagService.ResolveBodyForDetail(body, associateId, ownerId, topicTagGenerate); body = body.Replace("\n", "<br/>"); EmotionService emotionService = DIContainer.Resolve <EmotionService>(); body = emotionService.EmoticonTransforms(body); ParsedMediaService parsedMediaService = DIContainer.Resolve <ParsedMediaService>(); body = parsedMediaService.ResolveBodyForDetail(body, associateId, userId, UrlTagGenerate); return(body); }
/// <summary> /// 手机端帖子正文解析器 /// </summary> /// <param name="body"></param> /// <param name="tenantTypeId"></param> /// <param name="associateId"></param> /// <param name="userId"></param> /// <returns></returns> public string ProcessForMobile(string body, string tenantTypeId, long associateId, long userId) { //解析at用户 AtUserService atUserService = new AtUserService(tenantTypeId); body = atUserService.ResolveBodyForDetail(body, associateId, userId, AtUserTagGenerate); AttachmentService attachmentService = new AttachmentService(tenantTypeId); IEnumerable <Attachment> attachments = attachmentService.GetsByAssociateId(associateId); if (attachments != null && attachments.Count() > 0) { IList <BBTag> bbTags = new List <BBTag>(); string htmlTemplate = "<a href=\"{1}\" target=\"_blank\" menu=\"#attachement-artdialog-{2}\">{0}</a>"; //解析文本中附件 IEnumerable <Attachment> attachmentsFiles = attachments.Where(n => n.MediaType != MediaType.Image); foreach (var attachment in attachmentsFiles) { bbTags.Add(AddBBTagForMobile(htmlTemplate, attachment)); } body = HtmlUtility.BBCodeToHtml(body, bbTags); } body = new EmotionService().EmoticonTransforms(body); body = DIContainer.Resolve <ParsedMediaService>().ResolveBodyForHtmlDetail(body, ParsedMediaTagGenerateForMobile); return(body); }
/// <summary> /// 编辑问题 /// </summary> /// <remarks> /// 1.使用AuditService.ChangeAuditStatusForUpdate设置审核状态; /// 2.Repository更新时不处理:IsEssential /// 3.需要触发的事件:Update的OnBefore、OnAfter; /// </remarks> /// <param name="question">问题实体</param> /// <param name="changeAuditStatusForUpdate">是否更新审核状态</param> public void UpdateQuestion(AskQuestion question, bool changeAuditStatusForUpdate = true) { AskQuestion question_beforeUpDate = GetQuestion(question.QuestionId); if (question.Reward != question_beforeUpDate.Reward && question.Reward < (question.User.TradePoints + question_beforeUpDate.Reward)) { question.AddedReward = question.Reward - question_beforeUpDate.Reward; } else { question.AddedReward = 0; } EventBus <AskQuestion> .Instance().OnBefore(question, new CommonEventArgs(EventOperationType.Instance().Update())); AuditStatus prevAuditStatus = question.AuditStatus; //设置审核状态 if (changeAuditStatusForUpdate) { new AuditService().ChangeAuditStatusForUpdate(question.UserId, question); } askQuestionRepository.Update(question); AtUserService atUserService = new AtUserService(TenantTypeIds.Instance().AskQuestion()); atUserService.ResolveBodyForEdit(question.Body, question.UserId, question.QuestionId); EventBus <AskQuestion> .Instance().OnAfter(question, new CommonEventArgs(EventOperationType.Instance().Update())); EventBus <AskQuestion, AuditEventArgs> .Instance().OnAfter(question, new AuditEventArgs(prevAuditStatus, question.AuditStatus)); }
/// <summary> /// 发布问题 /// </summary> /// <remarks> /// 1.用户提问时,悬赏的积分会被冻结,需要先扣除相应的用户积分;同时发布问题会产生新积分 /// 2.注意在EventModule中处理动态、积分、通知、自动关注(提问者自动关注该问题); /// 3.使用AuditService.ChangeAuditStatusForCreate设置审核状态; /// 4.注意调用AttachmentService转换临时附件; /// 5.需要触发的事件:1)Create的OnBefore、OnAfter;2)审核状态变更; /// </remarks> /// <param name="question">问题实体</param> /// <returns>是否创建成功</returns> public bool CreateQuestion(AskQuestion question) { EventBus <AskQuestion> .Instance().OnBefore(question, new CommonEventArgs(EventOperationType.Instance().Create())); //设置审核状态 new AuditService().ChangeAuditStatusForCreate(question.UserId, question); askQuestionRepository.Insert(question); if (question.QuestionId > 0) { //将临时附件转换为正式附件 AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().AskQuestion()); attachmentService.ToggleTemporaryAttachments(question.UserId, TenantTypeIds.Instance().AskQuestion(), question.QuestionId); //用户计数 OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(question.UserId, OwnerDataKeys.Instance().QuestionCount(), 1); AtUserService atUserService = new AtUserService(TenantTypeIds.Instance().AskQuestion()); atUserService.ResolveBodyForEdit(question.Body, question.UserId, question.QuestionId); EventBus <AskQuestion> .Instance().OnAfter(question, new CommonEventArgs(EventOperationType.Instance().Create())); EventBus <AskQuestion, AuditEventArgs> .Instance().OnAfter(question, new AuditEventArgs(null, question.AuditStatus)); } return(question.QuestionId > 0); }
/// <summary> /// 通知处理 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> void CommentNoticeEventModule_After(Comment sender, AuditEventArgs eventArgs) { AuditService auditService = new AuditService(); bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) { var urlGetter = CommentUrlGetterFactory.Get(sender.TenantTypeId); var commentedObject = urlGetter.GetCommentedObject(sender.CommentedObjectId); var senderUser = sender.User(); if (urlGetter == null || commentedObject == null) { return; } //文章有新评论时,自动通知原作者 var toUserIds = new List <long>(); //评论相关的atuserid List <long> userids = new AtUserService(TenantTypeIds.Instance().Comment()).GetAtUserIds(sender.Id); if (!userids.Contains(commentedObject.UserId)) { toUserIds.Add(commentedObject.UserId); } if (sender.ParentId > 0 && !userids.Contains(sender.ToUserId)) { toUserIds.Add(sender.ToUserId); } foreach (var toUserId in toUserIds) { //通知的对象排除掉自己 if (toUserId == sender.UserId) { continue; } Notice notice = Notice.New(); notice.UserId = toUserId; notice.ApplicationId = 0; notice.TypeId = NoticeTypeIds.Instance().Reply(); notice.LeadingActor = senderUser != null ? senderUser.DisplayName : "匿名用户"; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(UserIdToUserNameDictionary.GetUserName(sender.UserId))); notice.RelativeObjectName = StringUtility.Trim(commentedObject.Name, 60); notice.RelativeObjectId = sender.Id; notice.RelativeObjectUrl = SiteUrls.FullUrl(urlGetter.GetCommentDetailUrl(sender.CommentedObjectId, sender.Id, commentedObject.UserId)) ?? string.Empty; notice.TemplateName = sender.ParentId > 0 ? NoticeTemplateNames.Instance().NewReply() : NoticeTemplateNames.Instance().NewComment(); new NoticeService().Create(notice); } } }
/// <summary> /// 内容处理 /// </summary> /// <param name="body">待处理内容</param> /// <param name="associateId">待处理相关项Id</param> /// <param name="userId">相关项作者</param> /// <param name="tenantTypeId">租户类型Id</param> /// <returns></returns> public string Process(string body, string tenantTypeId, long associateId, long userId) { tenantTypeId = TenantTypeIds.Instance().Comment(); AtUserService atUserService = new AtUserService(tenantTypeId); atUserService.ResolveBodyForEdit(body, userId, associateId); body = atUserService.ResolveBodyForDetail(body, associateId, userId, AtUserTagGenerate); EmotionService emotionService = DIContainer.Resolve <EmotionService>(); body = emotionService.EmoticonTransforms(body); return(body); }
/// <summary> /// 更新帖子 /// </summary> /// <param name="entity"></param> public override void Update(BarThread entity) { base.Update(entity); //更新解析正文缓存 string cacheKey = GetCacheKeyOfResolvedBody(entity.ThreadId); string resolveBody = cacheService.Get <string>(cacheKey); if (resolveBody != null) { resolveBody = entity.GetBody(); AtUserService atUserService = new AtUserService(TenantTypeIds.Instance().BarThread()); atUserService.ResolveBodyForEdit(resolveBody, entity.UserId, entity.ThreadId); resolveBody = barBodyProcessor.Process(resolveBody, TenantTypeIds.Instance().BarThread(), entity.ThreadId, entity.UserId); cacheService.Set(cacheKey, resolveBody, CachingExpirationType.SingleObject); } }
/// <summary> /// 获取提到用户的微博分页集合 /// </summary> /// <param name="userName">被提到的用户Id</param> /// <param name="pageIndex">页码</param> /// <returns></returns> public PagingDataSet <MicroblogEntity> GetMicroblogsByReferredUser(long userId, int pageIndex) { AtUserService atUserService = new AtUserService(TenantTypeIds.Instance().Microblog()); PagingDataSet <long> pagingIds = atUserService.GetPagingAssociateIds(userId, pageIndex); if (pagingIds != null) { PagingDataSet <MicroblogEntity> pds = new PagingDataSet <MicroblogEntity>(microblogRepository.PopulateEntitiesByEntityIds(pagingIds)); pds.PageIndex = pagingIds.PageIndex; pds.PageSize = pagingIds.PageSize; pds.TotalRecords = pagingIds.TotalRecords; return(pds); } return(null); }
/// <summary> /// 创建主题帖 /// </summary> /// <param name="thread">主题帖</param> public bool Create(BarThread thread) { BarSectionService barSectionService = new BarSectionService(); EventBus <BarThread> .Instance().OnBefore(thread, new CommonEventArgs(EventOperationType.Instance().Create())); //设置审核状态 auditService.ChangeAuditStatusForCreate(thread.UserId, thread); long id = 0; long.TryParse(barThreadRepository.Insert(thread).ToString(), out id); if (id > 0) { new AttachmentService(TenantTypeIds.Instance().BarThread()).ToggleTemporaryAttachments(thread.UserId, TenantTypeIds.Instance().BarThread(), id); BarSection barSection = barSectionService.Get(thread.SectionId); if (barSection != null) { //计数 CountService countService = new CountService(TenantTypeIds.Instance().BarSection()); countService.ChangeCount(CountTypes.Instance().ThreadCount(), barSection.SectionId, barSection.UserId, 1, true); countService.ChangeCount(CountTypes.Instance().ThreadAndPostCount(), barSection.SectionId, barSection.UserId, 1, true); if (thread.TenantTypeId == TenantTypeIds.Instance().Group()) { //群组内容计数+1 OwnerDataService groupOwnerDataService = new OwnerDataService(TenantTypeIds.Instance().Group()); groupOwnerDataService.Change(thread.SectionId, OwnerDataKeys.Instance().ThreadCount(), 1); } } if (thread.TenantTypeId == TenantTypeIds.Instance().Bar()) { //用户内容计数+1 OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(thread.UserId, OwnerDataKeys.Instance().ThreadCount(), 1); } AtUserService atUserService = new AtUserService(TenantTypeIds.Instance().BarThread()); atUserService.ResolveBodyForEdit(thread.GetBody(), thread.UserId, thread.ThreadId); EventBus <BarThread> .Instance().OnAfter(thread, new CommonEventArgs(EventOperationType.Instance().Create())); EventBus <BarThread, AuditEventArgs> .Instance().OnAfter(thread, new AuditEventArgs(null, thread.AuditStatus)); } return(id > 0); }
/// <summary> /// 创建微博 /// </summary> /// <param name="microblog">待创建微博实体</param> /// <returns></returns> public long Create(MicroblogEntity microblog) { EventBus <MicroblogEntity> .Instance().OnBefore(microblog, new CommonEventArgs(EventOperationType.Instance().Create())); //设置审核状态 auditService.ChangeAuditStatusForCreate(microblog.UserId, microblog); string videoAlias = string.Empty, audioAlias = string.Empty; microblog.Body = parsedMediaService.ResolveBodyForEdit(microblog.Body, out videoAlias, out audioAlias); microblog.HasVideo = !string.IsNullOrEmpty(videoAlias); microblog.HasMusic = !string.IsNullOrEmpty(audioAlias); microblog.VideoAlias = videoAlias; microblog.AudioAlias = audioAlias; long id = 0; long.TryParse(microblogRepository.Insert(microblog).ToString(), out id); if (id > 0) { string tenantTypeId = TenantTypeIds.Instance().Microblog(); OwnerDataService ownerDataService = new OwnerDataService(microblog.TenantTypeId); ownerDataService.Change(microblog.OwnerId, OwnerDataKeys.Instance().ThreadCount(), 1); //将临时附件转换为正式附件 attachmentService.ToggleTemporaryAttachments(microblog.UserId, tenantTypeId, id); AtUserService atUserService = new AtUserService(tenantTypeId); atUserService.ResolveBodyForEdit(microblog.Body, microblog.UserId, microblog.MicroblogId); TagService tagService = new TagService(tenantTypeId); tagService.ResolveBodyForEdit(microblog.Body, microblog.OwnerId, microblog.MicroblogId, tenantTypeId); EventBus <MicroblogEntity> .Instance().OnAfter(microblog, new CommonEventArgs(EventOperationType.Instance().Create())); EventBus <MicroblogEntity, AuditEventArgs> .Instance().OnAfter(microblog, new AuditEventArgs(null, microblog.AuditStatus)); } return(id); }
public string Process(string body, string tenantTypeId, long associateId, long userId) { //if (string.IsNullOrEmpty(body) || !body.Contains("[attach:")) // return body; //List<long> attachmentIds = new List<long>(); //Regex rg = new Regex(@"\[attach:(?<id>[\d]+)\]", RegexOptions.Multiline | RegexOptions.Singleline); //MatchCollection matches = rg.Matches(body); //if (matches != null) //{ // foreach (Match m in matches) // { // if (m.Groups["id"] == null || string.IsNullOrEmpty(m.Groups["id"].Value)) // continue; // long attachmentId = 0; // long.TryParse(m.Groups["id"].Value, out attachmentId); // if (attachmentId > 0 && !attachmentIds.Contains(attachmentId)) // attachmentIds.Add(attachmentId); // } //} //IEnumerable<ContentAttachment> attachments = new ContentAttachmentService().Gets(attachmentIds); //if (attachments != null && attachments.Count() > 0) //{ // IList<BBTag> bbTags = new List<BBTag>(); // string htmlTemplate = "<div class=\"tn-annexinlaid\"><a href=\"{3}\" rel=\"nofollow\">{0}</a>(<em>{1}</em>,<em>下载次数:{2}</em>)<a href=\"{3}\" rel=\"nofollow\">下载</a> </div>"; // //解析文本中附件 // foreach (var attachment in attachments) // { // bbTags.Add(AddBBTag(htmlTemplate, attachment)); // } // body = HtmlUtility.BBCodeToHtml(body, bbTags); //} //解析at用户 AtUserService atUserService = new AtUserService(tenantTypeId); body = atUserService.ResolveBodyForDetail(body, associateId, userId, AtUserTagGenerate); AttachmentService attachmentService = new AttachmentService(tenantTypeId); IEnumerable <Attachment> attachments = attachmentService.GetsByAssociateId(associateId); if (attachments != null && attachments.Count() > 0) { IList <BBTag> bbTags = new List <BBTag>(); string htmlTemplate = "<div class=\"tn-annexinlaid\"><a href=\"{3}\" rel=\"nofollow\">{0}</a>(<em>{1}</em>,<em>下载次数:{2}</em>)<a href=\"{3}\" rel=\"nofollow\">下载</a> </div>"; //解析文本中附件 IEnumerable <Attachment> attachmentsFiles = attachments.Where(n => n.MediaType != MediaType.Image); foreach (var attachment in attachmentsFiles) { bbTags.Add(AddBBTag(htmlTemplate, attachment)); } body = HtmlUtility.BBCodeToHtml(body, bbTags); } body = new EmotionService().EmoticonTransforms(body); body = DIContainer.Resolve <ParsedMediaService>().ResolveBodyForHtmlDetail(body, ParsedMediaTagGenerate); return(body); }
/// <summary> /// 撰写日志/转载日志 /// </summary> /// <param name="blogThread">日志实体</param> public bool Create(BlogThread blogThread, string privacyStatus1 = null, string privacyStatus2 = null) { //设计要点 //1、使用AuditService设置审核状态; //2、注意调用AttachmentService转换临时附件; //3、需要触发的事件参见《设计说明书-日志》 //4、草稿的审核状态为待审核; //5、转载的日志还需要为原日志转载数+1(调用计数服务); EventBus <BlogThread> .Instance().OnBefore(blogThread, new CommonEventArgs(EventOperationType.Instance().Create())); //设置审核状态,草稿的审核状态为待审核 if (blogThread.IsDraft) { blogThread.AuditStatus = AuditStatus.Pending; } else { AuditService auditService = new AuditService(); auditService.ChangeAuditStatusForCreate(blogThread.UserId, blogThread); } long threadId = 0; long.TryParse(blogThreadRepository.Insert(blogThread).ToString(), out threadId); if (threadId > 0) { //转换临时附件 AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().BlogThread()); attachmentService.ToggleTemporaryAttachments(blogThread.OwnerId, TenantTypeIds.Instance().BlogThread(), blogThread.ThreadId); //原日志转载数+1 if (blogThread.IsReproduced) { CountService countService = new CountService(TenantTypeIds.Instance().BlogThread()); countService.ChangeCount(CountTypes.Instance().ReproduceCount(), blogThread.OriginalThreadId, blogThread.OwnerId, 1, true); } //用户内容计数+1 if (!blogThread.IsDraft) { OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(blogThread.UserId, OwnerDataKeys.Instance().ThreadCount(), 1); } AtUserService atUserService = new AtUserService(TenantTypeIds.Instance().BlogThread()); atUserService.ResolveBodyForEdit(blogThread.GetBody(), blogThread.UserId, blogThread.ThreadId); //设置隐私状态 UpdatePrivacySettings(blogThread, privacyStatus1, privacyStatus2); EventBus <BlogThread> .Instance().OnAfter(blogThread, new CommonEventArgs(EventOperationType.Instance().Create())); EventBus <BlogThread, AuditEventArgs> .Instance().OnAfter(blogThread, new AuditEventArgs(null, blogThread.AuditStatus)); return(true); } return(false); }