Пример #1
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);
                }
            }
        }
Пример #2
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.
        }
Пример #3
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");
            }
        }
Пример #4
0
        public static bool IsPermanentlyDeleted(this DynamicTableEntity entity)
        {
            string flags = entity.GetFlags();

            return(SandFlags.Check(flags, SandFlags.MT_PERMANENT_DELETE, 1));
        }
Пример #5
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
        }