Пример #1
0
        public void CreateNewPost(byte[] argument, uint u)
        {
            byte[] threadIdBytes  = new byte[4];
            byte[] usernameBytes  = new byte[16];
            byte[] postTitleBytes = new byte[36];
            byte[] postBodyBytes  = new byte[600];

            Buffer.BlockCopy(argument, 0, threadIdBytes, 0, 4);
            Buffer.BlockCopy(argument, 4, usernameBytes, 0, 16);
            Buffer.BlockCopy(argument, 84, postTitleBytes, 0, 32);
            Buffer.BlockCopy(argument, 134, postBodyBytes, 0, 600);

            Console.WriteLine("Thread ID  = " + BitConverter.ToString(threadIdBytes));
            Console.WriteLine("username " + BitConverter.ToString(usernameBytes));
            Console.WriteLine("post Title " + BitConverter.ToString(postTitleBytes));
            Console.WriteLine("post Body " + BitConverter.ToString(postBodyBytes));


            // int threadIDX = BitConverter.ToInt32(threadIdBytes);
            String username  = _encoding.GetString(usernameBytes);
            String postTitle = _encoding.GetString(postTitleBytes);
            String postBody  = _encoding.GetString(postBodyBytes);

            int threadID = 0;

            if (u == 0)
            {
                // Create a new Thread before posting

                BbsThreadModel thread = new BbsThreadModel();
                thread.threadTitle = postTitleBytes;
                thread.categoryID  = 1;

                using (ISession session = _sessionFactory.OpenSession())
                {
                    //threadID = session.Query<BbsThreadModel>().Max(x => (int?) x.threadID).Value + 1;
                    //thread.threadID = threadID;
                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        session.Save(thread);
                        transaction.Commit();
                        threadID = thread.threadID;
                    }

                    session.Close();
                }
            }
            else
            {
                threadID = Convert.ToInt32(u);
            }


            // post to an existing thread

            BbsPostMetaModel meta = new BbsPostMetaModel();


            meta.unk2     = 0;
            meta.date     = DateTime.UtcNow;
            meta.username = usernameBytes;
            meta.title    = postTitleBytes;
            meta.subtitle = new byte[16];
            if (postTitle.Length > 16)
            {
                Buffer.BlockCopy(postTitleBytes, 0, meta.subtitle, 0, 16);
            }
            else
            {
                meta.subtitle = postTitleBytes;
            }
            meta.unk3     = "unk3";
            meta.threadID = threadID;

            using (ISession session = _sessionFactory.OpenSession())
            {
                try
                {
                    meta.unk0 = session.Query <BbsPostMetaModel>().Max(x => (int?)x.unk0).Value + 1;
                }
                catch (Exception)
                {
                    Console.WriteLine("BBS is empty , creating needed data");
                    meta.unk0 = 1;
                }

                //int postBodyID = session.Query<BbsPostBody>().Max(x => (int?) x.postBodyID).Value + 1;
                //meta.postID = postID;
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Save(meta);
                    //transaction.Commit();

                    BbsPostBody body = new BbsPostBody();

                    body.postBody = postBodyBytes;
                    body.postID   = meta.postID;

                    session.Save(body);
                    transaction.Commit();
                }

                session.Close();
            }

            // Console.WriteLine("Thread ID  = " + threadIDX);
            Console.WriteLine("username " + username);
            Console.WriteLine("post Title " + postTitle);
            Console.WriteLine("post Body " + postBody);
        }