Esempio n. 1
0
        /// <summary>マイリストへ動画を追加するストリームを取得する</summary>
        /// <param name="AddItem">追加する動画</param>
        /// <param name="IsGetToken">トークンを取得するかどうか</param>
        public Streams <Response> OpenMylistAddVideoStreams(Mylist.MylistItem AddItem, bool IsGetToken = true)
        {
            var streamDataList = new List <StreamData>();

            StreamData[] uploadStreamDatas = null;
            Response     result            = null;

            if (IsGetToken)
            {
                streamDataList.AddRange(host.GetToken());
            }

            if (target.ID == "")//とりあえずマイリスト
            {
                uploadStreamDatas = context.Client.OpenUploadStreams(ApiUrls.DeflistAddVideo, ContentType.Form).GetStreamDatas();
                uploadStreamDatas[0].GetWriteData = () =>
                {
                    return(Encoding.UTF8.GetBytes(string.Format(
                                                      PostTexts.DeflistAddVideo,
                                                      AddItem.VideoInfo.ID,
                                                      AddItem.Description,
                                                      host.token)));
                };
            }
            else
            {
                uploadStreamDatas = context.Client.OpenUploadStreams(ApiUrls.MylistAddVideo, ContentType.Form).GetStreamDatas();
                uploadStreamDatas[0].GetWriteData = () =>
                {
                    return(Encoding.UTF8.GetBytes(string.Format(
                                                      PostTexts.MylistAddVideo,
                                                      target.ID,
                                                      AddItem.VideoInfo.ID,
                                                      AddItem.Description,
                                                      "",
                                                      host.token)));
                };
            }

            uploadStreamDatas[1].SetReadData = (data) =>
            {
                var serialize = new DataContractJsonSerializer(typeof(Serial.MylistAddVideo.Contract));
                result = converter.ConvertResponse(
                    (Serial.MylistAddVideo.Contract)serialize.ReadObject(new MemoryStream(data)));
            };
            streamDataList.AddRange(uploadStreamDatas);

            return(new Streams <Response>(
                       streamDataList.ToArray(),
                       () => result));
        }
Esempio n. 2
0
        /// <summary>マイリストへ動画を追加する</summary>
        /// <param name="AddItem">追加する動画</param>
        /// <param name="IsGetToken">トークンを取得するかどうか</param>
        public Response MylistAddVideo(Mylist.MylistItem AddItem, bool IsGetToken = true)
        {
            var streams = OpenMylistAddVideoStreams(AddItem, IsGetToken);

            return(streams.Run(streams.UntreatedCount));
        }