Example #1
0
        // when an upload is completed successfully we parse the return stream
        // to setup the videoid.
        // also all retry counts will be reset to 0, as a successful upload incidates
        // a restored network condition (e.g.).
        private void ParseAndFinish(UserState u, Stream s)
        {
            YouTubeRequestSettings ys = new YouTubeRequestSettings(YouTubeUploader.ApplicationName,
                                                                   this.developerKey);
            YouTubeRequest ytr = new YouTubeRequest(ys);
            Video          v   = ytr.ParseVideo(s);

            Trace.TraceInformation("Upload successful");
            u.Row.Cells[COLUMNINDEX_STATUS].Value  = "Upload successful";
            u.Row.Cells[COLUMNINDEX_STATUS].Tag    = u;
            u.Row.Cells[COLUMNINDEX_VIDEOID].Value = v.VideoId;
            // we had one successful upload, reset the retry counts to 0
            lock (this.flag) {
                foreach (UserState us in retryQueue)
                {
                    us.RetryCounter = 0;
                }
            }
        }
Example #2
0
        // when an upload is completed successfully we parse the return stream
        // to setup the videoid.
        // also all retry counts will be reset to 0, as a successful upload incidates
        // a restored network condition (e.g.).
        private void ParseAndFinish(UserState u, Stream s) {
            YouTubeRequestSettings ys = new YouTubeRequestSettings(YouTubeUploader.ApplicationName,
                this.developerKey);
            YouTubeRequest ytr = new YouTubeRequest(ys);
            Video v = ytr.ParseVideo(s);

            Trace.TraceInformation("Upload successful");
            u.Row.Cells[COLUMNINDEX_STATUS].Value = "Upload successful";
            u.Row.Cells[COLUMNINDEX_STATUS].Tag = u;
            u.Row.Cells[COLUMNINDEX_VIDEOID].Value = v.VideoId;
            // we had one successful upload, reset the retry counts to 0
            lock (this.flag) {
                foreach (UserState us in retryQueue) {
                    us.RetryCounter = 0;
                }
            }
        }
		protected void OnResumableUploaderAsyncOperationCompleted(object sender, AsyncOperationCompletedEventArgs e)
		{
			var executeYouTubeUploaderWorkflowMessage = (IExecuteYouTubeUploaderWorkflowMessage)e.UserState;

			YouTubeUploaderService.Uploaders.Remove(executeYouTubeUploaderWorkflowMessage);

			if (e.Error != null)
			{
				if (e.Error is WebException)
				{
					var webException = (WebException) e.Error;
					var response = webException.Response;
					var responseBody = string.Empty;

					if (response != null)
					{
						if (response.ContentLength > 0)
						{
							using (var stream = response.GetResponseStream())
							{
								using (var reader = new StreamReader(stream))
								{
									responseBody = reader.ReadToEnd().Trim();
								}
							}
						}
					}
				}
			}

			var videoId = string.Empty;

			if (!e.Cancelled && e.Error == null)
			{
				var youTubeRequestSettings = new YouTubeRequestSettings(executeYouTubeUploaderWorkflowMessage.Settings.Authentication.ApplicationName, executeYouTubeUploaderWorkflowMessage.Settings.Authentication.DeveloperKey);
				var youTubeRequest = new YouTubeRequest(youTubeRequestSettings);
				var video = youTubeRequest.ParseVideo(e.ResponseStream);
				videoId = video.VideoId;
			}

			var executedYouTubeUploaderWorkflowMessage = new ExecutedYouTubeUploaderWorkflowMessage()
			{
				CorrelationId = executeYouTubeUploaderWorkflowMessage.CorrelationId,
				Cancelled = e.Cancelled,
				Error = e.Error,
				VideoId = videoId
			};

			var bus = BusDriver.Instance.GetBus(YouTubeUploaderService.BusName);
			bus.Publish(executedYouTubeUploaderWorkflowMessage);
		}