コード例 #1
0
ファイル: DiskBO.cs プロジェクト: zhangbo27/bbsmax
        public CreateUpdateDiskFileStatus RenameDiskDirectoryAndFiles
        (
            int userID
            , int parentID
            , IEnumerable <int> directoryIDs
            , IEnumerable <int> diskFileIDs
            , IEnumerable <string> directoryNames
            , IEnumerable <string> diskFileNames
        )
        {
            //Dictionary<string, string> temp = new Dictionary<string, string>(new DictionaryIgnoreCase());

            StringCollectionIgnoreCase newNames = new StringCollectionIgnoreCase();

            foreach (string directoryName in directoryNames)
            //for (int i = 0; i < directoryNames.Count; i++)
            {
                switch (ValidateUtil.IsFileName(directoryName))
                {
                case ValidateFileNameResult.Empty:
                    return(CreateUpdateDiskFileStatus.EmptyFileName);

                case ValidateFileNameResult.TooLong:
                    return(CreateUpdateDiskFileStatus.InvalidFileNameLength);

                case ValidateFileNameResult.InvalidFileName:
                    return(CreateUpdateDiskFileStatus.InvalidFileName);

                case ValidateFileNameResult.Success:

                    if (newNames.Contains(directoryName))
                    {
                        return(CreateUpdateDiskFileStatus.DuplicateFileName);
                    }
                    newNames.Add(directoryName);

                    break;

                default:
                    return(CreateUpdateDiskFileStatus.UnknownError);
                }
            }

            foreach (string diskFileName in diskFileNames)
            //for (int i = 0; i < diskFileNames.Count; i++)
            {
                switch (ValidateUtil.IsFileName(diskFileName))
                {
                case ValidateFileNameResult.Empty:
                    return(CreateUpdateDiskFileStatus.EmptyFileName);

                case ValidateFileNameResult.TooLong:
                    return(CreateUpdateDiskFileStatus.InvalidFileNameLength);

                case ValidateFileNameResult.InvalidFileName:
                    return(CreateUpdateDiskFileStatus.InvalidFileName);

                case ValidateFileNameResult.Success:

                    if (newNames.Contains(diskFileName))
                    {
                        return(CreateUpdateDiskFileStatus.DuplicateFileName);
                    }
                    newNames.Add(diskFileName);

                    break;

                default:
                    return(CreateUpdateDiskFileStatus.UnknownError);
                }
            }

            return(DiskDao.Instance.RenameDiskDirectoryAndFiles(
                       userID, parentID, directoryIDs, diskFileIDs, directoryNames, diskFileNames));
        }
コード例 #2
0
ファイル: NotifyBO.cs プロジェクト: zhangbo27/bbsmax
        /// <summary>
        /// 删除多个通知
        /// </summary>
        /// <param name="notifyIDs">要删除的通知的ID集</param>
        public bool DeleteNotifies(int operatorUserID, IEnumerable <int> notifyIDs)
        {
            if (notifyIDs == null)
            {
                ThrowError(new NoSelectedNotifiesError("notifyIDs"));
                return(false);
            }

            if (!ValidateUtil.HasItems <int>(notifyIDs))
            {
                return(true);
            }
#if !Passport
            PassportClientConfig settings = Globals.PassportClient;
            if (settings.EnablePassport)
            {
                List <int> ids = new List <int>();
                foreach (int id in notifyIDs)
                {
                    ids.Add(id);
                }

                int[] t = new int[ids.Count];
                ids.CopyTo(t);

                APIResult result = null;

                try
                {
                    result = settings.PassportService.Notify_DeleteNotifies(operatorUserID, t);
                }
                catch (Exception ex)
                {
                    ThrowError(new APIError(ex.Message));
                    return(false);
                }

                if (result.ErrorCode == Consts.ExceptionCode)
                {
                    if (result.Messages.Length > 0)
                    {
                        throw new Exception(result.Messages[0]);
                    }

                    return(false);
                }
                else if (result.IsSuccess == false)
                {
                    ThrowError <CustomError>(new CustomError("", result.Messages[0]));
                    return(false);
                }

                return(true);
            }
            else
#endif
            {
                List <int>       deleteNotifyIds = new List <int>();
                NotifyCollection notifies        = NotifyDao.Instance.GetNotifies(notifyIDs);

                ///如果集合里没有数据, 会出现没有权限的误报, 因此直接返回
                if (notifies.Count == 0)
                {
                    return(true);
                }

                foreach (Notify notify in notifies)
                {
                    if (notify.UserID == operatorUserID || ManagePermission.Can(operatorUserID, BackendPermissions.ActionWithTarget.Manage_Notify, notify.UserID))
                    {
                        deleteNotifyIds.Add(notify.NotifyID);
                    }
                }

                if (deleteNotifyIds.Count == 0)
                {
                    ThrowError(new NoPermissionDeleteNotifyError());
                    return(false);
                }

                UnreadNotifyCollection unread;

                NotifyDao.Instance.DeleteNotifies(null, deleteNotifyIds, out unread);

                foreach (UnreadNotifies un in unread)
                {
                    RemoveCacheByType(un.UserID, 0);

                    if (OnUserNotifyCountChanged != null)
                    {
                        OnUserNotifyCountChanged(un);
                    }
                    AuthUser user = UserBO.Instance.GetUserFromCache <AuthUser>(un.UserID);
                    if (user != null)
                    {
                        user.UnreadNotify = un;
                    }
                }

                return(true);
            }
        }
コード例 #3
0
ファイル: UrlUtil.cs プロジェクト: zhangbo27/bbsmax
        public static void BuildMainDomain(string domain, bool cacheable, out string mainDomain, out string cookieDomain)
        {
            KeyValuePair <string, string> domainInfo;

            if (s_CachedMainDomains.TryGetValue(domain, out domainInfo))
            {
                mainDomain   = domainInfo.Key;
                cookieDomain = domainInfo.Key;

                return;
            }

            mainDomain = null;

            string[] splitDomain = domain.Split('.');

            if (splitDomain.Length == 4 && ValidateUtil.IsIPAddress(domain))    //如果是ip地址
            {
                mainDomain = string.Empty;
            }

            else if (splitDomain.Length == 2)
            {
                mainDomain = string.Empty;
            }

            else if (splitDomain.Length > 2)
            {
                switch (splitDomain[splitDomain.Length - 1])
                {
                case "cn":
                    foreach (string part in s_Domains_CN)
                    {
                        if (splitDomain[splitDomain.Length - 2] == part)
                        {
                            mainDomain = string.Concat(splitDomain[splitDomain.Length - 3], ".", splitDomain[splitDomain.Length - 2], ".", splitDomain[splitDomain.Length - 1]);
                            break;
                        }
                    }
                    break;

                case "ru":
                    foreach (string part in s_Domains_RU)
                    {
                        if (splitDomain[splitDomain.Length - 2] == part)
                        {
                            mainDomain = string.Concat(splitDomain[splitDomain.Length - 3], ".", splitDomain[splitDomain.Length - 2], ".", splitDomain[splitDomain.Length - 1]);
                            break;
                        }
                    }
                    break;

                default:
                    break;
                }

                if (string.IsNullOrEmpty(mainDomain))
                {
                    mainDomain = string.Concat(splitDomain[splitDomain.Length - 2], ".", splitDomain[splitDomain.Length - 1]);
                }
            }
            else
            {
                mainDomain = string.Empty;
            }


            if (mainDomain.Length == 0)
            {
                cookieDomain = string.Empty;
                mainDomain   = domain;
            }
            else
            {
                cookieDomain = "." + mainDomain;
            }
        }
コード例 #4
0
ファイル: CommentBO.cs プロジェクト: zhangbo27/bbsmax
        /*
         * /// <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);
        }