Example #1
0
		private void DoTask(ISkyDoxUploadTask task, JobStage nextStage, bool saveStatus, CancellationToken token, string defaultErrorMessage)
		{
			if (!ShouldDoWork())
			{
				return;
			}

			Exception exception = null;
			if (task != null)
			{
				try
				{
					token.ThrowIfCancellationRequested();
					task.Run();
				}
				catch (OperationCanceledException)
				{
				    Caption = Resources.SkyDoxUploadJob_Stop_Paused;
					JobStatus = JobStatus.Paused;
					return;
				}
				catch (InvalidResponseException ex)
				{
					Logger.LogError(ex);
					exception = ex;
				}
				catch (WebException ex)
				{
					LogWebException(ex);
					Logger.LogError(ex);
					exception = ex;
				}
				catch( IOException ex)
				{
					Logger.LogError(ex);
					exception = ex;
				}
				catch (Exception ex)
				{
					JobStatus = JobStatus.Failed;
					Logger.LogError("Caught unhandled exception");
					Logger.LogError(ex);
					throw;
				}

				if (!task.Succeeded)
				{
					_errors++;
                    if (task.PendingUserActivation)
                    {
                        Caption = Resources.SkyDoxUploadJob_DoTask_Waiting_for_account_authentication__Please_check_your_email_;
                        JobStatus = JobStatus.Authenticating;
                    }
					else if (!task.ShouldRetry || _errors >= 3)
					{
                        JobStatus = JobStatus.Failed;
						string message = !string.IsNullOrEmpty(task.ErrorMessage) ? task.ErrorMessage : defaultErrorMessage;
                        HandleError(message, exception);
					}
					return;
				}
			}

			if (saveStatus)
			{
				_jobInfo.CurrentStage = nextStage;
				JobInfo.WriteJobInfo(_jobInfo, _jobXmlPath);
				JobInfo.WriteJobInfo(_jobInfo, _jobBackupXmlPath);
			}

			if (OnJobStageChanged != null)
			{
				OnJobStageChanged(this, EventArgs.Empty);
			}
		}
		private void DoTask(ISkyDoxUploadTask task, UploadInfo uploadInfo, AttachmentStage nextStage, CancellationToken token, bool writeToFile)
		{
			if (!_shouldWork)
			{
				return;
			}

			if (task != null)
			{
				try
				{
					token.ThrowIfCancellationRequested();
					task.Run();
				}
				catch (OperationCanceledException)
				{
					_shouldWork = false;
					uploadInfo.Status = AttachmentStatus.Pending;
					throw;
				}
				catch (Exception)
				{
					_shouldWork = false;
					uploadInfo.Status = AttachmentStatus.Failed;
					throw;
				}

				ErrorMessage = task.ErrorMessage;
				if (!task.Succeeded)
				{
					Succeeded = false;
					_shouldWork = false;
					ShouldRetry = task.ShouldRetry;
					return;
				}
			}
			uploadInfo.Stage = nextStage;
			if (task != null && writeToFile)
			{
				_progressReporter.WriteToFile();
			}
		}