Exemple #1
0
        public async Task PostComment(string comment, uint userId, string command, TimeSpan elapsedTime)
        {
            var postkey = await NiconicoContext.Live.GetPostKeyAsync(ThreadIdNumber, CommentCount / 100);

            if (string.IsNullOrEmpty(postkey))
            {
                CommentPosted?.Invoke(false /* failed post comment */, null);
                return;
            }

            PostChat chat = new PostChat();

            chat.Comment  = comment;
            chat.ThreadId = ThreadId;
            chat.PostKey  = postkey;
            chat.Ticket   = _Ticket;
            chat.Mail     = command;
            chat.Premium  = "";
            chat.UserId   = userId.ToString();

            var time = (uint)((elapsedTime + TimeSpan.FromSeconds(1)).TotalSeconds * 100);

            chat.Vpos = time.ToString();
            try
            {
                var chatSerializer = new XmlSerializer(typeof(PostChat));

                using (var releaser = await _NetworkStreamLock.LockAsync())
                {
                    var writer = _NetworkStream.AsOutputStream().AsStreamForWrite();
                    chatSerializer.Serialize(writer, chat);
                    writer.WriteByte(0);
                    writer.Flush();
                }

                _LastPostChat = chat;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());

                CommentPosted?.Invoke(false /* failed post comment */, null);
            }
        }