예제 #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
            });
        }
예제 #2
0
        private static void upgradeFlags()
        {
            string pkFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.GreaterThanOrEqual, "");

            TableQuery query = new TableQuery().Where(pkFilter).Select(new string[] { "flags" });

            int count = 0;

            foreach (DynamicTableEntity entity in Warehouse.DiscussionLoadTable.ExecuteQuery(query))
            {
                string        flags   = entity.GetFlags();
                StringBuilder builder = new StringBuilder("\n");

                SandFlags.SplitFlags(flags, (meta_title, meta_value) =>
                {
                    builder.Append(meta_title + "=" + meta_value + "\n");
                    count++;
                });
                if (builder.Length > 1)
                {
                    entity["flags2"] = new EntityProperty(builder.ToString());
                    Warehouse.DiscussionLoadTable.Execute(TableOperation.Merge(entity));
                }
            }
        }
예제 #3
0
        public static ViewType GetViewType(this DynamicTableEntity entity)
        {
            string flags = entity.GetFlags();

            //return SandFlags.Check(flags, SandFlags.VIEW_FLAG_CHAR, 2);

            int n = SandFlags.GetNumber(flags, SandFlags.MT_VIEW);

            return((ViewType)n);
        }
예제 #4
0
        public static void CheckControlRight(string board_id, string discussion_id, string letter_id, ref string delta_flags,
                                             DynamicTableEntity entity)
        {
            Subtype subtype = LetterConverter.GetSubtype(entity);

            if (subtype == Subtype.d)
            {
                Util.ThrowUnauthorizedException("不能修改的類型。");
            }

            bool auto_unreport = false;

            if (SandFlags.Check(delta_flags, SandFlags.MT_PERMANENT_DELETE, 1))
            {
                GroupStore.CheckPermanentDeleteRight(board_id, discussion_id, letter_id, entity);
                auto_unreport = true;
            }

            int delete_num = SandFlags.GetNumber(delta_flags, SandFlags.MT_DELETED);

            if (delete_num == 1 || delete_num == -1)
            {
                //bool is_undelete = SandFlags.Check(delta_flags, SandFlags.DELETED_FLAG_CHAR, -1);

                int user_level = GroupStore.CheckDeleteRight(board_id, discussion_id, letter_id, entity, delete_num == -1);

                //delta_flags = SandFlags.DELETED_FLAG_CHAR + (delete_num * user_level).ToString();
                //delta_flags = SandFlags.MultiplyNumber(delta_flags, SandFlags.DELETED_FLAG_CHAR, user_level);
                delta_flags = SandFlags.Operate(delta_flags, new FlagOperation
                {
                    type      = FlagOperation.Type.Multiply,
                    MetaTitle = SandFlags.MT_DELETED,
                    N         = user_level
                });

                string current_flags = entity.GetFlags();
                SandFlags.CheckLevel(current_flags, SandFlags.MT_DELETED, delta_flags);

                auto_unreport = true;
            }
            if (SandFlags.Check(delta_flags, SandFlags.MT_REPORT, 0))
            {
                GroupStore.CheckUnreportRight(board_id);
            }
            else if (SandFlags.Check(delta_flags, SandFlags.MT_REPORT, 1))
            {
            }
            else
            {
                if (auto_unreport)
                {
                    delta_flags = SandFlags.Add(delta_flags, SandFlags.MT_REPORT, 0);
                }
            }
        }
예제 #5
0
        public static void OperateFlags(this DynamicTableEntity entity, FlagOperation op)
        {
            string flags = entity.GetFlags();

            //flags = SandFlags.Merge(flags, delta_flags);
            flags = SandFlags.Operate(flags, op);

            if (flags.Length > 0)
            {
                entity["flags2"] = new EntityProperty(flags);
            }
            else
            {
                entity.Properties.Remove("flags2");
            }
        }
예제 #6
0
        public BoardSetting(string board_id)
        {
            BoardId   = board_id;
            BoardName = Warehouse.BsMapPond.Get().GetBoardName(board_id);

            string flags = BoardInfoStore.GetBoardFlags(board_id);

            this.LowKey = SandFlags.Check(flags, SandFlags.MT_LOW_KEY, 1);

#if ACCOUNT_USING_SQL
            g10 = GroupStore.GetBoardGroup(board_id, GroupStore.ChairOwnerGroupName, out g10UserIds);
            g11 = GroupStore.GetBoardGroup(board_id, GroupStore.ViceOwnerGroupName, out g11UserIds);
            g12 = GroupStore.GetBoardGroup(board_id, GroupStore.InsiderGroupName, out g12UserIds);
#endif
            //
            Output = JsonConvert.SerializeObject(this);                         // the ","Output":null" will also be written into Output.
        }
예제 #7
0
        public static void CreateLetterEntity(DynamicTableEntity entity, string creator, string words,
                                              Subtype subtype, string delta_flags, string board_id, string discussion_id)
        {
            CreatorConverter.FillEntity(entity, CreatorConverter.Status.Creator, creator);

            entity["subtype"] = new EntityProperty(subtype.ToString());
#if OLD
            string flags = SandFlags.Merge("", delta_flags);

            if (flags.Length > 0)
            {
                entity["flags"] = new EntityProperty(flags);
            }
#else
            entity.OperateFlags(new FlagMergeOperation(delta_flags));
#endif
            fillWords(entity, words, board_id, discussion_id);                          // must be after flags modification so that encrypt flag is correct.
        }
예제 #8
0
        private static void moveForeMeta()
        {
            Regex regex = new Regex(@"^>>(.+?)\n", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.CultureInvariant);
            //Regex regex = new Regex(@"^>>(.+?)$", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.CultureInvariant);
            // some abstract contain only ">>(0,0)" and no "\n".

            string pkFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.GreaterThanOrEqual, "");

            TableQuery query = new TableQuery().Where(pkFilter).Select(new string[] { "flags2", "abstract" });

            int count = 0;

            foreach (DynamicTableEntity entity in Warehouse.DiscussionLoadTable.ExecuteQuery(query))
            {
                string flags = null;
                string ab    = LetterConverter.GetAbstract(entity);

                if (ab != null)
                {
                    ab = regex.Replace(ab, (Match match) =>
                    {
                        if (match.Groups[1].Value[0] == '(')
                        {
                            flags = entity.GetFlags();
                            flags = SandFlags.Add(flags, SandFlags.MT_COORDINATE, match.Groups[1].Value);
                        }
                        return(string.Empty);
                    });
                }

                if (flags != null)
                {
                    count++;

                    entity["flags2"]   = new EntityProperty(flags);
                    entity["abstract"] = new EntityProperty(ab);

                    Warehouse.DiscussionLoadTable.Execute(TableOperation.Merge(entity));

                    //if (count > 0)
                    //	break;
                }
            }
        }
예제 #9
0
        public static bool VoteLetter(string board_id, string discussion_id, string letter_id, string delta_flags)
        {
            try
            {
                SandFlags.SplitFlags(delta_flags, (meta_title, meta_value) =>
                {
                    VoteBookStore.Vote(board_id, discussion_id, letter_id, meta_title);
                });
            }
            catch (StorageException ex)
            {
                return(false);
            }

            string partition_key = SandId.CombineId(board_id, discussion_id);

            string pkFilter       = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partition_key);
            string rkFilter       = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, letter_id);
            string combinedFilter = TableQuery.CombineFilters(pkFilter, TableOperators.And, rkFilter);

            TableQuery query = new TableQuery().Where(combinedFilter).Select(new string[] { "flags2" });

            foreach (DynamicTableEntity entity in Warehouse.DiscussionLoadTable.ExecuteQuery(query))
            {
                entity.OperateFlags(new FlagOperation
                {
                    type       = FlagOperation.Type.AddMultiple,
                    DeltaFlags = delta_flags,
                });

                if (entity.Properties.Count == 0)                               // TableOperation.Merge cannot be used to remove property. if "flags" becomes empty, it will be removed from properties and the merge will have no effect.
                {
                    throw new ProgramLogicException();
                }

                Warehouse.DiscussionLoadTable.Execute(TableOperation.Merge(entity));
            }
            Warehouse.DiscussionLoadPond.Notify(board_id, discussion_id);
            Warehouse.DiscussionSummaryPond.Notify(board_id, discussion_id);
            HttpResponse.RemoveOutputCacheItem("/discussionload/" + board_id + "/" + discussion_id);
            // Cache of ViewDiscussion is not removed so may serve old version.
            return(true);
        }
예제 #10
0
        private static void fillWords(DynamicTableEntity entity, string words, string board_id, string discussion_id)
        {
            string flags   = entity.GetFlags();
            bool   encrypt = SandFlags.Check(flags, SandFlags.MT_AUTHORIZATION, 2);

            if (encrypt)
            {
                entity["abstract"] = new EntityProperty(string.Empty);

                string key   = Warehouse.DiscussionKeyPond.Get(board_id, discussion_id, true);
                string crypt = CryptUtil.Encrypt(words, key);

                entity["words"] = new EntityProperty(crypt);
#if DEBUG
                string plain = CryptUtil.Decrypt(crypt, key);
                if (words != plain)
                {
                    throw new ProgramLogicException();
                }
#endif
            }
            else if (words.Length > ABSTRACT_MAX_LEN)
            {
                int p = words.LastIndexOfAny(Util.WordsSplitCharacters, ABSTRACT_MAX_LEN);
                if (p == -1)
                {
                    p = 0;
                }

                entity["abstract"] = new EntityProperty(words.Substring(0, p));
                entity["words"]    = new EntityProperty(words.Substring(p));
            }
            else
            {
                entity["abstract"] = new EntityProperty(words);
                entity.Properties.Remove("words");
            }
        }
예제 #11
0
        public static bool IsPermanentlyDeleted(this DynamicTableEntity entity)
        {
            string flags = entity.GetFlags();

            return(SandFlags.Check(flags, SandFlags.MT_PERMANENT_DELETE, 1));
        }
예제 #12
0
        public static void TestMain()
        {
#if false
            Debug.Assert(SandFlags.CheckWithin("", 'd') == true);
            Debug.Assert(SandFlags.CheckWithin(",l2,", 'l') == true);
            Debug.Assert(SandFlags.CheckWithin(",l2,", 'd', 'l') == true);
            Debug.Assert(SandFlags.CheckWithin(",l2,", 'd') == false);
            Debug.Assert(SandFlags.CheckWithin(",d1,l2,", 'd') == false);
            Debug.Assert(SandFlags.CheckWithin(",d1,l2,", 'd', 'l') == true);
            Debug.Assert(SandFlags.CheckWithin(",d1,l2,", 'l') == false);
            Debug.Assert(SandFlags.CheckWithin(",d1,l2,", 'd', 'l', 'e') == true);
            Debug.Assert(SandFlags.CheckWithin(",d1,l2,", 'f', 'l', 'e') == false);
            Debug.Assert(SandFlags.CheckWithin(",d1,l2,", 'd', 'f', 'e') == false);

            Debug.Assert(SandFlags.Check("", 'c') == false);
            Debug.Assert(SandFlags.Check(",", 'c') == false);
            Debug.Assert(SandFlags.Check(",c0,", 'c') == true);
            Debug.Assert(SandFlags.Check(",d5,", 'c') == false);
            Debug.Assert(SandFlags.Check(",d55555,e6,", 'c') == false);
            Debug.Assert(SandFlags.Check(",d5,e6666,c7,", 'c') == true);
            Debug.Assert(SandFlags.Check(",d5,e6,c77,f8,", 'c') == true);
            Debug.Assert(SandFlags.Check(",d5,e6,f88,", 'c') == false);

            Debug.Assert(SandFlags.Add("", "c3") == ",c3,");
            Debug.Assert(SandFlags.Add(",", "c34") == ",c34,");
            Debug.Assert(SandFlags.Add(",d4,", "c355") == ",d4,c355,");
            Debug.Assert(SandFlags.Add(",d4,e5,", "c3666") == ",d4,e5,c3666,");

            Debug.Assert(SandFlags.Remove("", 'c') == "");
            Debug.Assert(SandFlags.Remove(",", 'c') == "");
            Debug.Assert(SandFlags.Remove(",d5,", 'c') == ",d5,");
            Debug.Assert(SandFlags.Remove(",d5,e6,", 'c') == ",d5,e6,");
            Debug.Assert(SandFlags.Remove(",c2,", 'c') == "");
            Debug.Assert(SandFlags.Remove(",c0,d5,", 'c') == ",d5,");
            Debug.Assert(SandFlags.Remove(",d5,c1,", 'c') == ",d5,");
            Debug.Assert(SandFlags.Remove(",d5,c18,f9,", 'c') == ",d5,f9,");
            Debug.Assert(SandFlags.Remove(",c199,d5,f9,", 'c') == ",d5,f9,");
            Debug.Assert(SandFlags.Remove(",d5,f9,c1777,", 'c') == ",d5,f9,");

            Debug.Assert(SandFlags.Merge("", "") == "");
            Debug.Assert(SandFlags.Merge(",g6,", "") == ",g6,");
            Debug.Assert(SandFlags.Merge("", ",c1,") == ",c1,");
            Debug.Assert(SandFlags.Merge(",g6,", ",c1,") == ",g6,c1,");
            Debug.Assert(SandFlags.Merge("", ",c1,d2,") == ",c1,d2,");
            Debug.Assert(SandFlags.Merge(",e3,", ",c1,d2,") == ",e3,c1,d2,");
            Debug.Assert(SandFlags.Merge(",e3,f4,", ",c1,d2,") == ",e3,f4,c1,d2,");
            Debug.Assert(SandFlags.Merge(",e3,f4,c99,", ",c1,d2,") == ",e3,f4,c1,d2,");
            Debug.Assert(SandFlags.Merge(",c500,e3,f4,", ",c1,d2,") == ",e3,f4,c1,d2,");
            Debug.Assert(SandFlags.Merge(",e3,f4,c88,", ",c1,d2,") == ",e3,f4,c1,d2,");
            Debug.Assert(SandFlags.Merge(",d2,e3,f4,c88,", ",c1,d2,") == ",e3,f4,c1,d2,");
            Debug.Assert(SandFlags.Merge(",e3,d77,f4,c88,", ",c1,d2,") == ",e3,f4,c1,d2,");
            Debug.Assert(SandFlags.Merge(",e3,f4,d555,c88,", ",c1,d2,") == ",e3,f4,c1,d2,");

            Debug.Assert(SandFlags.Merge("", ",h0,") == "");
            Debug.Assert(SandFlags.Merge(",g6,", ",h0,") == ",g6,");
            Debug.Assert(SandFlags.Merge(",g6,h0,", ",h0,") == ",g6,");
            Debug.Assert(SandFlags.Merge(",h1,g6,", ",h0,") == ",g6,");
            Debug.Assert(SandFlags.Merge(",k7,h335,g6,", ",h0,") == ",k7,g6,");
            Debug.Assert(SandFlags.Merge(",k7,g666,h335,", ",h0,") == ",k7,g666,");
            Debug.Assert(SandFlags.Merge(",h335,k77,g6,", ",h0,") == ",k77,g6,");

            Debug.Assert(SandFlags.Merge(",h335,k77,g6,", ",h0,g0,") == ",k77,");
            Debug.Assert(SandFlags.Merge(",h335,k77,g6,", ",k0,g0,") == ",h335,");
            Debug.Assert(SandFlags.Merge(",h3,k7,g6,", ",k0,g7,h4,") == ",g7,h4,");
            Debug.Assert(SandFlags.Merge(",h3,k7,g6,", ",k0,g7,h4,e9,") == ",g7,h4,e9,");
            Debug.Assert(SandFlags.Merge(",a1,b2,c3,d4,e5,", ",g7,e1,d0,b0,a5,f6") == ",c3,g7,e1,a5,f6,");

            Debug.Assert(SandId.CountBoardList("b3a") == -1);
            Debug.Assert(SandId.CountBoardList("ba") == -1);
            Debug.Assert(SandId.CountBoardList("c,b5") == -1);
            Debug.Assert(SandId.CountBoardList("b70,ba") == -1);
            Debug.Assert(SandId.CountBoardList("b70,ba,") == -1);

            Debug.Assert(SandId.CountBoardList("") == 0);
            Debug.Assert(SandId.CountBoardList(",") == -1);
            Debug.Assert(SandId.CountBoardList(",,") == -1);
            Debug.Assert(SandId.CountBoardList("c") == -1);
            Debug.Assert(SandId.CountBoardList("b") == -1);
            Debug.Assert(SandId.CountBoardList("b3") == 1);
            Debug.Assert(SandId.CountBoardList(",b3") == -1);
            Debug.Assert(SandId.CountBoardList("b3,") == 1);
            Debug.Assert(SandId.CountBoardList("b30") == 1);
            Debug.Assert(SandId.CountBoardList("b30,c") == -1);
            Debug.Assert(SandId.CountBoardList("b30,b") == -1);
            Debug.Assert(SandId.CountBoardList("b30,b50") == 2);
            Debug.Assert(SandId.CountBoardList(",b30,b50") == -1);
            Debug.Assert(SandId.CountBoardList("b30,b50,") == 2);
            Debug.Assert(SandId.CountBoardList("b30,,b50") == -1);
            Debug.Assert(SandId.CountBoardList("b30,b50,b800") == 3);

            LinkedList <string> list = new LinkedList <string>();

            string text = Util.Serialize(list);
            LinkedList <string> list2 = Util.DeserializeToLinkedList(text);

            list.AddFirst("d");

            text  = Util.Serialize(list);
            list2 = Util.DeserializeToLinkedList(text);

            DiscussionSummary ds = new DiscussionSummary("b1026", "d11");

            StringWriter sw = new StringWriter();
            ds.Write(sw);
            string str = sw.ToString();

            LinkedList <string> q = RollManager.GetLatest("b1026");
            RollManager.PutLatest("b1026", "d90");
            RollManager.PutLatest("b1026", "d3");
            RollManager.PutLatest("b1026", "d77");
            RollManager.PutLatest("b1026", "d10");
            RollManager.PutLatest("b1026", "d77");

            q = RollManager.GetLatest("b1000");
            RollManager.PutLatest("b1000", "d1");
            RollManager.PutLatest("b1000", "d1");
            RollManager.PutLatest("b1000", "d10");
            RollManager.PutLatest("b1000", "d5");
            RollManager.PutLatest("b1000", "d1");


            List <string> list     = MvcWebRole1.Models.Store.GetLastDiscussions("b1026", 5);
            string        board_id = Store.CreateBoard("測試板");
#endif
        }