Ejemplo n.º 1
0
        public static ControlHistory ControlLetter(string board_id, string discussion_id, string letter_id, string delta_flags)
        {
            string partition_key = SandId.CombineId(board_id, discussion_id);

            // todo: select only needed properties.
            TableResult        result = Warehouse.DiscussionLoadTable.Execute(TableOperation.Retrieve(partition_key, letter_id));
            DynamicTableEntity entity = (DynamicTableEntity)result.Result;

            // permanent deleting twice is not blocked.
            GroupStore.CheckControlRight(board_id, discussion_id, letter_id, ref delta_flags, entity);

            int ec = RevisionStore.IncreaseEditCount(entity);

            RevisionStore.CreateRevision(entity, board_id, discussion_id, letter_id, ec);

            int prev_report_cnt = SandFlags.GetNumber(entity.GetFlags(), SandFlags.MT_REPORT);

            LetterConverter.ModifyLetterFlags(entity, null, delta_flags);

            int new_report_cnt = SandFlags.GetNumber(entity.GetFlags(), SandFlags.MT_REPORT);

            Warehouse.DiscussionLoadTable.Execute(TableOperation.Replace(entity));                  // Throws StorageException ((412) Precondition Failed) if the entity is modified in between.

            Warehouse.DiscussionLoadPond.Notify(board_id, discussion_id);
            Warehouse.DiscussionSummaryPond.Notify(board_id, discussion_id);
            HttpResponse.RemoveOutputCacheItem("/discussionload/" + board_id + "/" + discussion_id);

            return(new ControlHistory {
                ReportCount = new_report_cnt - prev_report_cnt
            });
        }
Ejemplo n.º 2
0
        public static void EditLetter(string board_id, string discussion_id, string letter_id, string editor, string words,
                                      string delta_flags, HttpFileCollectionBase files)
        {
            string partition_key = SandId.CombineId(board_id, discussion_id);

            TableResult        result = Warehouse.DiscussionLoadTable.Execute(TableOperation.Retrieve(partition_key, letter_id));
            DynamicTableEntity entity = (DynamicTableEntity)result.Result;

            GroupStore.CheckEditRight(board_id, discussion_id, entity);

            HashSet <string> files_set = new HashSet <string>();

            words = processUploadFiles(words, files, files_set);
            words = processWords(words);
            claimFiles(words, SandId.CombineId(board_id, discussion_id, letter_id), files_set);

            // if (entity != null)		// let it throw null reference exception.
            int ec = RevisionStore.IncreaseEditCount(entity);

            RevisionStore.CreateRevision(entity, board_id, discussion_id, letter_id, ec);

            LetterConverter.EditLetterEntity(entity, editor, words, delta_flags, board_id, discussion_id);

            Warehouse.DiscussionLoadTable.Execute(TableOperation.Replace(entity));                  // Throws StorageException ((412) Precondition Failed) if the entity is modified in between.

            Warehouse.DiscussionLoadPond.Notify(board_id, discussion_id);
            Warehouse.DiscussionSummaryPond.Notify(board_id, discussion_id);

            HttpResponse.RemoveOutputCacheItem("/discussionload/" + board_id + "/" + discussion_id);
        }
Ejemplo n.º 3
0
        public static void SetBoardSetting(string board_id, string board_name)
        {
            TableResult        result = Warehouse.BoardListTable.Execute(TableOperation.Retrieve(board_id, EMPTY_ROW_KEY));
            DynamicTableEntity entity = (DynamicTableEntity)result.Result;

            // if (entity != null)		// let it throw null reference exception.
            int ec = RevisionStore.IncreaseEditCount(entity);

            string partition_key = SandId.CombineId(Warehouse.BoardListTable.Name, board_id);

            RevisionStore.CreateHistory(entity, partition_key, ec, "boardname");

            CreatorConverter.FillEntity(entity, CreatorConverter.Status.Editor, null);
            entity["boardname"].StringValue = board_name;

            Warehouse.BoardListTable.Execute(TableOperation.Replace(entity));                  // Throws StorageException ((412) Precondition Failed) if the entity is modified in between.
            //don't work for child action. //HttpResponse.RemoveOutputCacheItem("/boardlist");

            //List<string> selection_list = SelectionBoardListResult.GetSelectionList(board_id);

            //if (selection_list != null)
            //foreach (string selection_id in selection_list)
            //don't work for child action. //HttpResponse.RemoveOutputCacheItem("/discussionlist/" + selection_id);

            Warehouse.BsMapPond.Notify();
            Warehouse.DiscussionListPond.Notify(board_id);
            Warehouse.BoardSettingPond.Notify(board_id);
        }
Ejemplo n.º 4
0
        public static void SetBoardFlags(string board_id, string delta_flags)
        {
            TableResult        result = Warehouse.BoardListTable.Execute(TableOperation.Retrieve(board_id, EMPTY_ROW_KEY));
            DynamicTableEntity entity = (DynamicTableEntity)result.Result;

            int ec = RevisionStore.IncreaseEditCount(entity);

            string partition_key = SandId.CombineId(Warehouse.BoardListTable.Name, board_id);

            RevisionStore.CreateHistory(entity, partition_key, ec, "flags2");

            CreatorConverter.FillEntity(entity, CreatorConverter.Status.Editor, null);
            entity.OperateFlags(new FlagMergeOperation(delta_flags));

            Warehouse.BoardListTable.Execute(TableOperation.Replace(entity));                  // Throws StorageException ((412) Precondition Failed) if the entity is modified in between.

            Warehouse.BoardSettingPond.Notify(board_id);
        }
Ejemplo n.º 5
0
        public static void UpdateGroup(string board_id, string group_id, string add_users, string remove_users)
        {
            string role_name = SandId.CombineId(board_id, group_id);

            if (!Roles.RoleExists(role_name))
            {
                Roles.CreateRole(role_name);
            }

            string[] ru = remove_users.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            if (ru.Length > 0)
            {
                Roles.RemoveUsersFromRole(ru, role_name);
            }

            string[] au = add_users.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            int cnt = Roles.GetUsersInRole(role_name).Length;

            int limit = group_id == GroupStore.ChairOwnerGroupName ? 1 : HeartsConfiguration.MAX_NUM_OF_USERS_IN_A_GROUP;

            if (cnt + au.Length > limit)
            {
                Util.ThrowBadRequestException("使用者數量超過" + limit + "個。");
            }

            if (au.Length > 0)
            {
                Roles.AddUsersToRole(au, role_name);
            }

            Warehouse.BoardSettingPond.Notify(board_id);

            string month = Util.DateTimeToString(DateTime.Now, 5);

            RevisionStore.CreateActivity(SandId.CombineId(ActivityType.UpdateGroup.ToString(), board_id, month),
                                         new string[] { "group_id", "add_users", "remove_users" },
                                         new object[] { group_id, add_users, remove_users });
        }