/// <summary> /// BarThread转换成<see cref="Lucene.Net.Documents.Document"/> /// </summary> /// <param name="BarThread">发帖实体</param> /// <returns>Lucene.Net.Documents.Document</returns> public static Document Convert(BarThread barThread) { Document doc = new Document(); //索引发帖基本信息 doc.Add(new Field(BarIndexDocument.SectionId, barThread.SectionId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(BarIndexDocument.ThreadId, barThread.ThreadId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(BarIndexDocument.PostId, "0", Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(BarIndexDocument.Subject, barThread.Subject.ToLower(), Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field(BarIndexDocument.Body, HtmlUtility.StripHtml(barThread.GetBody(), true, false).ToLower(), Field.Store.NO, Field.Index.ANALYZED)); doc.Add(new Field(BarIndexDocument.Author, barThread.Author, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field(BarIndexDocument.IsPost, "0", Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(BarIndexDocument.DateCreated, DateTools.DateToString(barThread.DateCreated, DateTools.Resolution.DAY), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(BarIndexDocument.TenantTypeId, barThread.TenantTypeId, Field.Store.YES, Field.Index.NOT_ANALYZED)); //索引发帖tag TagService tagService = new TagService(TenantTypeIds.Instance().BarThread()); IEnumerable<ItemInTag> itemInTags = tagService.GetItemInTagsOfItem(barThread.ThreadId); foreach (ItemInTag itemInTag in itemInTags) { doc.Add(new Field(BarIndexDocument.Tag, itemInTag.TagName.ToLower(), Field.Store.YES, Field.Index.ANALYZED)); } return doc; }
/// <summary> /// 帖子操作日志事件处理 /// </summary> private void BarThreadOperationLogEventModule_After(BarThread senders, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Delete() || eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved() || eventArgs.EventOperationType == EventOperationType.Instance().SetEssential() || eventArgs.EventOperationType == EventOperationType.Instance().SetSticky() || eventArgs.EventOperationType == EventOperationType.Instance().CancelEssential() || eventArgs.EventOperationType == EventOperationType.Instance().CancelSticky()) { OperationLogEntry entry = new OperationLogEntry(eventArgs.OperatorInfo); entry.ApplicationId = entry.ApplicationId; entry.Source = BarConfig.Instance().ApplicationName; entry.OperationType = eventArgs.EventOperationType; entry.OperationObjectName = senders.Subject; entry.OperationObjectId = senders.ThreadId; entry.Description = string.Format(ResourceAccessor.GetString("OperationLog_Pattern_" + eventArgs.EventOperationType), "帖子", entry.OperationObjectName); OperationLogService logService = Tunynet.DIContainer.Resolve<OperationLogService>(); logService.Create(entry); } }
public ActionResult Detail(string spaceKey, long threadId, int pageIndex = 1, bool onlyLandlord = false, SortBy_BarPost sortBy = SortBy_BarPost.DateCreated, long?postId = null, long?childPostIndex = null) { BarThread barThread = barThreadService.Get(threadId); if (barThread == null) { return(HttpNotFound()); } GroupEntity group = groupService.Get(spaceKey); if (group == null) { return(HttpNotFound()); } BarSection section = barSectionService.Get(barThread.SectionId); if (section == null || section.TenantTypeId != TenantTypeIds.Instance().Group()) { return(HttpNotFound()); } //验证是否通过审核 long currentSpaceUserId = UserIdToUserNameDictionary.GetUserId(spaceKey); if (!authorizer.IsAdministrator(BarConfig.Instance().ApplicationId) && barThread.UserId != currentSpaceUserId && (int)barThread.AuditStatus < (int)(new AuditService().GetPubliclyAuditStatus(BarConfig.Instance().ApplicationId))) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "尚未通过审核", Body = "由于当前帖子尚未通过审核,您无法浏览当前内容。", StatusMessageType = StatusMessageType.Hint }))); } pageResourceManager.InsertTitlePart(section.Name); pageResourceManager.InsertTitlePart(barThread.Subject); Category category = categoryService.Get(barThread.CategoryId ?? 0); string keyWords = string.Join(",", barThread.TagNames); pageResourceManager.SetMetaOfKeywords(category != null ? category.CategoryName + "," + keyWords : keyWords); //设置Keyords类型的Meta pageResourceManager.SetMetaOfDescription(HtmlUtility.TrimHtml(barThread.GetResolvedBody(), 120)); //设置Description类型的Meta ViewData["EnableRating"] = barSettings.EnableRating; //更新浏览计数 CountService countService = new CountService(TenantTypeIds.Instance().BarThread()); countService.ChangeCount(CountTypes.Instance().HitTimes(), barThread.ThreadId, barThread.UserId, 1, false); PagingDataSet <BarPost> barPosts = barPostService.Gets(threadId, onlyLandlord, sortBy, pageIndex); if (pageIndex > barPosts.PageCount && pageIndex > 1) { return(Detail(spaceKey, threadId, barPosts.PageCount)); } if (Request.IsAjaxRequest()) { return(PartialView("~/Applications/Bar/Views/Bar/_ListPost.cshtml", barPosts)); } ViewData["barThread"] = barThread; ViewData["group"] = group; return(View(barPosts)); }
public ActionResult EditPost(long threadId, long?postId) { BarThread thread = barThreadService.Get(threadId); if (thread == null) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = "没有找到你要编辑的回帖", Title = "没有找到回帖", StatusMessageType = StatusMessageType.Error }))); } pageResourceManager.InsertTitlePart(thread.BarSection.Name); BarPost post = null; if (postId.HasValue && postId.Value > 0) { post = barPostService.Get(postId ?? 0); if (!new Authorizer().BarPost_Edit(post)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = "您没有权限编辑此回帖", Title = "没有权限" }))); } if (post == null) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = "没有找到你要编辑的回帖", Title = "没有找到回帖" }))); } pageResourceManager.InsertTitlePart("编辑回帖"); } else { string errorMessage = string.Empty; if (!new Authorizer().BarPost_Create(thread.SectionId, out errorMessage)) { if (UserContext.CurrentUser == null) { return(Redirect(SiteUrls.Instance().Login(true))); } return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = errorMessage, Title = "没有权限" }))); } pageResourceManager.InsertTitlePart("发表回帖"); } BarPostEditModel postModel = null; if (post != null) { postModel = post.AsEditModel(); } else { postModel = new BarPostEditModel { ThreadId = threadId, PostId = postId, Subject = thread.Subject } }; ViewData["PostBodyMaxLength"] = barSettings.PostBodyMaxLength; postModel.SectionId = thread.SectionId; return(View(postModel)); }
public ActionResult Edit(string spaceKey, long?threadId) { long sectionId = GroupIdToGroupKeyDictionary.GetGroupId(spaceKey); BarSection section = barSectionService.Get(sectionId); if (UserContext.CurrentUser == null) { return(Redirect(SiteUrls.Instance().Login(true))); } if (section == null) { return(HttpNotFound()); } GroupEntity group = groupService.Get(spaceKey); if (group == null) { return(HttpNotFound()); } pageResourceManager.InsertTitlePart(section.Name); BarThread barThread = threadId.HasValue ? barThreadService.Get(threadId ?? 0) : null; if (threadId.HasValue) { if (!new Authorizer().BarThread_Edit(barThread)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = "没有权限编辑" + barThread.Subject + "!", Title = "没有权限", StatusMessageType = StatusMessageType.Error }))); } } else { string errorMessage = string.Empty; if (!new Authorizer().BarThread_Create(sectionId, out errorMessage)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = errorMessage, Title = "没有权限", StatusMessageType = StatusMessageType.Error }, Request.RawUrl))); } } pageResourceManager.InsertTitlePart(threadId.HasValue ? "编辑帖子" : "发帖"); if (threadId.HasValue && barThread == null) { return(HttpNotFound()); } ViewData["barSettings"] = barSettings; ViewData["group"] = group; ViewData["BarSection"] = section; return(View("Edit", barThread == null ? new BarThreadEditModel { SectionId = sectionId } : barThread.AsEditModel())); }
/// <summary> /// 更新索引 /// </summary> /// <param name="barThread">待更新的发帖</param> public void UpdateBarThread(BarThread barThread) { Document doc = BarIndexDocument.Convert(barThread); searchEngine.Update(doc, barThread.ThreadId.ToString(), BarIndexDocument.ThreadId); }
/// <summary> /// 添加索引 /// </summary> /// <param name="barThread">待添加的发帖</param> public void InsertBarThread(BarThread barThread) { InsertBarThread(new BarThread[] { barThread }); }
/// <summary> /// 动态处理程序 /// </summary> /// <param name="barThread"></param> /// <param name="eventArgs"></param> private void BarThreadActivityModule_After(BarThread barThread, AuditEventArgs eventArgs) { //1、通过审核的内容才生成动态;(不满足) //2、把通过审核的内容设置为未通过审核或者删除内容,需要移除动态;(不满足) //3、把未通过审核的内容通过审核,需要添加动态; (不满足) //4、详见动态需求说明 //生成动态 ActivityService activityService = new ActivityService(); AuditService auditService = new AuditService(); bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) //生成动态 { if (barThread.BarSection == null) { return; } var barUrlGetter = BarUrlGetterFactory.Get(barThread.TenantTypeId); if (barUrlGetter == null) { return; } //生成Owner为帖吧的动态 Activity actvityOfBar = Activity.New(); actvityOfBar.ActivityItemKey = ActivityItemKeys.Instance().CreateBarThread(); actvityOfBar.ApplicationId = BarConfig.Instance().ApplicationId; AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().BarThread()); IEnumerable <Attachment> attachments = attachmentService.GetsByAssociateId(barThread.ThreadId); if (attachments != null && attachments.Any(n => n.MediaType == MediaType.Image)) { actvityOfBar.HasImage = true; } actvityOfBar.IsOriginalThread = true; actvityOfBar.IsPrivate = false; actvityOfBar.UserId = barThread.UserId; actvityOfBar.ReferenceId = 0;//没有涉及到的实体 actvityOfBar.ReferenceTenantTypeId = string.Empty; actvityOfBar.SourceId = barThread.ThreadId; actvityOfBar.TenantTypeId = TenantTypeIds.Instance().BarThread(); actvityOfBar.OwnerId = barThread.SectionId; actvityOfBar.OwnerName = barThread.BarSection.Name; actvityOfBar.OwnerType = barUrlGetter.ActivityOwnerType; activityService.Generate(actvityOfBar, false); if (!barUrlGetter.IsPrivate(barThread.SectionId)) { //生成Owner为用户的动态 Activity actvityOfUser = Activity.New(); actvityOfUser.ActivityItemKey = actvityOfBar.ActivityItemKey; actvityOfUser.ApplicationId = actvityOfBar.ApplicationId; actvityOfUser.HasImage = actvityOfBar.HasImage; actvityOfUser.HasMusic = actvityOfBar.HasMusic; actvityOfUser.HasVideo = actvityOfBar.HasVideo; actvityOfUser.IsOriginalThread = actvityOfBar.IsOriginalThread; actvityOfUser.IsPrivate = actvityOfBar.IsPrivate; actvityOfUser.UserId = actvityOfBar.UserId; actvityOfUser.ReferenceId = actvityOfBar.ReferenceId; actvityOfUser.SourceId = actvityOfBar.SourceId; actvityOfUser.TenantTypeId = actvityOfBar.TenantTypeId; actvityOfUser.OwnerId = barThread.UserId; actvityOfUser.OwnerName = barThread.User.DisplayName; actvityOfUser.OwnerType = ActivityOwnerTypes.Instance().User(); activityService.Generate(actvityOfUser, false); } } else if (auditDirection == false) //删除动态 { activityService.DeleteSource(TenantTypeIds.Instance().BarThread(), barThread.ThreadId); } }
private void BarThread_After(BarThread barThread, CommonEventArgs commonEventArgs) { if (barThread == null) { return; } if (barSearcher == null) { barSearcher = (BarSearcher)SearcherFactory.GetSearcher(BarSearcher.CODE); } //添加索引 if (commonEventArgs.EventOperationType == EventOperationType.Instance().Create()) { barSearcher.InsertBarThread(barThread); } //删除索引 if (commonEventArgs.EventOperationType == EventOperationType.Instance().Delete()) { barSearcher.DeleteBarThread(barThread.ThreadId); } //更新索引 if (commonEventArgs.EventOperationType == EventOperationType.Instance().Update() || commonEventArgs.EventOperationType == EventOperationType.Instance().Approved() || commonEventArgs.EventOperationType == EventOperationType.Instance().Disapproved()) { barSearcher.UpdateBarThread(barThread); } }
/// <summary> /// 动态处理程序 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void BarPostActivityModule_After(BarPost sender, AuditEventArgs eventArgs) { ActivityService activityService = new ActivityService(); AuditService auditService = new AuditService(); bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) //生成动态 { BarThreadService barThreadService = new BarThreadService(); BarThread barThread = barThreadService.Get(sender.ThreadId); if (barThread == null) { return; } if (sender.UserId == barThread.UserId) { return; } var barUrlGetter = BarUrlGetterFactory.Get(barThread.TenantTypeId); if (barUrlGetter == null) { return; } if (sender.ParentId > 0) { BarPost parentPost = new BarPostService().Get(sender.ParentId); if (parentPost == null) { return; } if (parentPost.UserId == sender.UserId) { return; } } Activity actvity = Activity.New(); actvity.ActivityItemKey = ActivityItemKeys.Instance().CreateBarPost(); actvity.ApplicationId = BarConfig.Instance().ApplicationId; //仅一级回复可以上传附件 if (sender.ParentId == 0) { AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().BarPost()); IEnumerable <Attachment> attachments = attachmentService.GetsByAssociateId(sender.PostId); if (attachments != null && attachments.Any(n => n.MediaType == MediaType.Image)) { actvity.HasImage = true; } //actvity.HasMusic = barThread.HasMusic; //actvity.HasVideo = barThread.HasVideo; } actvity.IsOriginalThread = true; actvity.IsPrivate = barUrlGetter.IsPrivate(barThread.SectionId); actvity.OwnerId = barThread.SectionId; actvity.OwnerName = barThread.BarSection.Name; actvity.OwnerType = barUrlGetter.ActivityOwnerType; actvity.ReferenceId = barThread.ThreadId; actvity.ReferenceTenantTypeId = TenantTypeIds.Instance().BarThread(); actvity.SourceId = sender.PostId; actvity.TenantTypeId = TenantTypeIds.Instance().BarPost(); actvity.UserId = sender.UserId; //创建从属内容,不向自己的动态收件箱推送动态 activityService.Generate(actvity, false); } else if (auditDirection == false) //删除动态 { activityService.DeleteSource(TenantTypeIds.Instance().BarPost(), sender.PostId); } }