Exemple #1
0
        /// <summary>
        /// コメントデータを取得する
        /// </summary>
        private async Task <List <ComApi.CommentBody.Json.JsonComment> > GetCommentData(WatchPage::BaseJson data, int?_when = null)
        {
            var logger     = NicoLogger.GetLogger();
            var serializer = new CommentSerializer();
            var chandler   = new CommentHandller();

            List <ComApi.RequestItems> comRequest = GetCommentRequest(data, _when);

            //コメントを取得する
            logger.Debug("コメントの取得を開始", moduleName);
            HttpClient client  = context.NicoClient.Client;
            var        comBody = await client.PostAsync(new Uri(@"http://nmsg.nicovideo.jp/api.json/"), new StringContent(serializer.SerializeJson(comRequest)));

            //エラーハンドリング
            if (!comBody.IsSuccessStatusCode)
            {
                throw new Exception($"コメントの取得に失敗しました。 (status_code: {(int)comBody.StatusCode})");
            }
            else
            {
                logger.Debug($"コメントデータの取得が完了", moduleName);
            }

            //取得したコメントをデシリアライズ
            string comJson = await comBody.Content.ReadAsStringAsync();

            return(serializer.DeserializeJson <List <ComApi.CommentBody.Json.JsonComment> >(comJson));
        }
Exemple #2
0
        /// <summary>
        /// XMLを取得
        /// </summary>
        /// <param name="comments"></param>
        /// <returns></returns>
        public string GetXML(List <ComApi.CommentBody.Json.JsonComment> comments)
        {
            var xmlItems = new ComApi::CommentBody.XML.packet();

            xmlItems.chat = new List <ComApi.CommentBody.XML.packetChat>();

            foreach (var comment in comments)
            {
                if (comment.thread != null)
                {
                    xmlItems.thread = GetThread(comment.thread);
                }
                else if (comment.chat != null)
                {
                    xmlItems.chat.Add(GetChat(comment.chat));
                }
            }
            var serializer = new CommentSerializer();

            return(serializer.SerializeXML(xmlItems));
        }