Example #1
0
 internal Streams(StreamData[] StreamDatas)
 {
     nowIndex = 0;
     streamDatas = StreamDatas;
     NowStreamType = StreamDatas[0].StreamType;
 }
Example #2
0
        /// <summary>コメントをアップロードするストリームを取得する</summary>
        /// <param name="Comment">投稿するコメント</param>
        public Streams<Response> OpenCommentUploadStreams(Comment Comment)
        {
            var videoAccessStreamData = OpenVideoAccessStreamData();
            var streamDataList = new List<StreamData>();
            var uploadStreamData = new StreamData[2];
            string postkey = null;
            Response result = null;

            for (int i = 0; i < 2; i++)
                uploadStreamData[i] = new StreamData();

            if (videoAccessStreamData != null)
                streamDataList.Add(videoAccessStreamData);

            if (videoCache == null || videoCache.Count < 15)
                streamDataList.AddRange(OpenCommentDownloadStreams().GetStreamDatas());

            streamDataList.Add(
                new StreamData()
                {
                    StreamType = StreamType.Read,
                    GetStream = () =>
                    {
                        return context.Client.OpenDownloadStream(
                            string.Format(ApiUrls.PostVideoComment,
                                videoCache["block_no"],
                                videoCache["thread_id"]));
                    },
                    SetReadData = (data) =>
                    {
                        postkey = Uri.UnescapeDataString(Encoding.UTF8.GetString(data)).Replace("postkey=", "");
                    },
                });

            //コメント投稿ストリームデータ生成
            var super = streamDataList[0].SetReadData;
            streamDataList[0].SetReadData = (data) =>
            {
                super(data);
                var streamData = context.Client.OpenUploadStreams(videoCache["ms"], ContentType.XML).GetStreamDatas();
                for (int i = 0; i < 2; i++)
                {
                    uploadStreamData[i].StreamType = streamData[i].StreamType;
                    uploadStreamData[i].GetStream = streamData[i].GetStream;
                }
            };

            uploadStreamData[0].GetWriteData = () =>
            {
                return Encoding.UTF8.GetBytes(
                    string.Format(PostTexts.PostVideoComment,
                        videoCache["thread_id"],
                        ((int)(Comment.PlayTime.TotalMilliseconds / 10)).ToString(),
                        Comment.Command,
                        videoCache["ticket"],
                        videoCache["user_id"],
                        postkey,
                        Comment.Body));
            };

            uploadStreamData[1].SetReadData = (data) =>
            {
                var serialize = new XmlSerializer(typeof(Serial.PostComment.Packet));
                var serial = (Serial.PostComment.Packet)serialize.Deserialize(new MemoryStream(data));
                result = converter.ConvertResponse(serial);
                videoCache["block_no"] = ((int)((serial.chat_result.no + 1) / 100)).ToString();//更新
            };
            streamDataList.AddRange(uploadStreamData);

            return new Streams<Response>(
                streamDataList.ToArray(),
                () => result);
        }