Пример #1
0
        public void CancelPublish()
        {
            Cancel();

            try
            {
                if (_stream != null)
                {
                    _stream.Cancel();
                    _stream.Dispose();
                    _stream = null;
                }
            }
            catch (NullReferenceException)
            {
            }

            if (!string.IsNullOrEmpty(_updateUrl))
            {
                HttpWebRequest req = HttpRequestHelper.CreateHttpWebRequest(_updateUrl, true, -1, -1);
                YouTubeUploadRequestHelper.AddSimpleHeader(req, _authToken);
                req.Method = "DELETE";
                req.GetResponse().Close();
            }
        }
Пример #2
0
 internal void SendRequest(CancelableStream stream)
 {
     _request.ContentLength             = _requestBodyTop.Length + stream.Length + _requestBodyBottom.Length;
     _request.AllowWriteStreamBuffering = false;
     _requestStream = _request.GetRequestStream();
     _requestStream.Write(_requestBodyTop.ToArray(), 0, (int)_requestBodyTop.Length);
     StreamHelper.Transfer(stream, _requestStream, 8192, true);
     _requestStream.Write(_requestBodyBottom.ToArray(), 0, (int)_requestBodyBottom.Length);
     _requestStream.Close();
 }
Пример #3
0
            public HttpWebRequest Create(string uri)
            {
                HttpWebRequest req = HttpRequestHelper.CreateHttpWebRequest(uri, true);

                _multipartMimeRequestHelper.Init(req);

                if (_filter != null)
                {
                    _filter(req);
                }

                _multipartMimeRequestHelper.Open();
                _multipartMimeRequestHelper.AddXmlRequest(_xmlDoc);
                _multipartMimeRequestHelper.AddFile(_filename);
                _multipartMimeRequestHelper.Close();

                using (CancelableStream stream = new CancelableStream(new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read)))
                {
                    return(_multipartMimeRequestHelper.SendRequest(stream));
                }
            }
Пример #4
0
        private string Upload()
        {
            HttpWebRequest req = HttpRequestHelper.CreateHttpWebRequest("http://uploads.gdata.youtube.com/feeds/api/users/default/uploads", true, -1, -1);

            YouTubeUploadRequestHelper uploader = new YouTubeUploadRequestHelper(req);

            uploader.AddHeader(_authToken, Path.GetFileName(Path.GetFileName(_filePath)));
            uploader.Open();
            uploader.AddXmlRequest(_title, _description, _tags, _categoryId, _permissionValue);
            uploader.AddFile(_filePath);
            uploader.Close();

            try
            {
                using (_stream = new CancelableStream(new FileStream(_filePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
                {
                    uploader.SendRequest(_stream);
                }
            }
            finally
            {
                _stream = null;
            }



            string result;

            using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
            {
                using (StreamReader responseReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                {
                    result = responseReader.ReadToEnd();
                }
            }


            return(result);
        }
            public HttpWebRequest Create(string uri)
            {
                // TODO: ETag support required??
                // TODO: choose rational timeout values
                HttpWebRequest request = HttpRequestHelper.CreateHttpWebRequest(uri, false);

                request.ContentType = MimeHelper.GetContentType(Path.GetExtension(_filename));
                if (_parent._options != null && _parent._options.SupportsSlug)
                {
                    request.Headers.Add("Slug", Path.GetFileNameWithoutExtension(_filename));
                }

                request.Method = _method;

                request.AllowWriteStreamBuffering = _allowWriteStreamBuffering;

                if (_etag != null && _etag.Length != 0)
                {
                    request.Headers.Add("If-match", _etag);
                }

                _parent._requestFilter(request);

                using (Stream inS = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    using (CancelableStream cs = new CancelableStream(inS))
                    {
                        request.ContentLength = cs.Length;
                        using (Stream s = request.GetRequestStream())
                        {
                            StreamHelper.Transfer(cs, s);
                        }
                    }
                }

                return(request);
            }