Example #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 void Request_OnTranfering(object sender, YouTubeEventArgs args)
 {
     if (this.OnTranferingProgress != null)
     {
         this.OnTranferingProgress(sender, args);
     }
 }
Example #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void Request_OnExceptionCatched(object sender, YouTubeEventArgs args)
 {
     if (this.OnExceptionCatched != null)
     {
         strResponse = args.Message;
         this.OnExceptionCatched(sender, args);
     }
 }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="asynchronousResult"></param>
        private void ReadCallback(IAsyncResult asynchronousResult)
        {
            try
            {
                YouTubeWebRequest request = (YouTubeWebRequest)asynchronousResult.AsyncState;
                //Console.WriteLine("Working...");
                Stream ms = request.YouTubeRequest.EndGetRequestStream(asynchronousResult);

                int    bytesCount           = 0;
                Int64  bytesTotalTransfered = 0;
                Int64  bytesTotal           = request.POSTData.Length;
                byte[] bytes = new byte[2048];

                YouTubeEventArgs args = new YouTubeEventArgs();
                args.BytesTotal = bytesTotal;

                request.POSTData.Seek(0, SeekOrigin.Begin);

                while ((bytesCount = request.POSTData.Read(bytes, 0, bytes.Length)) > 0)
                {
                    ms.Write(bytes, 0, bytesCount);
                    bytesTotalTransfered += bytesCount;
                    args.BytesTransfered  = bytesTotalTransfered;
                    if (this.OnTranfering != null)
                    {
                        this.OnTranfering(this, args);
                    }
                }


                if (this.OnTransferComplete != null)
                {
                    args.Message = "SUCCESS UPLOAD";
                    this.OnTransferComplete(this, args);
                }

                request.YouTubeRequest.BeginGetResponse(ReadCallbackResponse, this);
                //Console.WriteLine("Done");
            }
            catch (Exception ex)
            {
                YouTubeEventArgs args = new YouTubeEventArgs();
                if (this.OnExceptionCatched != null)
                {
                    args.Message = ex.ToString();
                    this.OnExceptionCatched(this, args);
                }
            }
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="asynchronousResult"></param>
        private void ReadCallbackResponse(IAsyncResult asynchronousResult)
        {
            YouTubeWebRequest request = (YouTubeWebRequest)asynchronousResult.AsyncState;
            WebResponse       webResp = request.YouTubeRequest.EndGetResponse(asynchronousResult);
            String            message = "";

            try
            {
                using (StreamReader streamRd = new StreamReader(webResp.GetResponseStream()))
                {
                    message = streamRd.ReadToEnd();
                    //Console.WriteLine(message);
                }

                YouTubeEventArgs args = new YouTubeEventArgs();
                if (this.OnReceveResponseComplete != null)
                {
                    args.Message = message;
                    this.OnReceveResponseComplete(this, args);
                }
            }
            catch (WebException ex)
            {
                using (StreamReader streamRd = new StreamReader(ex.Response.GetResponseStream()))
                {
                    //Console.WriteLine("web exception\n" + streamRd.ReadToEnd());

                    if (this.OnExceptionCatched != null)
                    {
                        YouTubeEventArgs args = new YouTubeEventArgs();
                        args.Message = streamRd.ReadToEnd();
                        this.OnExceptionCatched(this, args);
                    }
                }
            }
        }
Example #5
0
 static void youTube_OnTranferingProgress(object sender, YouTubeEventArgs e)
 {
     Console.WriteLine("Transered: {0}", e.BytesTransfered);
 }
Example #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 void Request_OnReceveResponseComplete(object sender, YouTubeEventArgs args)
 {
     strResponse = args.Message;
     eventWaitResponse.Set();
 }
Example #7
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>        
 void Request_OnTranfering(object sender, YouTubeEventArgs args)
 {
     if (this.OnTranferingProgress != null)
     {
         this.OnTranferingProgress(sender, args);
     }
 }
Example #8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 void Request_OnReceveResponseComplete(object sender, YouTubeEventArgs args)
 {
     strResponse = args.Message;
     eventWaitResponse.Set();
 }
Example #9
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void Request_OnExceptionCatched(object sender, YouTubeEventArgs args)
 {
     if (this.OnExceptionCatched != null)
     {
         strResponse = args.Message;
         this.OnExceptionCatched(sender, args);
     }
 }
Example #10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="asynchronousResult"></param>
        private void ReadCallbackResponse(IAsyncResult asynchronousResult)
        {
            YouTubeWebRequest request = (YouTubeWebRequest)asynchronousResult.AsyncState;
            WebResponse webResp = request.YouTubeRequest.EndGetResponse(asynchronousResult);
            String message = "";
            try
            {
                using (StreamReader streamRd = new StreamReader(webResp.GetResponseStream()))
                {
                    message = streamRd.ReadToEnd();
                    //Console.WriteLine(message);
                }

                YouTubeEventArgs args = new YouTubeEventArgs();
                if (this.OnReceveResponseComplete != null)
                {
                    args.Message = message;
                    this.OnReceveResponseComplete(this, args);
                }
            }
            catch (WebException ex)
            {
                using (StreamReader streamRd = new StreamReader(ex.Response.GetResponseStream()))
                {
                    //Console.WriteLine("web exception\n" + streamRd.ReadToEnd());

                    if (this.OnExceptionCatched != null)
                    {
                        YouTubeEventArgs args = new YouTubeEventArgs();
                        args.Message = streamRd.ReadToEnd();
                        this.OnExceptionCatched(this, args);
                    }
                }
            }
        }
Example #11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="asynchronousResult"></param>
        private void ReadCallback(IAsyncResult asynchronousResult)
        {
            try
            {
                YouTubeWebRequest request = (YouTubeWebRequest)asynchronousResult.AsyncState;
                //Console.WriteLine("Working...");
                Stream ms = request.YouTubeRequest.EndGetRequestStream(asynchronousResult);

                int bytesCount = 0;
                Int64 bytesTotalTransfered = 0;
                Int64 bytesTotal = request.POSTData.Length;
                byte[] bytes = new byte[2048];

                YouTubeEventArgs args = new YouTubeEventArgs();
                args.BytesTotal = bytesTotal;

                request.POSTData.Seek(0, SeekOrigin.Begin);

                while ((bytesCount = request.POSTData.Read(bytes, 0, bytes.Length)) > 0)
                {
                    ms.Write(bytes, 0, bytesCount);
                    bytesTotalTransfered += bytesCount;
                    args.BytesTransfered = bytesTotalTransfered;
                    if (this.OnTranfering != null)
                    {
                        this.OnTranfering(this, args);
                    }
                }

                if (this.OnTransferComplete != null)
                {
                    args.Message = "SUCCESS UPLOAD";
                    this.OnTransferComplete(this, args);
                }

                request.YouTubeRequest.BeginGetResponse(ReadCallbackResponse, this);
                //Console.WriteLine("Done");
            }
            catch (Exception ex)
            {
                YouTubeEventArgs args = new YouTubeEventArgs();
                if (this.OnExceptionCatched != null)
                {
                    args.Message = ex.ToString();
                    this.OnExceptionCatched(this, args);
                }
            }
        }