/// <summary> /// 应用加载 /// </summary> public override void Load() { base.Load(); //注册日志Rss浏览计数服务 CountService countService = new CountService(TenantTypeIds.Instance().Microblog()); countService.RegisterCounts(); //注册计数服务 countService.RegisterCountPerDay(); //需要统计阶段计数时,需注册每日计数服务 countService.RegisterStageCount(CountTypes.Instance().CommentCount(), 1); //注册微博用户计数服务 List <string> tenantTypeIds = new List <string>() { TenantTypeIds.Instance().User(), TenantTypeIds.Instance().Group() }; OwnerDataSettings.RegisterStatisticsDataKeys(tenantTypeIds, OwnerDataKeys.Instance().ThreadCount()); TagUrlGetterManager.RegisterGetter(TenantTypeIds.Instance().Microblog(), new MicroblogTagUrlGetter()); //添加应用管理员角色 ApplicationAdministratorRoleNames.Add(ApplicationIds.Instance().Microblog(), new List <string> { "MicroblogAdministrator" }); }
/// <summary> /// 应用加载 /// </summary> public override void Load() { base.Load(); //注册日志计数服务 CountService countService = new CountService(TenantTypeIds.Instance().BlogThread()); //注册计数服务 countService.RegisterCounts(); //需要统计阶段计数时,需注册每日计数服务 countService.RegisterCountPerDay(); //注册日志浏览计数服务 countService.RegisterStageCount(CountTypes.Instance().HitTimes(), 7); //注册用户计数服务 OwnerDataSettings.RegisterStatisticsDataKeys(TenantTypeIds.Instance().User(), OwnerDataKeys.Instance().ThreadCount()); //标签云中标签的链接 TagUrlGetterManager.RegisterGetter(TenantTypeIds.Instance().BlogThread(), new BlogTagUrlGetter()); //添加应用管理员角色 ApplicationAdministratorRoleNames.Add(ApplicationIds.Instance().Blog(), new List <string> { "BlogAdministrator" }); }
/// <summary> /// 应用加载 /// </summary> public override void Load() { base.Load(); //注册帖吧计数服务 CountService countService = new CountService(TenantTypeIds.Instance().BarSection()); countService.RegisterCounts(); //注册计数服务 countService.RegisterCountPerDay(); //需要统计阶段计数时,需注册每日计数服务 countService.RegisterStageCount(CountTypes.Instance().ThreadAndPostCount(), 1); //注册帖子计数服务 countService = new CountService(TenantTypeIds.Instance().BarThread()); countService.RegisterCounts(); //注册计数服务 countService.RegisterCountPerDay(); //需要统计阶段计数时,需注册每日计数服务 countService.RegisterStageCount(CountTypes.Instance().HitTimes(), 1, 7); //注册贴吧用户计数服务 List <string> tenantTypeIds = new List <string>() { TenantTypeIds.Instance().User(), TenantTypeIds.Instance().Group() }; OwnerDataSettings.RegisterStatisticsDataKeys(tenantTypeIds , OwnerDataKeys.Instance().ThreadCount() , OwnerDataKeys.Instance().PostCount() , OwnerDataKeys.Instance().FollowSectionCount()); TagUrlGetterManager.RegisterGetter(TenantTypeIds.Instance().BarThread(), new BarTagUrlGetter()); TagUrlGetterManager.RegisterGetter(TenantTypeIds.Instance().Group(), new BarTagUrlGetter()); //添加应用管理员角色 ApplicationAdministratorRoleNames.Add(ApplicationIds.Instance().Bar(), new List <string> { "BarAdministrator" }); }
/// <summary> /// 分页获取非主流排序方式的ContentItem /// </summary> public PagingDataSet <ContentItem> GetContentItemsSortBy(ContentItemSortBy sortBy, int?contentTypeId = null, int?contentFolderId = null, bool includeFolderDescendants = true, string tagName = null, int pageSize = 15, int pageIndex = 1) { ContentItemQuery query; if (contentFolderId.HasValue) { query = new ContentItemQuery(CacheVersionType.AreaVersion); query.AreaCachePropertyName = "ContentFolderId"; query.AreaCachePropertyValue = contentFolderId.Value; query.ContentFolderId = contentFolderId; } else { query = new ContentItemQuery(CacheVersionType.GlobalVersion); } query.IncludeFolderDescendants = includeFolderDescendants; query.SortBy = sortBy; query.PubliclyAuditStatus = new AuditService().GetPubliclyAuditStatus(ApplicationIds.Instance().CMS()); query.TagName = tagName; if (contentTypeId.HasValue && contentTypeId.Value > 0) { query.ContentTypeId = contentTypeId; } return(contentItemRepository.GetContentItems(true, query, pageSize, pageIndex)); }
/// <summary> /// 获取MicroblogConfig实例 /// </summary> public static MicroblogConfig Instance() { ApplicationBase app = DIContainer.Resolve <ApplicationService>().Get(ApplicationIds.Instance().Microblog()); if (app != null) { return(app.Config as MicroblogConfig); } else { return(null); } }
/// <summary> /// 获取BlogConfig实例 /// </summary> public static BlogConfig Instance() { ApplicationService applicationService = new ApplicationService(); ApplicationBase app = applicationService.Get(ApplicationIds.Instance().Blog()); if (app != null) { return(app.Config as BlogConfig); } else { return(null); } }
/// <summary> /// 删除栏目 /// </summary> /// <param name="contentFolder"></param> public void Delete(ContentFolder contentFolder) { if (contentFolder == null) { return; } //更新父栏目的ChildCount if (contentFolder.ParentId > 0) { ContentFolder parentContentFolder = Get(contentFolder.ParentId); if (parentContentFolder != null) { parentContentFolder.ChildCount -= 1; contentFolderRepository.Update(parentContentFolder); } } ContentItemService contentItemService = new ContentItemService(); //所有后代栏目 IEnumerable <ContentFolder> descendantContentFolders = GetDescendants(contentFolder.ContentFolderId); if (descendantContentFolders != null) { foreach (var item in descendantContentFolders) { contentItemService.DeleteByFolder(item.ContentFolderId); contentFolderRepository.Delete(item); } } contentFolderRepository.Delete(contentFolder); contentItemService.DeleteByFolder(contentFolder.ContentFolderId); EntityData.ForType(typeof(Navigation)).RealTimeCacheHelper.IncreaseAreaVersion("OwnerId", 0); //执行事件 EventBus <ContentFolder> .Instance().OnAfter(contentFolder, new CommonEventArgs(EventOperationType.Instance().Delete(), ApplicationIds.Instance().CMS())); }
/// <summary> /// 更新栏目 /// </summary> /// <remarks> /// 不要修改ParentId,如需修改请使用Move() /// </remarks> /// <param name="contentFolder"></param> public void Update(ContentFolder contentFolder) { contentFolderRepository.Update(contentFolder); EntityData.ForType(typeof(Navigation)).RealTimeCacheHelper.IncreaseAreaVersion("OwnerId", 0); //执行事件 EventBus <ContentFolder> .Instance().OnAfter(contentFolder, new CommonEventArgs(EventOperationType.Instance().Update(), ApplicationIds.Instance().CMS())); }
/// <summary> /// 创建栏目 /// </summary> /// <param name="contentFolder"></param> public void Create(ContentFolder contentFolder) { if (contentFolder.ParentId > 0) { ContentFolder parentContentFolder = Get(contentFolder.ParentId); if (parentContentFolder != null) { contentFolder.Depth = parentContentFolder.Depth + 1; contentFolder.ParentIdList = parentContentFolder.ParentIdList + "," + contentFolder.ParentId; parentContentFolder.ChildCount += 1; contentFolderRepository.Update(parentContentFolder); } else { contentFolder.ParentId = 0; } } contentFolderRepository.Insert(contentFolder); if (contentFolder.ContentFolderId > 0) { contentFolder.DisplayOrder = contentFolder.ContentFolderId; contentFolderRepository.Update(contentFolder); EntityData.ForType(typeof(Navigation)).RealTimeCacheHelper.IncreaseAreaVersion("OwnerId", 0); } //执行事件 EventBus <ContentFolder> .Instance().OnAfter(contentFolder, new CommonEventArgs(EventOperationType.Instance().Create(), ApplicationIds.Instance().CMS())); }
/// <summary> /// 批量移动ContentItem /// </summary> /// <param name="contentItemIds"></param> /// <param name="toContentFolderId"></param> public void Move(IEnumerable <long> contentItemIds, int toContentFolderId) { ContentFolderService contentFolderService = new ContentFolderService(); ContentFolder toContentFolder = contentFolderService.Get(toContentFolderId); if (toContentFolder == null) { return; } contentItemIds = contentItemIds.Distinct(); IEnumerable <ContentItem> contentItemsForMove = contentItemRepository.PopulateEntitiesByEntityIds(contentItemIds).Where(c => c.ContentFolderId != toContentFolderId); contentItemRepository.Move(contentItemsForMove, toContentFolderId); foreach (var contentItem in contentItemsForMove) { //执行事件 EventBus <ContentItem> .Instance().OnAfter(contentItem, new CommonEventArgs(EventOperationType.Instance().Update(), ApplicationIds.Instance().CMS())); } }
/// <summary> /// 更新ContentItem /// </summary> /// <param name="contentItem"></param> public void Update(ContentItem contentItem) { //执行事件 EventBus <ContentItem> .Instance().OnBefore(contentItem, new CommonEventArgs(EventOperationType.Instance().Update())); AuditStatus prevAuditStatus = contentItem.AuditStatus; //设置审核状态 AuditService auditService = new AuditService(); auditService.ChangeAuditStatusForUpdate(contentItem.UserId, contentItem); if (contentItem.AdditionalProperties.Get <bool>("FirstAsTitleImage", false)) { IEnumerable <Attachment> attachments = new AttachmentService(TenantTypeIds.Instance().ContentItem()).GetsByAssociateId(contentItem.ContentItemId); Attachment fristImage = attachments.Where(n => n.MediaType == MediaType.Image).FirstOrDefault(); if (fristImage != null) { contentItem.FeaturedImageAttachmentId = fristImage.AttachmentId; contentItem.FeaturedImage = fristImage.GetRelativePath() + "\\" + fristImage.FileName; } } contentItemRepository.Update(contentItem); //执行事件 EventBus <ContentItem> .Instance().OnAfter(contentItem, new CommonEventArgs(EventOperationType.Instance().Update(), ApplicationIds.Instance().CMS())); EventBus <ContentItem, AuditEventArgs> .Instance().OnAfter(contentItem, new AuditEventArgs(prevAuditStatus, contentItem.AuditStatus)); }
/// <summary> /// 创建ContentItem /// </summary> /// <param name="contentItem"></param> public void Create(ContentItem contentItem) { //设置审核状态 if (contentItem.IsContributed && contentItem.ContentFolder != null && contentItem.ContentFolder.NeedAuditing) { new AuditService().ChangeAuditStatusForCreate(contentItem.UserId, contentItem); } else { contentItem.AuditStatus = AuditStatus.Success; } //执行事件 EventBus <ContentItem> .Instance().OnBefore(contentItem, new CommonEventArgs(EventOperationType.Instance().Create())); contentItemRepository.Insert(contentItem); //转换临时附件 AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().ContentItem()); attachmentService.ToggleTemporaryAttachments(contentItem.UserId, TenantTypeIds.Instance().ContentItem(), contentItem.ContentItemId); if (contentItem.AdditionalProperties.Get <bool>("FirstAsTitleImage", false)) { IEnumerable <Attachment> attachments = new AttachmentService(TenantTypeIds.Instance().ContentItem()).GetsByAssociateId(contentItem.ContentItemId); Attachment fristImage = attachments.Where(n => n.MediaType == MediaType.Image).FirstOrDefault(); if (fristImage != null) { contentItem.FeaturedImageAttachmentId = fristImage.AttachmentId; contentItem.FeaturedImage = fristImage.GetRelativePath() + "\\" + fristImage.FileName; } } //用户投稿计数+1 OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(contentItem.UserId, OwnerDataKeys.Instance().ContributeCount(), 1); //执行事件 EventBus <ContentItem> .Instance().OnAfter(contentItem, new CommonEventArgs(EventOperationType.Instance().Create(), ApplicationIds.Instance().CMS())); EventBus <ContentItem, AuditEventArgs> .Instance().OnAfter(contentItem, new AuditEventArgs(null, contentItem.AuditStatus)); }
/// <summary> /// 设置审核设置 /// </summary> public void UpdateAuditStatus(long contentItemId, bool isApproved) { AuditStatus auditStatus = isApproved ? AuditStatus.Success : AuditStatus.Fail; ContentItem contentItem = contentItemRepository.Get(contentItemId); string operationType = isApproved ? EventOperationType.Instance().Approved() : EventOperationType.Instance().Disapproved(); if (contentItem != null && contentItem.AuditStatus != auditStatus) { AuditStatus oldAuditStatus = contentItem.AuditStatus; contentItem.AuditStatus = auditStatus; contentItemRepository.Update(contentItem); //触发事件 EventBus <ContentItem> .Instance().OnAfter(contentItem, new CommonEventArgs(operationType, ApplicationIds.Instance().CMS())); EventBus <ContentItem, AuditEventArgs> .Instance().OnAfter(contentItem, new AuditEventArgs(oldAuditStatus, auditStatus)); } }
/// <summary> /// 设置置顶 /// </summary> /// <param name="contentItemId"></param> /// <param name="isGlobalSticky"></param> /// <param name="globalStickyDate"></param> /// <param name="isFolderSticky"></param> /// <param name="folderStickyDate"></param> public void SetSticky(long contentItemId, bool isGlobalSticky, DateTime globalStickyDate, bool isFolderSticky, DateTime folderStickyDate) { ContentItem contentItem = contentItemRepository.Get(contentItemId); if (contentItem == null) { return; } string eventOperationTypeGlobal = string.Empty; if (contentItem.IsGlobalSticky != isGlobalSticky) { contentItem.IsGlobalSticky = isGlobalSticky; contentItem.GlobalStickyDate = ValueUtility.GetSafeSqlDateTime(globalStickyDate); eventOperationTypeGlobal = isGlobalSticky ? EventOperationType.Instance().SetGlobalSticky() : EventOperationType.Instance().CancelGlobalSticky(); } string eventOperationTypeFolder = string.Empty; if (contentItem.IsFolderSticky != isFolderSticky) { contentItem.IsFolderSticky = isFolderSticky; contentItem.FolderStickyDate = ValueUtility.GetSafeSqlDateTime(folderStickyDate); eventOperationTypeFolder = isFolderSticky ? EventOperationType.Instance().SetFolderSticky() : EventOperationType.Instance().CancelFolderSticky(); } contentItemRepository.Update(contentItem); if (!string.IsNullOrEmpty(eventOperationTypeGlobal)) {//执行事件 EventBus <ContentItem> .Instance().OnAfter(contentItem, new CommonEventArgs(eventOperationTypeGlobal, ApplicationIds.Instance().CMS())); } if (!string.IsNullOrEmpty(eventOperationTypeFolder)) {//执行事件 EventBus <ContentItem> .Instance().OnAfter(contentItem, new CommonEventArgs(eventOperationTypeFolder, ApplicationIds.Instance().CMS())); } }
/// <summary> /// 设置/取消 精华 /// </summary> /// <param name="contentItemId"></param> /// <param name="isEssential"></param> public void SetEssential(long contentItemId, bool isEssential) { ContentItem contentItem = contentItemRepository.Get(contentItemId); if (contentItem != null && contentItem.IsEssential != isEssential) { contentItem.IsEssential = isEssential; contentItemRepository.Update(contentItem); //执行事件 if (isEssential) { EventBus <ContentItem> .Instance().OnAfter(contentItem, new CommonEventArgs(EventOperationType.Instance().SetEssential(), ApplicationIds.Instance().CMS())); } else { EventBus <ContentItem> .Instance().OnAfter(contentItem, new CommonEventArgs(EventOperationType.Instance().CancelEssential(), ApplicationIds.Instance().CMS())); } } }
public ActionResult EditPage(WikiPageEditModel editModel) { if (UserContext.CurrentUser == null) { return(Redirect(SiteUrls.Instance().Login(true))); } //声明必要的变量 WikiPage page = null; WikiPageVersion pageVersion = null; #region 敏感词过滤 string errorMessage = string.Empty; if (ModelState.HasBannedWord(out errorMessage)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "发布失败", Body = errorMessage, StatusMessageType = StatusMessageType.Error }))); } #endregion if (editModel.PageId < 1)//新建词条 { page = editModel.AsWikiPage(); bool valid = wikiService.IsExists(page.Title); if (valid) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "发布同名词条失败", Body = "发布失败,请稍后再试!", StatusMessageType = StatusMessageType.Error }))); } bool isCreated = wikiService.Create(page, editModel.Body); if (page.PageId < 1) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "发布失败", Body = "发布失败,请稍后再试!", StatusMessageType = StatusMessageType.Error }))); } pageVersion = page.LastestVersion; } else//编辑词条 { //userFocusCategoryService.del page = wikiService.Get(editModel.PageId); if (page == null) { return(HttpNotFound()); } //判断一下是否可以编辑 bool IsCanEdit = !page.IsLocked; IUser user = UserContext.CurrentUser; if (page.OwnerId == user.UserId || DIContainer.Resolve <Authorizer>().IsAdministrator(ApplicationIds.Instance().Wiki())) { IsCanEdit = true; } if (!IsCanEdit) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "编辑失败", Body = "编辑失败,该词条已经被锁定,请稍后再试!", StatusMessageType = StatusMessageType.Error }))); } categoryService.DeleteItemInCategory(page.SiteCategory.CategoryId, page.PageId); page = editModel.AsWikiPage(); wikiService.Update(page); pageVersion = editModel.AsWikiPageVersion(); pageVersion.PageId = page.PageId; wikiService.CreatePageVersion(pageVersion); if (pageVersion.VersionId < 1) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "编辑失败", Body = "编辑失败,请稍后再试!", StatusMessageType = StatusMessageType.Error }))); } } #region 分类、标签 if (editModel.SiteCategoryId > 0) { categoryService.AddCategoriesToItem(new List <long> { editModel.SiteCategoryId }, page.PageId); } string tags = string.Join(",", editModel.TagNames); if (!string.IsNullOrEmpty(tags)) { tagService.ClearTagsFromItem(page.PageId, pageVersion.UserId); tagService.AddTagsToItem(tags, pageVersion.UserId, page.PageId); } #endregion return(Redirect(SiteUrls.Instance().PageDetail(page.PageId))); }
/// <summary> /// 删除ContentItem /// </summary> /// <param name="contentItem"></param> public void Delete(ContentItem contentItem) { if (contentItem != null) { //执行事件 EventBus <ContentItem> .Instance().OnBefore(contentItem, new CommonEventArgs(EventOperationType.Instance().Delete())); contentItemRepository.Delete(contentItem); //用户投稿计数-1 OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(contentItem.UserId, OwnerDataKeys.Instance().ContributeCount(), -1); //删除标签关联 TagService tagService = new TagService(TenantTypeIds.Instance().ContentItem()); tagService.ClearTagsFromItem(contentItem.ContentItemId, contentItem.UserId); //删除评论 CommentService commentService = new CommentService(); commentService.DeleteCommentedObjectComments(contentItem.ContentItemId); //执行事件 EventBus <ContentItem> .Instance().OnAfter(contentItem, new CommonEventArgs(EventOperationType.Instance().Delete(), ApplicationIds.Instance().CMS())); EventBus <ContentItem, AuditEventArgs> .Instance().OnAfter(contentItem, new AuditEventArgs(contentItem.AuditStatus, null)); } }