An event arguments class that indicates that a task has ended.
Inheritance: System.EventArgs
		/// <summary>
		/// Handles the <see cref="IBackgroundTask.TaskEnded"/> event of the game discoverer.
		/// </summary>
		/// <remarks>
		/// If the game being searched for has not been found, this displays the not found UI.
		/// </remarks>
		/// <param name="sender">The object that raised the event.</param>
		/// <param name="e">A <see cref="TaskEndedEventArgs"/> describing the event arguments.</param>
		private void Detector_TaskEnded(object sender, TaskEndedEventArgs e)
		{
			if (InvokeRequired)
			{
				Invoke((Action<object, TaskEndedEventArgs>)Detector_TaskEnded, sender, e);
				return;
			}
			if (!Discoverer.IsFound(GameMode.ModeId) && !Discoverer.HasCandidates(GameMode.ModeId))
				SetVisiblePanel(pnlNotFound);
		}
		/// <summary>
		/// Raises the <see cref="IBackgroundTask.TaskEnded"/> event.
		/// </summary>
		/// <param name="e">A <see cref="TaskEndedEventArgs"/> describing the event arguments.</param>
		protected override void OnTaskEnded(TaskEndedEventArgs e)
		{
			if (m_lstFailedUpdaters.Count > 0)
			{
				StringBuilder stbMessage = new StringBuilder();
				stbMessage.AppendLine("The following updates failed:");
				for (Int32 i = 0; i < m_lstFailedUpdaters.Count; i++)
				{
					IUpdater updUpdater = m_lstFailedUpdaters[i];
					stbMessage.AppendFormat("{0}: {1}", updUpdater.Name, updUpdater.Message);
					if (i < m_lstFailedUpdaters.Count - 1)
						stbMessage.AppendLine();
				}
				base.OnTaskEnded(new TaskEndedEventArgs(e.Status, stbMessage.ToString(), e.ReturnValue));
			}
			else
				base.OnTaskEnded(e);
		}
		/// <summary>
		/// Raises the <see cref="IBackgroundTask.TaskEnded"/> event.
		/// </summary>
		/// <remarks>
		/// This signals the <see cref="StartWait(bool, object[])"/> method that the task has ended,
		/// and makes the return value accessible to said method.
		/// </remarks>
		/// <param name="e">A <see cref="TaskEndedEventArgs"/> describing the event arguments.</param>
		protected override void OnTaskEnded(TaskEndedEventArgs e)
		{
			m_areTaskEnded.Set();
			m_objReturnValue = e.ReturnValue;
			base.OnTaskEnded(e);
		}
		/// <summary>
		/// Raises the <see cref="IBackgroundTask.TaskEnded"/> event.
		/// </summary>
		/// <param name="e">A <see cref="TaskEndedEventArgs"/> describing the event arguments.</param>
		protected override void OnTaskEnded(TaskEndedEventArgs e)
		{
			base.OnTaskEnded(e);
		}
Esempio n. 5
0
		/// <summary>
		/// Handles the <see cref="IBackgroundTask.TaskEnded"/> event of the mod builder task.
		/// </summary>
		/// <param name="sender">The object that raised the event.</param>
		/// <param name="e">A <see cref="TaskEndedEventArgs"/> describing the event arguments.</param>
		private void ModBuilder_TaskEnded(object sender, TaskEndedEventArgs e)
		{
			m_lstRunningTasks.Remove((IBackgroundTask)sender);
			if (Status == TaskStatus.Running)
			{
				if (e.Status == TaskStatus.Complete)
					RegisterModFiles((IList<string>)e.ReturnValue);
				else
				{
					OverallMessage = String.Format("{0} can't be added.", GetModDisplayName());
					ItemMessage = e.Message;
					//if we errored while adding, let's set to imcomplete so as to not
					// loose the file we download - the user may wish to do somethinng manual
					Status = (e.Status == TaskStatus.Error) ? TaskStatus.Incomplete : e.Status;
					OnTaskEnded(e.Message, e.ReturnValue);
				}
			}
		}
Esempio n. 6
0
		/// <summary>
		/// Handles the <see cref="IBackgroundTask.TaskEnded"/> event of the file downloader tasks.
		/// </summary>
		/// <param name="sender">The object that raised the event.</param>
		/// <param name="e">A <see cref="TaskEndedEventArgs"/> describing the event arguments.</param>
		private void Downloader_TaskEnded(object sender, TaskEndedEventArgs e)
		{
			m_lstRunningTasks.Remove((IBackgroundTask)sender);
			if (e.Status == TaskStatus.Complete)
			{
				DownloadedFileInfo dfiDownloadInfo = (DownloadedFileInfo)e.ReturnValue;
				if (String.IsNullOrEmpty(Descriptor.SourcePath) && (Descriptor.DownloadFiles.IndexOf(dfiDownloadInfo.URL) == 0))
					Descriptor.SourcePath = dfiDownloadInfo.SavedFilePath;

				Descriptor.DownloadFiles.Clear();
				Descriptor.DownloadedFiles.Add(dfiDownloadInfo.SavedFilePath);

				KeyedSettings<AddModDescriptor> dicQueuedMods = m_eifEnvironmentInfo.Settings.QueuedModsToAdd[m_gmdGameMode.ModeId];
				dicQueuedMods[Descriptor.SourceUri.ToString()] = Descriptor;
				lock (m_eifEnvironmentInfo.Settings)
					m_eifEnvironmentInfo.Settings.Save();

				if (Descriptor.DownloadFiles.Count == 0)
				{
					StepOverallProgress();
					AddModFile(m_cocConfirmOverwrite);
				}
			}
			else if (IsActive)
			{
				if ((FileDownloadTask)sender != null)
				{
					ErrorCode = ((FileDownloadTask)sender).ErrorCode;
					ErrorInfo = ((FileDownloadTask)sender).ErrorInfo;
				}

				Status = e.Status;
				OverallMessage = e.Message;
				OnTaskEnded(e.Message, e.ReturnValue);
			}
			else if ((e.Status == TaskStatus.Paused) || (e.Status == TaskStatus.Queued))
			{
				string[] TempFiles = (string[])e.ReturnValue;
				Descriptor.PausedFiles.AddRange(TempFiles);
			}

			if (swtSpeed.IsRunning)
				swtSpeed.Stop();
		}
Esempio n. 7
0
		/// <summary>
		/// Raises the <see cref="IBackgroundTask.TaskEnded"/> event.
		/// </summary>
		/// <remarks>
		/// This removes the task state from storage if it failed.
		/// </remarks>
		/// <param name="e">A <see cref="TaskEndedEventArgs"/> describing the event's arguments.</param>
		protected override void OnTaskEnded(TaskEndedEventArgs e)
		{
			if ((e.Status != TaskStatus.Paused) && (e.Status != TaskStatus.Incomplete) && (e.Status != TaskStatus.Queued) && (Descriptor != null))
			{
				if ((e.Status != TaskStatus.Paused) && (e.Status != TaskStatus.Incomplete) && (e.Status != TaskStatus.Queued))
					lock (m_dctSourceUri)
						if (m_dctSourceUri.ContainsKey(Descriptor.SourceUri.ToString()) && (m_dctSourceUri[Descriptor.SourceUri.ToString()] == m_intLocalID))
							m_dctSourceUri.Remove(Descriptor.SourceUri.ToString());

				foreach (string strFile in Descriptor.DownloadedFiles)
					if (strFile.StartsWith(m_gmdGameMode.GameModeEnvironmentInfo.ModDownloadCacheDirectory, StringComparison.OrdinalIgnoreCase))
						FileUtil.ForceDelete(strFile);
				if (e.Status == TaskStatus.Cancelled)
				{
					if (Descriptor != null)
					{
						if (Descriptor.PausedFiles.Count > 0)
						{
							foreach (string strFile in Descriptor.PausedFiles)
								if (strFile.StartsWith(m_gmdGameMode.GameModeEnvironmentInfo.ModDownloadCacheDirectory, StringComparison.OrdinalIgnoreCase))
								{
									FileUtil.ForceDelete(strFile);
								}
							Descriptor.PausedFiles.Clear();
						}
						else
						{
							if (!String.IsNullOrEmpty(Descriptor.DefaultSourcePath))
							{
								if (File.Exists(Descriptor.DefaultSourcePath + ".parts"))
									FileUtil.ForceDelete(Descriptor.DefaultSourcePath + ".parts");
								if (File.Exists(Descriptor.DefaultSourcePath + ".partial"))
									FileUtil.ForceDelete(Descriptor.DefaultSourcePath + ".partial");
							}
						}
					}
				}
				KeyedSettings<AddModDescriptor> dicQueuedMods = m_eifEnvironmentInfo.Settings.QueuedModsToAdd[m_gmdGameMode.ModeId];
				dicQueuedMods.Remove(Descriptor.SourceUri.ToString());
				lock (m_eifEnvironmentInfo.Settings)
					m_eifEnvironmentInfo.Settings.Save();
			}
			base.OnTaskEnded(e);
		}
		/// <summary>
		/// Handles the <see cref="IBackgroundTask.TaskEnded"/> event of a task set.
		/// </summary>
		/// <remarks>
		/// This displays the confirmation message.
		/// </remarks>
		/// <param name="sender">The object that raised the event.</param>
		/// <param name="e">A <see cref="TaskSetCompletedEventArgs"/> describing the event arguments.</param>
		private void RunningTask_TaskEnded(object sender, TaskEndedEventArgs e)
		{
			if (RunningTask != null)
			{
				lock (m_objLock)
				{
					if (RunningTask != null)
					{
						RunningTask.TaskEnded -= RunningTask_TaskEnded;
						int intPosition = TaskList.IndexOf((WriteLoadOrderTask)RunningTask);
						RunningTask = null;
						TaskList.RemoveAt(intPosition);
					}
				}
			}
		}
			/// <summary>
			/// Handles the <see cref="IBackgroundTask.TaskEnded"/> event of the mod adding task.
			/// </summary>
			/// <remarks>
			/// This retrieves the paths of the added mods.
			/// </remarks>
			/// <param name="sender">The object that raised the event.</param>
			/// <param name="e">A <see cref="TaskEndedEventArgs"/> describing the event arguments.</param>
			private void ModAdder_TaskEnded(object sender, TaskEndedEventArgs e)
			{
				if ((e.Status != TaskStatus.Paused) && (e.Status != TaskStatus.Queued))
				{
					lock (m_dicActiveTasks)
					{
						Uri uriKey = (from k in m_dicActiveTasks
									  where (k.Value == sender)
									  select k.Key).FirstOrDefault();
						if (uriKey != null)
							m_dicActiveTasks.Remove(uriKey);
						if(m_dicActiveTasks.Count > 0)
							ResumeQueued();
					}
				}
			}
Esempio n. 10
0
		/// <summary>
		/// Raises the <see cref="IBackgroundTask.TaskEnded"/> event.
		/// </summary>
		/// <remarks>
		/// This raises the <see cref="GameResolved"/> event for any games that were not found.
		/// </remarks>
		/// <param name="e">The <see cref="TaskEndedEventArgs"/> describing the event arguments.</param>
		protected override void OnTaskEnded(TaskEndedEventArgs e)
		{
			base.OnTaskEnded(e);
			string[] strModeIds = new string[m_dicCandidatePathsByGame.Count];
			m_dicCandidatePathsByGame.Keys.CopyTo(strModeIds, 0);
			foreach (string strModeId in strModeIds)
				if (m_dicCandidatePathsByGame[strModeId].Count == 0)
					OnGameResolved(m_dicGameModesById[strModeId], null);
		}
		/// <summary>
		/// Handles the <see cref="IBackgroundTask.TaskEnded"/> event of tasks run during initialization.
		/// </summary>
		/// <remarks>
		/// This signals the wait handle that is blocking the initialization thread, allowing it to continue
		/// with the initialization.
		/// </remarks>
		/// <param name="sender">The object that raised the event.</param>
		/// <param name="e">A <see cref="TaskEndedEventArgs"/> describing the event arguments.</param>
		private void Task_TaskEnded(object sender, TaskEndedEventArgs e)
		{
			m_areTaskWait.Set();
		}
		/// <summary>
		/// Handles the <see cref="IBackgroundTask.TaskEnded"/> event of the task.
		/// </summary>
		/// <remarks>
		/// This sets the <see cref="Form.DialogResult"/>, dependant upon whether or not the
		/// task was cancelled.
		/// </remarks>
		/// <param name="sender">The object that triggered the event.</param>
		/// <param name="e">A <see cref="TaskEndedEventArgs"/> that describes the event arguments.</param>
		private void Task_TaskEnded(object sender, TaskEndedEventArgs e)
		{
			m_tmrGlow.Stop();
			if (Disposing || IsDisposed)
				return;
			try
			{
				//if the form hasn't been created, there is no point in updating
				// the UI
				//further, if the form handle hasn't been created, there is no way
				// to safely update the form from another thread
				if (IsHandleCreated)
				{

					if (InvokeRequired)
					{
						Invoke((Action<object, TaskEndedEventArgs>)Task_TaskEnded, sender, e);
						return;
					}
					else if ((Owner != null) && Owner.InvokeRequired)
					{
						Owner.Invoke((Action<object, TaskEndedEventArgs>)Task_TaskEnded, sender, e);
						return;
					}
				}
			}
			catch (ObjectDisposedException)
			{
				//if the control is disposed, we don't need to do anything
				return;
			}

			if (e.Status == TaskStatus.Complete)
				DialogResult = DialogResult.OK;
			else
				DialogResult = DialogResult.Cancel;
			m_drtLastDialogResult = DialogResult;
			if (e.ReturnValue != null)
				ShowMessage((ViewMessage)e.ReturnValue);
			else if (!String.IsNullOrEmpty(e.Message))
				MessageBox.Show(this, e.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
			//only try to close the form if it has been created
			// otherwise Close() can get called before the form is shown,
			// and then once Show() or ShowDialog() is called an
			// System.ObjectDisposedException is thrown
			if (IsHandleCreated)
			{
				for (Int32 i = 0; i < 10; i++)
				{
					try
					{
						this.Close();
						break;
					}
					catch (InvalidOperationException)
					{
						//we are trying to close the form at the exact moment it is being shown
						// wait a moment and try again
						Thread.Sleep(100);
					}
				}
			}
		}