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);
		}
		protected void OnResumableUploaderAsyncOperationCompleted(object sender, AsyncOperationCompletedEventArgs e)
		{
			var executePicasaUploaderWorkflowMessage = (IExecutePicasaUploaderWorkflowMessage)e.UserState;

			PicasaUploaderService.Uploaders.Remove(executePicasaUploaderWorkflowMessage);

			if (e.Error != null)
			{
				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 executedPicasaUploaderWorkflowMessage = new ExecutedPicasaUploaderWorkflowMessage()
			{
				CorrelationId = executePicasaUploaderWorkflowMessage.CorrelationId,
				Cancelled = e.Cancelled,
				Error = e.Error
			};

			var bus = BusDriver.Instance.GetBus(PicasaUploaderService.BusName);
			bus.Publish(executedPicasaUploaderWorkflowMessage);
		}
Esempio n. 3
0
 private static void OnSpreadsheetUploadDone(object in_sender, AsyncOperationCompletedEventArgs in_e)
 {
     Instance.InstanceData.Commands.Remove(GFCommand.WaitingForUpload);
     Instance.InstanceData.Commands.Add(GFCommand.UploadComplete);
 }
Esempio n. 4
0
        private void OnDone(object sender, AsyncOperationCompletedEventArgs e)
        {
            UserState ut = e.UserState as UserState;

            if (this.states.Contains(ut) == false)
                return;

            this.states.Remove(ut);
        
            if (e.Error == null && e.Cancelled == false)
            {

                if (ut.opType == UserState.OperationType.query ||
                    ut.opType == UserState.OperationType.queryForBackup)
                {
                    if (e.Feed != null)
                    {
                        this.photoFeed = e.Feed as PicasaFeed;
                        this.InitializeList(ut.filename);
                    }
                }

                if (ut.opType == UserState.OperationType.upload)
                {
                    if (e.Entry != null)
                    {
                        ListViewItem item = new ListViewItem(e.Entry.Title.Text);
                        item.Tag = e.Entry;
                        this.PhotoList.Items.Add(item);
                        this.FileInfo.Text = "Upload succeeded";
                    }
                }
                if (ut.opType == UserState.OperationType.download ||
                    ut.opType == UserState.OperationType.downloadList)
                {
                    if (e.ResponseStream != null)
                    {
                        WriteFile(ut.filename, e.ResponseStream);
                        this.FileInfo.Text = "Saved file: " + ut.filename;
                    }
                }
                if (ut.opType == UserState.OperationType.downloadList)
                {
                    // we need to create a new object for uniqueness

                    UserState u = new UserState();
                    u.counter = ut.counter + 1;
                    u.feed = ut.feed;
                    u.foldername = ut.foldername;
                    u.opType = UserState.OperationType.downloadList;
                    
                    if (u.feed.Entries.Count > 0)
                    {
                        u.feed.Entries.RemoveAt(0);
                        this.PhotoList.Items.RemoveAt(0);

                    }
                    this.states.Add(u);
                    SaveAnotherPictureDelegate d = new SaveAnotherPictureDelegate(this.CreateAnotherSaveFile);

                    this.BeginInvoke(d, u);

                }
                if (ut.opType == UserState.OperationType.queryForBackup)
                {
                    UserState u = new UserState();
                    u.opType = UserState.OperationType.downloadList;
                    u.feed = this.photoFeed;
                    u.counter = 1;
                    u.foldername = ut.foldername;
                    u.filename = ut.foldername + "\\image1.jpg";
                    this.states.Add(u);
                    SaveAnotherPictureDelegate d = new SaveAnotherPictureDelegate(this.CreateAnotherSaveFile);
                    this.BeginInvoke(d, u);
                }
            }
            this.progressBar.Value = 0;

            if (this.states.Count == 0)
            {
                this.CancelAsync.Enabled = false;
                this.CancelAsync.Visible = false;
            }

        }
Esempio n. 5
0
 private void OnGoogleNoteUpdated(object sender, AsyncOperationCompletedEventArgs e)
 {
     MoveGoogleNote(e.Entry as DocumentEntry, e.UserState as NoteMatch, false, e.Error, e.Cancelled);
 }
Esempio n. 6
0
        // This is the method that the underlying, free-threaded 
        // asynchronous behavior will invoke.  This will happen on
        // an arbitrary thread.
        private void OnAsyncCompletionMethod(object operationState) {
            AsyncData data = operationState as AsyncData;
            AsyncOperation asyncOp = data.Operation;
            AsyncOperationCompletedEventArgs args = new AsyncOperationCompletedEventArgs(data);

            // In this case, don't allow cancellation, as the method 
            // is about to raise the completed event.
            lock (this.userStateToLifetime.SyncRoot) {
                if (!userStateToLifetime.Contains(data.UserData)) {
                    asyncOp = null;
                } else {
                    this.userStateToLifetime.Remove(asyncOp.UserSuppliedState);
                }
            }

            // The asyncOp object is responsible for marshaling 
            // the call.
            if (asyncOp != null) {
                asyncOp.PostOperationCompleted(this.onCompletedDelegate, args);
            }

            // Note that after the call to OperationCompleted, 
            // asyncOp is no longer usable, and any attempt to use it
            // will cause an exception to be thrown.
        }
Esempio n. 7
0
        /// <summary>
        /// this method cancels the corresponding async operation. 
        /// It sends still a completed event, but that event will then
        /// have the cancel property set to true
        /// </summary>
        /// <param name="userData">your identifier for the operation to be cancelled</param>
        public void CancelAsync(object userData) {
            lock (this.userStateToLifetime.SyncRoot) {
                object obj = this.userStateToLifetime[userData];
                if (obj != null) {
                    this.userStateToLifetime.Remove(userData);

                    AsyncOperation asyncOp = obj as AsyncOperation;
                    // The asyncOp object is responsible for 
                    // marshaling the call to the proper 
                    // thread or context.

                    AsyncData data = new AsyncData(null, userData, this.onProgressReportDelegate);
                    AsyncOperationCompletedEventArgs args = new AsyncOperationCompletedEventArgs(data, true);

                    asyncOp.PostOperationCompleted(this.onCompletedDelegate, args);
                }
            }
        }
Esempio n. 8
0
        // send when an upload is done. This can mean it completed, it failed
        // or it was cancelled
        private void OnDone(object sender, AsyncOperationCompletedEventArgs e) {
            if (e != null) {
                UserState u = e.UserState as UserState;

                Trace.TraceInformation("OnDone - Upload finished for :" + u.ResumeUri);
                Trace.Indent();

                if (u != null && u.Row != null) {
                    if (e.Cancelled) {
                        Trace.TraceInformation("Cancelled. Current Pos = " + u.CurrentPosition);
                        u.Row.Cells[COLUMNINDEX_STATUS].Value = "Operation was cancelled";
                        // if it was cancelled, reset the retry counter
                        u.RetryCounter = 0;
                        u.Row.Cells[COLUMNINDEX_STATUS].Tag = u;
                        AddToRetryQueue(u);
                    } else if (e.Error != null) {
                        Trace.TraceInformation("Error. Current Pos = " + u.CurrentPosition);
                        Trace.TraceInformation("Error was: " + e.Error.ToString() + " - " + e.Error.Message);
                        u.Error = e.Error.Message;
                        u.Row.Cells[COLUMNINDEX_STATUS].Value = e.Error.Message;
                        u.Row.Cells[COLUMNINDEX_STATUS].Value = "Tried (" + u.RetryCounter + ") - Last error was: " + u.Error;
                        u.Row.Cells[COLUMNINDEX_STATUS].Tag = u;
                        TryARetry(u);
                    } else {
                        ParseAndFinish(u, e.ResponseStream);
                    }
                }

                RemoveFromProcessingQueue(u);

                // only add new ones, if we did not have a cancellation
                if (!e.Cancelled) {
                    // now add a new row, if there is one
                    // this will go over all rows and tries to upload them
                    foreach (DataGridViewRow row in this.csvDisplayGrid.Rows) {
                        if (UploadRow(row)) {
                            break;
                        }
                    }
                }

                Trace.Unindent();
            }

            if (Finished()) {
                ToggleButtons(true);

                if (this.autoStart && this.outputFileName != null) {
                    SaveGridAsCSV(outputFileName);
                }
            }
            SetTitle();
        }
 private void Service_AsyncOperationCompleted(object sender, AsyncOperationCompletedEventArgs e)
 {
     AsyncOperationCompleted(sender, e);
 }
        void Upload_AsyncOperationCompleted(object sender, AsyncOperationCompletedEventArgs e)
        {
            //(e.Entry as YouTubeEntry).VideoId;
            if (!String.IsNullOrEmpty((e.Entry as YouTubeEntry).VideoId))
            {
                button1.IsEnabled = true;
                var procstatus = (e.Entry as YouTubeEntry).State.Name; //Processing - use later
                var actstatus = (e.Entry as YouTubeEntry).State.Value; //Actual status - use later
                var name = textBox1.Text; //Filename
                listVideosView.IsEnabled = true;

                StoredVariables.SetFilename(name);
                StoredVariables.SetYoutube_ID( (e.Entry as YouTubeEntry).VideoId );
                StoredVariables.SetYoutube_Status((e.Entry as YouTubeEntry).State.Value);

                var VideoList = new VideoWatcher(StoredVariables.IncludeDirectory);
                VideoList.Refresh(listVideosView);
            }
        }
Esempio n. 11
0
        /*
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
        TryLoginLabel:              //Ask user to re-submit invalid credentials until success or cancel.
            if (retryLogin)
            {
                try
                {   ///*
                    ((GDataRequestFactory)request.Service.RequestFactory).KeepAlive = true;
                    ((GDataRequestFactory)request.Service.RequestFactory).Timeout = 9999999;
                    Task.Factory.StartNew(() => { backgroundWorker1.ReportProgress(1); });
                    newVideo = request.Upload(newVideo);
                    //
                }

                catch (InvalidCredentialsException c)
                {
                    Console.WriteLine(c);
                    LoginForm LoginForm = new LoginForm();
                    LoginForm.ShowDialog();

                    goto TryLoginLabel;
                }
                catch (AccountDisabledException c)
                {
                    Console.WriteLine(c);
                    LoginForm LoginForm = new LoginForm();
                    LoginForm.ShowDialog();

                    goto TryLoginLabel;
                }
            }

        } */
        //Kept for reference.
        void Service_AsyncOperationCompleted(object sender, AsyncOperationCompletedEventArgs e)
        {
            request.Service.AsyncOperationCompleted -= new AsyncOperationCompletedEventHandler(Service_AsyncOperationCompleted); //Event is firing twice. Fix later.
            debugBox.Text = "100";
            newVideo.VideoId = ((Google.GData.YouTube.YouTubeEntry)(e.Entry)).VideoId;
            if (!String.IsNullOrEmpty(newVideo.VideoId)  ) //Got a valid URL back.
            {
                VideoID = newVideo.VideoId;

                textComplete.Visible = true;
                buttonUpload.Enabled = false;

                VideoId.Add(VideoID);
                VideoStatus.Add("Uploaded");
                VideoFilename.Add(listVideosView.FocusedItem.Text);

                drawVideoList();
            }
        }
Esempio n. 12
0
        private void OnGoogleNoteUpdated(object sender, AsyncOperationCompletedEventArgs e)
        {
            DocumentEntry entry = e.Entry as DocumentEntry;

            Assert.IsNotNull(entry);

            Logger.Log("Updated Google note", EventType.Information);

            System.IO.File.Delete(e.UserState as string);
        }
Esempio n. 13
0
        private void OnGoogleNoteCreated(object sender, AsyncOperationCompletedEventArgs e)
        {
            DocumentEntry entry = e.Entry as DocumentEntry;

            Assert.IsNotNull(entry);

            Logger.Log("Created Google note", EventType.Information);

            //Now update the same entry
            //Instantiate the ResumableUploader component.
            ResumableUploader uploader = new ResumableUploader();
            uploader.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(OnGoogleNoteUpdated);
            uploader.UpdateAsync(_authenticator, entry, e.UserState);
        }
Esempio n. 14
0
        void service_AsyncOperationCompleted(object sender, AsyncOperationCompletedEventArgs e)
        {
            dynamic r = e.UserState;

            int a = r.SiteID;
            AsyncManager am = r.AM;
            am.OutstandingOperations.Decrement();

            //e.
            //throw new NotImplementedException();
        }