示例#1
0
        public bool Append(IChunkUploadAppendParameters parameters)
        {
            if (MediaId == null)
            {
                throw new InvalidOperationException("You cannot append content to a non initialized chunked upload. You need to invoke the initialize method OR set the MediaId property of an existing ChunkedUpload.");
            }

            if (parameters.SegmentIndex == null)
            {
                parameters.SegmentIndex = NextSegmentIndex;
            }

            if (parameters.MediaId == null)
            {
                parameters.MediaId = MediaId;
            }

            var appendQuery = _uploadQueryGenerator.GetChunkedUploadAppendQuery(parameters);

            var multiPartRequestParameters = new MultipartHttpRequestParameters
            {
                Query    = appendQuery,
                Binaries = new List <byte[]> {
                    parameters.Binary
                },
                Timeout               = parameters.Timeout,
                ContentId             = parameters.MediaType,
                UploadProgressChanged = parameters.UploadProgressChanged
            };

            var success = _twitterAccessor.TryExecuteMultipartQuery(multiPartRequestParameters);

            if (success)
            {
                UploadedSegments.Add(parameters.SegmentIndex.Value, parameters.Binary);
                ++NextSegmentIndex;
            }

            return(success);
        }
示例#2
0
        public string GetChunkedUploadAppendQuery(IChunkUploadAppendParameters parameters)
        {
            if (parameters.MediaId == null)
            {
                throw new ArgumentNullException($"{nameof(parameters.MediaId)}", "APPEND Media Id cannot be null. Make sure you use the media id retrieved from the INIT query.");
            }

            if (parameters.SegmentIndex == null)
            {
                throw new ArgumentNullException($"{nameof(parameters.SegmentIndex)}", "APPEND Segment index is required. Its initial value should be 0.");
            }

            var appendQuery = new StringBuilder(Resources.Upload_URL);

            appendQuery.AddParameterToQuery("command", "APPEND");
            appendQuery.AddParameterToQuery("media_id", parameters.MediaId.Value.ToString(CultureInfo.InvariantCulture));
            appendQuery.AddParameterToQuery("segment_index", parameters.SegmentIndex.Value.ToString(CultureInfo.InvariantCulture));

            appendQuery.AddFormattedParameterToQuery(parameters.CustomRequestParameters?.FormattedCustomQueryParameters);

            return(appendQuery.ToString());
        }
示例#3
0
        public string GetChunkedUploadAppendQuery(IChunkUploadAppendParameters parameters)
        {
            if (parameters.MediaId == null)
            {
                throw new ArgumentNullException("APPEND Media Id cannot be null. Make sure you use the media id retrieved from the INIT query.");
            }

            if (parameters.SegmentIndex == null)
            {
                throw new ArgumentNullException("APPEND Segment index is required. Its initial value should be 0.");
            }

            var appendQuery = Resources.Upload_URL;

            appendQuery = appendQuery.AddParameterToQuery("command", "APPEND");
            appendQuery = appendQuery.AddParameterToQuery("media_id", parameters.MediaId.Value.ToString(CultureInfo.InvariantCulture));
            appendQuery = appendQuery.AddParameterToQuery("segment_index", parameters.SegmentIndex.Value.ToString(CultureInfo.InvariantCulture));

            var formattedParameters = parameters.CustomRequestParameters.FormattedCustomQueryParameters;
            appendQuery += formattedParameters;

            return appendQuery;
        }
示例#4
0
        public bool Append(IChunkUploadAppendParameters parameters)
        {
            if (MediaId == null)
            {
                throw new InvalidOperationException("You cannot append content to a non initialized chunked upload. You need to invoke the initialize method OR set the MediaId property of an existing ChunkedUpload.");
            }

            if (parameters.SegmentIndex == null)
            {
                parameters.SegmentIndex = NextSegmentIndex;
            }

            if (parameters.MediaId == null)
            {
                parameters.MediaId = MediaId;
            }

            var appendQuery = _uploadQueryGenerator.GetChunkedUploadAppendQuery(parameters);

            var multiPartRequestParameters = new MultipartHttpRequestParameters
            {
                Query = appendQuery,
                Binaries = new List<byte[]> { parameters.Binary },
                Timeout = parameters.Timeout,
                ContentId = parameters.MediaType
            };

            var success = _twitterAccessor.TryExecuteMultipartQuery(multiPartRequestParameters);

            if (success)
            {
                UploadedSegments.Add(parameters.SegmentIndex.Value, parameters.Binary);
                ++NextSegmentIndex;
            }

            return success;
        }