/// <summary> /// 高级删除 /// </summary> public bool DeleteTags(AdminTagFilter filter) { if (SafeMode) { if (!IsExecutorLogin) { ThrowError(new NotLoginError()); return(false); } } if (filter == null) { filter = new AdminTagFilter(); } if (SafeMode) { //TODO: } bool success = TagDao.Instance.DeleteTagsByFilter(filter); if (success) { CacheUtil.RemoveBySearch(CacheKey_TagPrefix); } return(true); }
/// <summary> /// 删除标签 /// </summary> /// <param name="tagID">删除标签ID</param> public bool DeleteTag(int tagID) { if (SafeMode) { if (!IsExecutorLogin) { ThrowError(new NotLoginError()); return(false); } } if (tagID <= 0) { ThrowError(new InvalidParamError("tagID")); return(false); } if (SafeMode) { //TODO: } bool success = TagDao.Instance.DeleteTag(tagID); if (success) { CacheUtil.RemoveBySearch(CacheKey_TagPrefix); } return(true); }
/// <summary> /// 删除多个标签 /// </summary> public bool DeleteTags(IEnumerable <int> tagIDs) { if (SafeMode) { if (!IsExecutorLogin) { ThrowError(new NotLoginError()); return(false); } } if (tagIDs == null || ValidateUtil.HasItems <int>(tagIDs) == false) { ThrowError(new NotSelectedTagsError("tagIDs")); return(false); } if (SafeMode) { //TODO: } bool success = TagDao.Instance.DeleteTags(tagIDs); if (success) { CacheUtil.RemoveBySearch(CacheKey_TagPrefix); } return(true); }
/// <summary> /// 保存标签 /// </summary> /// <param name="tags">标签集</param> /// <param name="type">类型,如日志标签等</param> /// <param name="targetID">标签的对象ID</param> public bool SaveTags(TagCollection tags, TagType type, int targetID) { if (SafeMode) { if (!IsExecutorLogin) { ThrowError(new NotLoginError()); return(false); } } if (targetID <= 0) { ThrowError(new InvalidParamError("targetID")); return(false); } bool success = TagDao.Instance.SaveTags(tags, type, targetID); if (success) { CacheUtil.RemoveBySearch(CacheKey_TagPrefix); } return(true); }
private void RemoveCacheByGroup(int userID, int groupID) { string cacheKey = string.Format(cacheKey_ByGroup, userID, groupID); CacheUtil.RemoveBySearch(string.Format(cacheKey_EmoticonPagedRoot, groupID));//清除已分页的本组缓存 CacheUtil.Remove(cacheKey); }
private void RemoveCacheByType(int userID, int type) { if (type == 0) { CacheUtil.RemoveBySearch(string.Format(cacheKey_UserNotifyRoot, userID)); } else { CacheUtil.RemoveBySearch(string.Format(cacheKey_UserNotifyType, userID, type)); } }
/// <summary> /// 批量删除表情 /// </summary> /// <param name="userID">用户ID</param> /// <param name="groupID"></param> /// <param name="emoticonsIdentities">要删除的ID</param> /// <returns></returns> public void DeleteEmoticons(int userID, int groupID, IEnumerable <int> emoticonIds) { if (ValidateUtil.HasItems <int>(emoticonIds)) { List <string> canDeleteFiles = EmoticonDao.Instance.DeleteEmoticons(userID, groupID, emoticonIds); CacheUtil.RemoveBySearch(string.Format(cacheKey_EmoticonPagedRoot, groupID)); CacheUtil.Remove(string.Format(cacheKey_EmoticonUserGroups, userID)); DeleteEmoticonFiles(canDeleteFiles); } }
public bool SaveUploadedFile(AuthUser my, int directoryID, int tempFileID, bool replaceExistFile) { AuthUser user = my; if (my == User.Guest) { ThrowError(new NotLoginError()); return(false); } TempUploadFile tempUploadFile = FileManager.GetUserTempUploadFile(my.UserID, tempFileID); if (tempUploadFile == null) { ThrowError(new UnknownError()); return(false); } long diskSpace = GetDiskSpaceSize(my.UserID); long userRemnantDiskSpace = GetDiskSpaceSize(my.UserID) - user.UsedDiskSpaceSize; if (tempUploadFile.FileSize > GetMaxFileSize(my.UserID)) { ThrowError(new DiskFileSizeOverflowError(GetMaxFileSize(my.UserID))); return(false); } if (tempUploadFile.FileSize > userRemnantDiskSpace) { ThrowError(new InsufficientDiskSpaceError(diskSpace)); return(false); } if (DiskDao.Instance.SaveUploadFile(my.UserID, directoryID, tempUploadFile.FileID, tempUploadFile.FileName, tempUploadFile.FileSize, userRemnantDiskSpace, replaceExistFile)) { tempUploadFile.Save(); //string thumbPath = BuildThumb(tempUploadFile); //FileManager.DeleteFiles(canDeleteFileIds); CacheUtil.RemoveBySearch(string.Format(cacheKey_diskRoot, my.UserID)); return(true); } else { //if (!string.IsNullOrEmpty(thumbPath)) // IOUtil.DeleteFile(thumbPath); //saver.Cancel(); return(false); } }
public static void ClearAllCache() { lock (s_AllCachedThreadsLocker) { CacheUtil.RemoveBySearch("Threads/"); //int count = CacheUtil.GetBySearch<ThreadCollectionV5>("Threads/").Count; //if (count > 0) //{ // MaxLabs.bbsMax.Common.LogHelper.CreateErrorLog2("ClearAllCache", count.ToString()); //} s_AllCachedThreads = null; s_AllForumTopThreads = null; s_ForumCacheKeys = null; //s_ForumLockers = null; InitForumLockers(); } }
///// <summary> ///// 删除搜索结果 ///// </summary> ///// <param name="filter"></param> ///// <returns></returns> //public bool RemoveCommentsBySearch(int operatorUserID, AdminCommentFilter filter, bool updatePoint) //{ // Guid[] excludeRoleIDs = ManagePermission.GetNoPermissionTargetRoleIds(operatorUserID); // //DeleteResult deleteResult = CommentDao.Instance.DeleteCommentsBySearch(filter, operatorUserID, excludeRoleIDs); // DeleteResult deleteResult = null; // if (updatePoint) // { // bool success = CommentPointAction.Instance.UpdateUsersPoint(CommentPointType.DeleteCommentByAdmin, delegate(PointActionManager.TryUpdateUserPointState state, out Dictionary<int, int> userIDs) // { // if (state == PointActionManager.TryUpdateUserPointState.CheckSucceed) // { // deleteResult = CommentDao.Instance.DeleteCommentsByFilter(filter, operatorUserID, excludeRoleIDs, true); // userIDs = new Dictionary<int, int>(); // foreach (DeleteResultItem item in deleteResult) // { // userIDs.Add(item.UserID, item.Count); // } // return true; // } // else // { // userIDs = null; // return false; // } // }); // if (!success) // return false; // } // else // { // deleteResult = CommentDao.Instance.DeleteCommentsByFilter(filter, operatorUserID, excludeRoleIDs, true); // } // foreach (DeleteResultItem item in deleteResult) // { // UserBO.Instance.RemoveUserCache(item.UserID); // } // CacheUtil.RemoveBySearch("Doing/List/All"); // CacheUtil.RemoveBySearch("Comment/List/Space"); // return true; //} ///// <summary> ///// 更新关键字版本和评论内容 ///// </summary> ///// <param name="comments"></param> //protected void TryUpdateKeyword(CommentCollection comments) //{ // TextRevertableCollection processlist = new TextRevertableCollection(); // KeywordReplaceRegulation keyword = AllSettings.Current.ContentKeywordSettings.ReplaceKeywords; // foreach (Comment comment in comments) // { // if (keyword.NeedUpdateText(comment)) // { // processlist.Add(comment); // } // } // if (processlist.Count > 0) // { // CommentDao.Instance.FillCommentReverters(processlist); // keyword.Update(processlist); // CommentDao.Instance.UpdateCommentKeywords(processlist); // } //} /// <summary> /// 审核评论单条或多条 用于后台 /// </summary> /// <param name="commentIDs"></param> public bool ApproveComments(int operatorUserID, IEnumerable <int> commentIDs) { if (ValidateUtil.HasItems <int>(commentIDs) == false) { ThrowError(new NotSelectedCommentsError("commentIDs")); return(false); } CommentCollection comments = CommentDao.Instance.GetComments(commentIDs); if (comments.Count == 0) { return(true); } List <int> canApproveCommentIDs = new List <int>(); foreach (Comment comment in comments) { if (ManagePermission.Can(operatorUserID, BackendPermissions.ActionWithTarget.Manage_Comment, comment.UserID)) { canApproveCommentIDs.Add(comment.CommentID); } } if (canApproveCommentIDs.Count == 0) { ThrowError <NoPermissionApproveCommentError>(new NoPermissionApproveCommentError()); return(false); } CommentDao.Instance.ApproveComments(canApproveCommentIDs); //TODO:优化 CacheUtil.RemoveBySearch("Doing/List/All"); CacheUtil.RemoveBySearch("Comment/List/Space"); return(true); }
/// <summary> /// 保存个人隐私设置 /// </summary> /// <param name="space"></param> //public bool ModifySpacePrivacy(Space space) public void ModifySpacePrivacy(int operatorUserID, SpacePrivacyType blogPrivacy, SpacePrivacyType feedPrivacy, SpacePrivacyType boardPrivacy, SpacePrivacyType doingPrivacy, SpacePrivacyType albumPrivacy, SpacePrivacyType spacePrivacy, SpacePrivacyType sharePrivacy, SpacePrivacyType friendListPrivacy, SpacePrivacyType informationPrivacy) { SpaceDao.Instance.UpdateSpacePrivacy(operatorUserID, blogPrivacy, feedPrivacy, boardPrivacy, doingPrivacy, albumPrivacy, spacePrivacy, sharePrivacy, friendListPrivacy, informationPrivacy); User user = UserBO.Instance.GetUserFromCache(operatorUserID); if (user != null) { user.BlogPrivacy = blogPrivacy; user.FeedPrivacy = feedPrivacy; user.BoardPrivacy = boardPrivacy; user.DoingPrivacy = doingPrivacy; user.AlbumPrivacy = albumPrivacy; user.SpacePrivacy = spacePrivacy; user.SharePrivacy = sharePrivacy; user.FriendListPrivacy = friendListPrivacy; user.InformationPrivacy = informationPrivacy; } string key = string.Format(cacheKey_View_All, operatorUserID); CacheUtil.RemoveBySearch(key); }
/// <summary> /// 创建许多表情 /// </summary> /// <param name="emoticon"></param> /// <returns></returns> public void CreateEmoticons(int userID, EmoticonCollection emoticons) { if (!CanUseEmoticon(userID)) { ThrowError(new NoPermissionUseEmoticonError()); return; } List <int> removedCackes = new List <int>(); foreach (Emoticon emote in emoticons) { if (!removedCackes.Contains(emote.GroupID)) { CacheUtil.RemoveBySearch(string.Format(cacheKey_EmoticonPagedRoot, emote.GroupID)); removedCackes.Add(emote.GroupID); } emote.UserID = userID; } CacheUtil.Remove(string.Format(cacheKey_EmoticonUserGroups, userID)); EmoticonDao.Instance.CreateEmoticons(emoticons); }
/// <summary> /// �Ƴ�ij�û�����������Ӳ�̻��� /// </summary> /// <param name="userID"></param> private void RemoveCacheByUser(int userID) { CacheUtil.RemoveBySearch(string.Format(cacheKey_diskRoot, userID)); }
/// <summary> /// ȡ�ø�Ŀ¼�ļ�����һ��Ŀ¼�������ļ����ļ��С� /// </summary> /// <param name="userID">��ǰ�û���ID��</param> /// <param name="directoryID">���ļ��е�ID��</param> /// <param name="directories">������ļ���ʵ��<see cref="DiskDirectory"/>���б��</param> /// <param name="files">������ļ�ʵ��<see cref="DiskFile"/>�б��</param> /// <param name="totalSize">��ǰ��Ŀ¼���������ļ��Ĵ�С��</param> /// <returns>����ɹ�ȡ����<c>true</c>,����<c>false</c>��</returns> public List <IFile> GetDiskFiles(int userID, int directoryID, out DiskDirectoryCollection directories, out DiskFileCollection files, FileOrderBy orderBy, bool isDesc, ExtensionList fileTypes) { List <IFile> dirAndFiles; int fileTypeKey = fileTypes == null || fileTypes.Count == 0?0: fileTypes.ToString("").GetHashCode(); string cachekeyOfDirectorys = string.Format(cacheKey_directoryList, userID, directoryID); string cacheKeyOfFiles = string.Format(cacheKey_fileList, userID, directoryID, fileTypeKey); if (!CacheUtil.TryGetValue <DiskFileCollection>(cacheKey_fileList, out files) || CacheUtil.TryGetValue <DiskDirectoryCollection>(cachekeyOfDirectorys, out directories)) { DiskDao.Instance.GetDiskFiles(userID, directoryID, out directories, out files); CacheUtil.Set <DiskFileCollection>(cacheKeyOfFiles, files); CacheUtil.Set <DiskDirectoryCollection>(cachekeyOfDirectorys, directories); } /*���´������ܺܲ ԭ����3.0��BO������Ӧ�����ܣ� ��ʱ��Ӧ����������ѭ������*/ string cacheKeyOfAllFiles = string.Format(cacheKey_directoryList, userID, directoryID, orderBy, isDesc); if (!CacheUtil.TryGetValue <List <IFile> >(cacheKeyOfAllFiles, out dirAndFiles)) { dirAndFiles = new List <IFile>(directories.Count + files.Count); if (orderBy != FileOrderBy.None) { DiskFile temp; int v; for (int i = 0; i < files.Count - 1; i++) { for (int j = i + 1; j < files.Count; j++) { v = CompareFile(files[i], files[j], orderBy); if (isDesc) { if (v > 0) { temp = files[i]; files[i] = files[j]; files[j] = temp; } } else { if (v < 0) { temp = files[j]; files[j] = files[i]; files[i] = temp; } } } } DiskDirectory tempDir; for (int i = 0; i < directories.Count - 1; i++) { for (int j = i + 1; j < directories.Count; j++) { v = CompareFile(directories[i], directories[j], orderBy); if (isDesc) { if (v > 0) { tempDir = directories[i]; directories[i] = directories[j]; directories[j] = tempDir; } } else { if (v < 0) { tempDir = directories[j]; directories[j] = directories[i]; directories[i] = tempDir; } } } } } if (orderBy == FileOrderBy.Type && isDesc == false) { foreach (DiskFile file in files) { if (fileTypes != null && fileTypes.Count > 0 && !fileTypes.Contains(file.ExtensionName)) { continue; } dirAndFiles.Add(file); } foreach (IFile dir in directories) { dirAndFiles.Add(dir); } } else { foreach (IFile dir in directories) { dirAndFiles.Add(dir); } foreach (DiskFile file in files) { if (fileTypes != null && fileTypes.Count > 0 && !fileTypes.Contains(file.ExtensionName)) { continue; } dirAndFiles.Add(file); } } CacheUtil.RemoveBySearch(string.Format(cacheKey_allFileListRoot, userID, directoryID)); CacheUtil.Set <List <IFile> >(cacheKeyOfAllFiles, dirAndFiles); } return(dirAndFiles); }
/// <summary> /// 评论编辑 /// </summary> /// <param name="commentID"></param> /// <param name="content"></param> /// <param name="type"></param> /// <returns></returns> public bool ModifyComment(int operatorUserID, int commentID, string content, CommentType type, out string newContent) { newContent = content; if (commentID <= 0) { ThrowError(new InvalidParamError("commentID")); return(false); } Comment comment = GetCommentByID(commentID); if (comment == null) { ThrowError <InvalidParamError>(new InvalidParamError("commentID")); return(false); } if (ValidateCommentEditPermission(operatorUserID, comment) == false) { return(false); } if (string.IsNullOrEmpty(content)) { Context.ThrowError(new EmptyCommentError("content")); return(false); } if (StringUtil.GetByteCount(content) > Consts.Comment_Length) { Context.ThrowError(new InvalidCommentLengthError("content", content, Consts.Comment_Length)); return(false); } bool isApproved = true; string reverter, version; content = AllSettings.Current.ContentKeywordSettings.ReplaceKeywords.Replace(content, out version, out reverter); string keyword = null; if (AllSettings.Current.ContentKeywordSettings.BannedKeywords.IsMatch(content, out keyword)) { Context.ThrowError(new KeywordBannedError("content", keyword)); return(false); } else if (AllSettings.Current.ContentKeywordSettings.ApprovedKeywords.IsMatch(content)) { isApproved = false; } content = CommentUbbParser.ParseForSave(content); if (StringUtil.GetByteCount(content) > Consts.Comment_Length) { Context.ThrowError(new InvalidCommentLengthError("content", content, Consts.Comment_Length)); return(false); } int targetID; CommentDao.Instance.UpdateComment(commentID, operatorUserID, isApproved, content, reverter, out targetID); if (type == CommentType.Doing) { CacheUtil.RemoveBySearch("Doing/List/All"); } if (type == CommentType.Board) //更新留言所在用户缓存的数据而不是留言的用户! { CacheUtil.RemoveBySearch(string.Format(cacheKey_List_Space, targetID, type)); } newContent = content; if (isApproved == false) { ThrowError <UnapprovedCommentError>(new UnapprovedCommentError()); return(false); } return(true); }
public void GroupImportEmoticon(int userID, Dictionary <string, List <EmoticonItem> > groupedEmoticonDatas , out int groupCount, out int fileCount, out int saveGroupcount, out int saveFileCount) { bool stopSaveFile = false; long maxEmotcionSize; //单个文件最大限制 long canUseSpcaeSize; //总可用空间大小 int canUploadEmoticonCount; //总可用表情数量 int usedEmoticonCount; long usedspaceSize = GetUserEmoticonStat(userID, out usedEmoticonCount); //已用空间大小 canUseSpcaeSize = MaxEmoticonSpace(userID); //取得最大可用空间 canUploadEmoticonCount = MaxEmoticonCount(userID); //取得最大表情数 maxEmotcionSize = MaxEmticonFileSize(userID); //获取单个表情的最大限制 int currentFileSizes = 0; string imgUrl; groupCount = 0; saveGroupcount = 0; fileCount = 0; saveFileCount = 0; Dictionary <string, EmoticonCollection> groupedEmoticons = new Dictionary <string, EmoticonCollection>(); foreach (KeyValuePair <string, List <EmoticonItem> > groups in groupedEmoticonDatas) { groupCount++; EmoticonCollection emoticons = new EmoticonCollection(); bool hasFileSaved = false; foreach (EmoticonItem item in groups.Value) { fileCount++; if (usedspaceSize + currentFileSizes + item.Size > canUseSpcaeSize) { if (!stopSaveFile) { ThrowError(new EmoticonSpaceOverflow(canUseSpcaeSize)); stopSaveFile = true; } break; } if (saveFileCount + usedEmoticonCount >= canUploadEmoticonCount) { if (!stopSaveFile) { ThrowError(new EmoticonFileCountOverflow(canUploadEmoticonCount)); stopSaveFile = true; } break; } switch (SaveEmoticonFile(userID, item.Data, item.MD5, item.FileName, out imgUrl)) { case EmoticonSaveStatus.Success: Emoticon emote = new Emoticon(); emote.ImageSrc = imgUrl; emote.MD5 = item.MD5; emote.Shortcut = item.Shortcut; emote.FileSize = item.Data.Length; emoticons.Add(emote); hasFileSaved = true; saveFileCount++; currentFileSizes += item.Size; break; } } if (hasFileSaved) { groupedEmoticons.Add(groups.Key, emoticons); } //if (stopSaveFile) // break; } if (groupCount > 0 && saveFileCount > 0) { CreateEmoticonsAndGroups(userID, groupedEmoticons); saveGroupcount = groupedEmoticons.Count; CacheUtil.RemoveBySearch(string.Format(cacheKey_ByGroupRoot, userID)); } }
/* * /// <summary> * /// 删除评论 包括删除自己的评论 别人对自己应用的评论 并更新缓存 * /// </summary> * /// <param name="commentID"></param> * /// <param name="type"></param> * /// <returns></returns> * public bool RemoveComment(int userID, int commentID, CommentType type) * { * if (commentID <= 0) * { * ThrowError(new InvalidParamError("commentID")); * return false; * } * * int commentUserID; * * CommentPointManager.Instance.UpdateUserPoint(userID, CommentPMType.DeleteComment, delegate(UserBO.TryUpdateUserPointState state) * { * return true; * }); * * CommentDao.Instance.DeleteComment(userID, commentID, out commentUserID); * * if (type == CommentType.Doing) * CacheUtil.RemoveBySearch("Doing/List/All"); * if (type == CommentType.Board) * CacheUtil.RemoveBySearch(string.Format(cacheKey_List_Space, commentUserID, type)); * * //TODO;对comment用户的积分操作 * * return true; * } */ /// <summary> /// 删除评论单条或批量 并更新缓存 用于后台 /// </summary> /// <param name="commentIDs"></param> public bool RemoveComments(int operatorUserID, IEnumerable <int> commentIDs, bool isUpdatePoint) { if (ValidateUtil.HasItems <int>(commentIDs) == false) { ThrowError(new NotSelectedCommentsError("commentIDs")); return(false); } CommentCollection comments = CommentDao.Instance.GetComments(commentIDs); Dictionary <int, int> deleteResults = new Dictionary <int, int>(); List <int> deleteCommentIDs = new List <int>(); foreach (Comment comment in comments) { if (comment.UserID == operatorUserID || comment.TargetUserID == operatorUserID) //是自己的 或者 是别人评论自己的可以删除 { deleteCommentIDs.Add(comment.CommentID); if (deleteResults.ContainsKey(comment.UserID)) { deleteResults[comment.UserID] += 1; } else { deleteResults.Add(comment.UserID, 1); } } else //不是自己的判断权限 { if (ManagePermission.Can(operatorUserID, BackendPermissions.ActionWithTarget.Manage_Comment, comment.UserID, comment.LastEditUserID) == false) { //没权限 跳过 } else { deleteCommentIDs.Add(comment.CommentID); if (deleteResults.ContainsKey(comment.UserID)) { deleteResults[comment.UserID] += 1; } else { deleteResults.Add(comment.UserID, 1); } } } } if (deleteResults.Count == 0) { ThrowError <NoPermissionDeleteCommentError>(new NoPermissionDeleteCommentError()); return(false); } if (isUpdatePoint) { CommentPointType pointType; if (deleteResults.Count == 1 && deleteResults.ContainsKey(operatorUserID)) //自己删除 { pointType = CommentPointType.DeleteCommentBySelf; } else { pointType = CommentPointType.DeleteCommentByAdmin; } bool success = CommentPointAction.Instance.UpdateUsersPoint(deleteResults, pointType, delegate(PointActionManager.TryUpdateUserPointState state) { if (state == PointActionManager.TryUpdateUserPointState.CheckSucceed) { CommentDao.Instance.DeleteComments(deleteCommentIDs); return(true); } else { return(false); } }); if (!success) { return(false); } } else { CommentDao.Instance.DeleteComments(deleteCommentIDs); } if (comments.Count == 1) { if (comments[0].Type == CommentType.Doing) { CacheUtil.RemoveBySearch("Doing/List/All"); } if (comments[0].Type == CommentType.Board) { CacheUtil.RemoveBySearch(string.Format(cacheKey_List_Space, comments[0].UserID, CommentType.Board)); } FeedBO.Instance.DeleteFeed(AppActionType.AddComment, comments[0].TargetID, comments[0].UserID); } else { //TODO:优化 CacheUtil.RemoveBySearch("Doing/List/All"); CacheUtil.RemoveBySearch("Comment/List/Space"); Dictionary <int, List <int> > deleteFeedIDs = new Dictionary <int, List <int> >(); foreach (Comment comment in comments) { if (deleteFeedIDs.ContainsKey(comment.TargetID) == false) { deleteFeedIDs.Add(comment.TargetID, new List <int>(new int[] { comment.UserID })); } else { deleteFeedIDs[comment.TargetID].Add(comment.UserID); } } FeedBO.Instance.DeleteFeeds(AppActionType.AddComment, deleteFeedIDs); } return(true); }
/************************************** * Clear开头的函数清除缓存 * **************************************/ /// <summary> /// 清除“大家的记录”的缓存数据 /// </summary> internal void ClearCachedEveryoneData() { CacheUtil.RemoveBySearch("Doing/All/"); }
/// <summary> /// 清除按用户缓存的数据 /// </summary> /// <param name="userID">用户ID</param> private void ClearCachedUserData(int userID) { CacheUtil.RemoveBySearch("Doing/" + userID); }
/// <summary> /// 添加评论 并更新缓存 /// </summary> /// <param name="userID">评论者ID</param> /// <param name="targetID">被评论的记录、日志、相册的ID</param> /// <param name="commentID">被评论的评论ID</param> /// <param name="type">评论类型 记录、日志、相册</param> /// <param name="content"></param> /// <param name="createIP"></param> /// <returns></returns> public bool AddComment(AuthUser operatorUser, int targetID, int commentID, CommentType type, string content, string createIP, bool isReply, int replyTargetUserID, out int newCommentId, out string newCommentContent) { Notify notify; newCommentId = 0; newCommentContent = string.Empty; if (Permission.Can(operatorUser, SpacePermissionSet.Action.AddComment) == false) { ThrowError <NoPermissionAddCommentError>(new NoPermissionAddCommentError()); return(false); } if (targetID < 0) { ThrowError(new InvalidParamError("targetID")); return(false); } if (commentID < 0) { ThrowError(new InvalidParamError("commentID")); return(false); } if (string.IsNullOrEmpty(content)) { ThrowError(new EmptyCommentError("content")); return(false); } if (StringUtil.GetByteCount(content) > Consts.Comment_Length) { ThrowError(new InvalidCommentLengthError("content", content, Consts.Comment_Length)); return(false); } int commentTargetUserID = GetCommentTargetUserID(targetID, type); if (FriendBO.Instance.MyInBlacklist(operatorUser.UserID, commentTargetUserID)) { ThrowError(new PrivacyError()); return(false); } bool isApproved = true; //string reverter, version; //content = AllSettings.Current.ContentKeywordSettings.ReplaceKeywords.Replace(content, out version, out reverter); CommentPointType commentPointType = CommentPointType.AddApprovedComment; KeywordReplaceRegulation keywordReg = AllSettings.Current.ContentKeywordSettings.ReplaceKeywords; content = keywordReg.Replace(content); string keyword = null; if (AllSettings.Current.ContentKeywordSettings.BannedKeywords.IsMatch(content, out keyword)) { Context.ThrowError(new KeywordBannedError("content", keyword)); return(false); } if (AllSettings.Current.ContentKeywordSettings.ApprovedKeywords.IsMatch(content)) { isApproved = false; commentPointType = CommentPointType.AddNoApprovedComment; } if (StringUtil.GetByteCount(content) > Consts.Comment_Length) { Context.ThrowError(new InvalidCommentLengthError("content", content, Consts.Comment_Length)); return(false); } int targetUserID = 0; int tempCommentID = 0; content = CommentUbbParser.ParseForSave(content); newCommentContent = content; bool success = CommentPointAction.Instance.UpdateUserPoint(operatorUser.UserID, commentPointType, delegate(PointActionManager.TryUpdateUserPointState state) { if (state != PointActionManager.TryUpdateUserPointState.CheckSucceed) { return(false); } else { //添加评论并发送动态与通知 switch (type) { case CommentType.Board: SimpleUser user = UserBO.Instance.GetSimpleUser(targetID); if (user == null) { ThrowError(new UserNotExistsError("targetID", targetID)); return(false); } CommentDao.Instance.AddComment(operatorUser.UserID, targetID, type, isApproved, content, /* reverter, */ createIP, out targetUserID, out tempCommentID); FeedBO.Instance.CreateLeveMessageFeed(operatorUser.UserID, targetID); if (isReply && operatorUser.UserID != replyTargetUserID) { notify = new BoardCommentNotify(operatorUser.UserID, tempCommentID, isReply, targetID); notify.UserID = replyTargetUserID; NotifyBO.Instance.AddNotify(operatorUser, notify); } else if (targetID != operatorUser.UserID) { notify = new BoardCommentNotify(operatorUser.UserID, tempCommentID, false, targetID); notify.UserID = targetID; NotifyBO.Instance.AddNotify(operatorUser, notify); } CacheUtil.RemoveBySearch(string.Format(cacheKey_List_Space, targetID, type)); break; case CommentType.Blog: BlogArticle article = BlogBO.Instance.GetBlogArticle(targetID); if (article == null) { ThrowError(new NotExistsAlbumError(targetID)); return(false); } if (!article.EnableComment) { ThrowError(new PrivacyError()); return(false); } else { if (article.UserID != operatorUser.UserID) //如果不是作者评论自己的 给作者加积分 { CommentDao.Instance.AddComment(operatorUser.UserID, targetID, type, isApproved, content, /* reverter, */ createIP, out targetUserID, out tempCommentID); success = BlogPointAction.Instance.UpdateUserPoint(article.UserID, BlogPointType.ArticleWasCommented); if (success == false) { return(false); } } else { CommentDao.Instance.AddComment(operatorUser.UserID, targetID, type, isApproved, content, /* reverter, */ createIP, out targetUserID, out tempCommentID); } } FeedBO.Instance.CreatBlogCommentFeed(operatorUser.UserID, article.UserID, targetID, article.Subject); if (isReply && operatorUser.UserID != replyTargetUserID) { notify = new BlogCommentNotify(operatorUser.UserID, article.Subject, targetID, tempCommentID, isReply, article.UserID); notify.UserID = replyTargetUserID; NotifyBO.Instance.AddNotify(operatorUser, notify); } else if (article.UserID != operatorUser.UserID) { notify = new BlogCommentNotify(operatorUser.UserID, article.Subject, targetID, tempCommentID, false, article.UserID); notify.UserID = article.UserID; NotifyBO.Instance.AddNotify(operatorUser, notify); } break; case CommentType.Doing: Doing doing = DoingBO.Instance.GetDoing(targetID); if (doing == null) { ThrowError(new NotExistsDoingError(targetID)); return(false); } CommentDao.Instance.AddComment(operatorUser.UserID, targetID, type, isApproved, content, /* reverter, */ createIP, out targetUserID, out tempCommentID); if (isReply && operatorUser.UserID != replyTargetUserID) { notify = new DoingPostNotify(operatorUser.UserID, doing.Content, doing.ID, tempCommentID, isReply, doing.UserID); notify.UserID = replyTargetUserID; NotifyBO.Instance.AddNotify(operatorUser, notify); } else if (doing.UserID != operatorUser.UserID) { notify = new DoingPostNotify(operatorUser.UserID, doing.Content, doing.ID, tempCommentID, false, doing.UserID); notify.UserID = doing.UserID; NotifyBO.Instance.AddNotify(operatorUser, notify); } DoingBO.Instance.ClearCachedEveryoneData(); break; case CommentType.Share: Share share = ShareBO.Instance.GetUserShare(targetID); if (share == null) { ThrowError(new NotExistsShareError(targetID)); return(false); } if (share.UserID != operatorUser.UserID) //如果不是分享作者评论自己的分享 给分享作者加积分 { CommentDao.Instance.AddComment(operatorUser.UserID, targetID, type, isApproved, content, /* reverter, */ createIP, out targetUserID, out tempCommentID); success = SharePointAction.Instance.UpdateUserPoint(share.UserID, SharePointType.ShareWasCommeted); if (!success) { return(false); } } else { CommentDao.Instance.AddComment(operatorUser.UserID, targetID, type, isApproved, content, /* reverter, */ createIP, out targetUserID, out tempCommentID); } ShareBO.Instance.ClearCachedEveryoneData(); FeedBO.Instance.CreatShareCommentFeed(operatorUser.UserID, share.UserID, targetID, share.Type); if (isReply && operatorUser.UserID != replyTargetUserID) { notify = new SharePostNotify(operatorUser.UserID, targetID, tempCommentID, isReply, share.UserID); notify.UserID = replyTargetUserID; NotifyBO.Instance.AddNotify(operatorUser, notify); } else if (share.UserID != operatorUser.UserID) { notify = new SharePostNotify(operatorUser.UserID, targetID, tempCommentID, false, share.UserID); notify.UserID = share.UserID; NotifyBO.Instance.AddNotify(operatorUser, notify); } break; case CommentType.Photo: Photo photo = AlbumBO.Instance.GetPhoto(targetID); if (photo == null) { ThrowError(new NotExistsPhotoError(targetID)); return(false); } CommentDao.Instance.AddComment(operatorUser.UserID, targetID, type, isApproved, content, /* reverter, */ createIP, out targetUserID, out tempCommentID); FeedBO.Instance.CreatPictureCommentFeed(operatorUser.UserID, targetUserID, targetID, photo.ThumbSrc, photo.Name, content); if (isReply && operatorUser.UserID != replyTargetUserID) { notify = new PhotoCommentNotify(operatorUser.UserID, targetID, photo.Name, tempCommentID, isReply, photo.UserID); notify.UserID = replyTargetUserID; NotifyBO.Instance.AddNotify(operatorUser, notify); } else if (photo.UserID != operatorUser.UserID) { notify = new PhotoCommentNotify(operatorUser.UserID, targetID, photo.Name, tempCommentID, false, photo.UserID); notify.UserID = photo.UserID; NotifyBO.Instance.AddNotify(operatorUser, notify); } break; } return(true); } }); if (success == false) { return(false); } newCommentId = tempCommentID; //更新热度 if (targetUserID != 0) { HotType hotType = HotType.Comment; if (type == CommentType.Board) { hotType = HotType.Messag; } FriendBO.Instance.UpdateFriendHot(operatorUser.UserID, hotType, targetUserID); } if (isApproved == false) { Context.ThrowError(new UnapprovedCommentError()); return(false); } return(true); }