/// <summary>
 /// Pauses a task.
 /// </summary>
 /// <param name="p_tskTask">The task to pause.</param>
 public void PauseActivity(IBackgroundTask p_tskTask)
 {
     if (CanPause(p_tskTask))
     {
         p_tskTask.Pause();
     }
 }
 /// <summary>
 /// Resumes a task.
 /// </summary>
 /// <param name="p_tskTask">The task to resume.</param>
 public void ResumeActivity(IBackgroundTask p_tskTask)
 {
     if (CanResume(p_tskTask))
     {
         p_tskTask.Resume();
     }
 }
 /// <summary>
 /// Pauses a task.
 /// </summary>
 /// <param name="p_tskTask">The task to pause.</param>
 public void QueueDownload(IBackgroundTask p_tskTask)
 {
     if (CanQueue(p_tskTask))
     {
         p_tskTask.Queue();
     }
 }
Exemple #4
0
 public TraductorActiveMQController(IConfiguration configuration, IBackgroundTask backgroundTask)
 {
     _configuration             = configuration;
     _controlMensajeriaActiveMQ = new ControlMensajeriaActiveMQ(configuration);
     _dispositivo    = new Dispositivo(configuration);
     _backgroundTask = backgroundTask;
 }
Exemple #5
0
 /// <summary>
 /// Puases the given task.
 /// </summary>
 /// <param name="p_tskTask">The task to pause.</param>
 public void QueueTask(IBackgroundTask p_tskTask)
 {
     if (DownloadMonitor.CanQueue(p_tskTask))
     {
         DownloadMonitor.QueueDownload(p_tskTask);
     }
 }
        /// <summary>
        /// Queues the page view.
        /// </summary>
        /// <param name="task">The task.</param>
        public static void Add(IBackgroundTask task)
        {
            lock (TaskManagerLockObject)
            {
                if (_currentBackgroundTaskBatch == null)
                {
                    _currentBackgroundTaskBatch = new BackgroundTaskBatch();
                }
                _currentBackgroundTaskBatch.Add(task);

                if (_currentBackgroundTaskBatch.Count >= BatchSize)
                {
                    var tasks = _currentBackgroundTaskBatch.GetTasks();
                    ThreadPool.QueueUserWorkItem(callback =>
                    {
                        if(_processor == null) return;

                        foreach (var item in tasks)
                        {
                            _processor.Process(item);
                        }
                    });

                    _currentBackgroundTaskBatch = null;
                }
            }
        }
 /// <summary>
 /// Resumes the given task.
 /// </summary>
 /// <param name="p_tskTask">The task to resume.</param>
 public void ResumeTask(IBackgroundTask p_tskTask)
 {
     if (ActivityMonitor.CanResume(p_tskTask))
     {
         ActivityMonitor.ResumeActivity(p_tskTask);
     }
 }
Exemple #8
0
 /// <summary>
 /// Puases the given task.
 /// </summary>
 /// <param name="p_tskTask">The task to pause.</param>
 public void PauseTask(IBackgroundTask p_tskTask)
 {
     if (DownloadMonitor.CanPause(p_tskTask))
     {
         DownloadMonitor.PauseDownload(p_tskTask);
     }
 }
 /// <summary>
 /// Puases the given task.
 /// </summary>
 /// <param name="p_tskTask">The task to pause.</param>
 public void PauseTask(IBackgroundTask p_tskTask)
 {
     if (ActivityMonitor.CanPause(p_tskTask))
     {
         ActivityMonitor.PauseActivity(p_tskTask);
     }
 }
Exemple #10
0
 private void ProcessImportAlternateIngredientUpdate(IBackgroundTask task, bool forceRecalculation)
 {
     ExecuteStoredProc(_connectionString, "import_api_alternate_ingredient_update",
                       new SqlParameter("@product_id", task.ProductId),
                       new SqlParameter("@user_id", task.UserId),
                       new SqlParameter("@force_recalculation", Convert.ToInt16(forceRecalculation)));
 }
Exemple #11
0
 private void ProcessAlternateIngredientUpdate(IBackgroundTask task)
 {
     ExecuteStoredProc(_connectionString, "sc_alternate_ingredient_update", new SqlParameter[] {
         new SqlParameter("@product_id", task.ProductId),
         new SqlParameter("@user_id", task.UserId)
     });
 }
 /// <summary>
 /// Start the task in a new thread
 /// </summary>
 /// <param name="dispatcher"></param>
 public void StartNew(IBackgroundTask <StorageContext> dispatcher)
 {
     Task.Factory.StartNew(() => dispatcher.Execute(_context),
                           CancellationToken.None,
                           TaskCreationOptions.None,
                           TaskScheduler.Default);
 }
Exemple #13
0
 private void OnBackgroundTaskCompleted(IBackgroundTask arg1, object arg2)
 {
     _progressBar.Visible   = false;
     _progressLabel.Visible = false;
     _progressBar.Style     = ProgressBarStyle.Blocks;
     _progressLabel.Text    = null;
 }
 private static void TryAdd(IBackgroundTask task, string key = null)
 {
     lock (_entries)
     {
         _entries.Add(string.IsNullOrWhiteSpace(key) ? DateTime.Now.ToString() : key, task);
     }
 }
 /// <summary>
 /// Pauses a task.
 /// </summary>
 /// <param name="p_tskTask">The task to pause.</param>
 public void PauseDownload(IBackgroundTask p_tskTask)
 {
     if (CanPause(p_tskTask))
     {
         p_tskTask.Pause();
     }
 }
 /// <summary>
 /// Resumes a task.
 /// </summary>
 /// <param name="p_tskTask">The task to resume.</param>
 public void ResumeDownload(IBackgroundTask p_tskTask)
 {
     if (CanResume(p_tskTask))
     {
         p_tskTask.Resume();
     }
 }
        /// <summary>
        /// A simple constructor that initializes the object with the given values.
        /// </summary>
        /// <param name="backgroundTask">The <see cref="IBackgroundTask"/> whose progress is to be displayed.</param>
        protected ProgressDialog(IBackgroundTask backgroundTask, bool allowCancel)
        {
            if (backgroundTask == null)
            {
                throw new ArgumentNullException(nameof(backgroundTask), "Argument can't be null");
            }

            Task                  = backgroundTask;
            Task.TaskEnded       += Task_TaskEnded;
            Task.PropertyChanged += Task_PropertyChanged;
            InitializeComponent();

            pbrItemProgress.Maximum = (int)Task.ItemProgressMaximum;
            pbrItemProgress.Minimum = (int)Task.ItemProgressMinimum;

            pbrItemProgress.Value = (int)Task.ItemProgress;
            lblItemMessage.Text   = Task.ItemMessage;
            lblTotalMessage.Text  = Task.OverallMessage;

            pbrItemProgress.Step     = Task.ItemProgressStepSize;
            pbrTotalProgress.Maximum = (int)Task.OverallProgressMaximum;
            pbrTotalProgress.Minimum = (int)Task.OverallProgressMinimum;
            pbrTotalProgress.Value   = (int)Task.OverallProgress;
            pbrTotalProgress.Step    = Task.OverallProgressStepSize;
            pnlItemProgress.Visible  = Task.ShowItemProgress;
            pbrTotalProgress.Style   = Task.ShowOverallProgressAsMarquee ? ProgressBarStyle.Marquee : ProgressBarStyle.Continuous;
            pbrItemProgress.Style    = Task.ShowItemProgressAsMarquee ? ProgressBarStyle.Marquee : ProgressBarStyle.Continuous;

            butCancel.Visible = allowCancel;
        }
Exemple #18
0
 /// <summary>
 /// Handles the <see cref="INotifyCollectionChanged.CollectionChanged"/> event of the view model's
 /// installed mod list.
 /// </summary>
 /// <remarks>
 /// This updates the list of mods to refelct changes to the installed mod list.
 /// </remarks>
 /// <param name="sender">The object that raised the event.</param>
 /// <param name="e">A <see cref="NotifyCollectionChangedEventArgs"/> describing the event arguments.</param>
 private void TaskList_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     switch (e.Action)
     {
     case NotifyCollectionChangedAction.Add:
     case NotifyCollectionChangedAction.Remove:
         lock (m_objLock)
         {
             if ((RunningTask == null) || ((RunningTask.Status != BackgroundTasks.TaskStatus.Queued) && (RunningTask.Status != BackgroundTasks.TaskStatus.Running) && (RunningTask.Status != BackgroundTasks.TaskStatus.Retrying)))
             {
                 if ((TaskList != null) && (TaskList.Count > 0))
                 {
                     lock (TaskList)
                     {
                         WriteLoadOrderTask NextTask = TaskList.FirstOrDefault();
                         RunningTask            = NextTask;
                         RunningTask.TaskEnded += new EventHandler <TaskEndedEventArgs>(RunningTask_TaskEnded);
                         NextTask.Update();
                     }
                 }
             }
         }
         break;
     }
 }
		/// <summary>
		/// Adds a task to the monitor.
		/// </summary>
		/// <param name="p_tskTask">The task to monitor.</param>
		public void AddActivity(IBackgroundTask p_tskTask)
		{
			p_tskTask.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Task_PropertyChanged);
			m_oclTasks.Add(p_tskTask);
			if (p_tskTask.IsActive)
				m_setActiveTasks.Add(p_tskTask);
		}
Exemple #20
0
 public NotificationService(INotificationRepository notificationRepository, UserManager <User> userManager,
                            IBackgroundTask backgroundTask)
 {
     this.notificationRepository = notificationRepository;
     this.userManager            = userManager;
     this.backgroundTask         = backgroundTask;
 }
        /// <summary>
        /// A simple constructor that initializes the object with the given values.
        /// </summary>
        /// <param name="p_bgtTask">The <see cref="IBackgroundTask"/> whose progress is to be displayed.</param>
        protected ProgressDialog(IBackgroundTask p_bgtTask, bool p_booAllowCancel)
        {
            m_intCreatedThreadId = Thread.CurrentThread.ManagedThreadId;
            Task                  = p_bgtTask;
            Task.TaskEnded       += new EventHandler <TaskEndedEventArgs>(Task_TaskEnded);
            Task.PropertyChanged += new PropertyChangedEventHandler(Task_PropertyChanged);
            InitializeComponent();

            pbrItemProgress.Maximum = (Int32)Task.ItemProgressMaximum;
            pbrItemProgress.Minimum = (Int32)Task.ItemProgressMinimum;

            pbrItemProgress.Value = (Int32)Task.ItemProgress;
            lblItemMessage.Text   = Task.ItemMessage;
            lblTotalMessage.Text  = Task.OverallMessage;

            pbrItemProgress.Step     = Task.ItemProgressStepSize;
            pbrTotalProgress.Maximum = (Int32)Task.OverallProgressMaximum;
            pbrTotalProgress.Minimum = (Int32)Task.OverallProgressMinimum;
            pbrTotalProgress.Value   = (Int32)Task.OverallProgress;
            pbrTotalProgress.Step    = Task.OverallProgressStepSize;
            pnlItemProgress.Visible  = Task.ShowItemProgress;
            pbrTotalProgress.Style   = Task.ShowOverallProgressAsMarquee ? ProgressBarStyle.Marquee : ProgressBarStyle.Continuous;
            pbrItemProgress.Style    = Task.ShowItemProgressAsMarquee ? ProgressBarStyle.Marquee : ProgressBarStyle.Continuous;

            butCancel.Visible = p_booAllowCancel;
        }
        public IBackgroundTask AsyncAddMod(Uri p_uriPath, ConfirmOverwriteCallback p_cocConfirmOverwrite)
        {
            IBackgroundTask tskAddModTask = ModAdditionQueue.AddMod(p_uriPath, p_cocConfirmOverwrite);

            AsyncAddModTask(tskAddModTask);
            return(tskAddModTask);
        }
        private static void RunProcess(IBackgroundTask process, ILoggerFactory loggerFactory, TaskContext context)
        {
            TrySetThreadName(process.ToString());

            var logger = loggerFactory.CreateLogger(process.GetProcessType());

            logger.LogDebug($"Background process '{process}' started.");

            try
            {
                process.Invoke(context);
            }
            catch (Exception ex)
            {
                if (ex is OperationCanceledException && context.IsShutdownRequested)
                {
                    // Graceful shutdown
                    logger.LogTrace($"Background process '{process}' was stopped due to a shutdown request.");
                }
                else
                {
                    logger.LogError(
                        $"Fatal error occurred during execution of '{process}' process. It will be stopped. See the exception for details.",
                        ex);
                }
            }

            logger.LogDebug($"Background process '{process}' stopped.");
        }
 public BackgroundTaskViewModel(IStatusBarService statusBarService, IBackgroundTask task)
 {
     this.statusBarService      = statusBarService;
     this.task                  = task ?? throw new ArgumentNullException(nameof(task));
     this.task.ProgressChanged += Task_ProgressChanged;
     this.DisplayName           = this.task.DisplayName;
 }
Exemple #25
0
        /// <summary>
        /// Run a background task.
        /// </summary>
        /// <param name="action"></param>
        public void RunBackgroundTask(IBackgroundTask action)
        {
            var actionId = action.Id ?? System.Guid.NewGuid().ToString("N");
            var cancelationTokenSource = new CancellationTokenSource();
            var token = cancelationTokenSource.Token;

            var asyncState = new JobState();

            asyncState.Id                = actionId;
            asyncState.BackgroundTask    = action;
            asyncState.CancellationToken = token;

            var jobTask = new Task(action: (state) =>
            {
                try
                {
                    action.Execute(token);
                }
                catch (Exception ex)
                {
                    Logger.Current.Write(LogLevel.Critical, ex.ToString());
                }
            }, state: asyncState, cancellationToken: token);

            _runningJobCancellationTokens.AddOrUpdate(actionId, cancelationTokenSource, (str, cts) => { return(cancelationTokenSource); });

            //we need this handler to only fire once, even though the job could be long lived and fire every often
            action.Complete -= _onComplete;
            action.Complete += _onComplete;

            jobTask.Start();

            _runningJobs.AddOrUpdate(actionId, jobTask, (str, j) => { return(jobTask); });
            _runningJobStartTimes.AddOrUpdate(actionId, DateTime.UtcNow, (str, dt) => { return(DateTime.UtcNow); });
        }
Exemple #26
0
 public void Remove(IBackgroundTask task)
 {
     lock (syncroot)
     {
         Tasks.Remove(task);
     }
 }
 public Conf_ProgressDialog(IBackgroundTask handler)
 {
     InitializeComponent();
     this.handler = handler;
     if (!string.IsNullOrEmpty(handler.TaskName))
         this.Text = handler.TaskName;
     statusLabel.Text = "";
 }
Exemple #28
0
 /// <summary>
 /// Called when [processing finished].
 /// </summary>
 protected void OnProcessingFinished(IBackgroundTask task)
 {
     // Remove item from queue to cleanup any held references
     if (task.ExecutionStatus == ExecutionStatus.Error || task.ExecutionStatus == ExecutionStatus.Success)
     {
         _queue.Remove(task);
     }
 }
Exemple #29
0
 protected virtual void OnBackgroundTask(IBackgroundTask backgroundTask)
 {
     if (this.BackgroundTask == null)
     {
         return;
     }
     this.BackgroundTask(this, new BackgroundTaskEventArgs(backgroundTask));
 }
		/// <summary>
		/// Removes a task from the monitor.
		/// </summary>
		/// <remarks>
		/// Tasks can only be removed if they are not running.
		/// </remarks>
		/// <param name="p_tskTask">The task to remove.</param>
		public void RemoveActivity(IBackgroundTask p_tskTask)
		{
			if (CanRemove(p_tskTask))
			{
				p_tskTask.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(Task_PropertyChanged);
				m_oclTasks.Remove(p_tskTask);
				m_setActiveTasks.Remove(p_tskTask);
			}
		}
Exemple #31
0
 private void OnBackgroundTaskStarted(IBackgroundTask task, object state)
 {
     backgroundTaskView.Visibility      = Visibility.Visible;
     backgroundTaskView.IsIndeterminate = task.IsIndeterminate;
     if (state != null)
     {
         backgroundTaskView.State = state.ToString();
     }
 }
 /// <summary>
 /// Removes a task from the monitor.
 /// </summary>
 /// <remarks>
 /// Tasks can only be removed if they are not running.
 /// </remarks>
 /// <param name="p_tskTask">The task to remove.</param>
 public void RemoveActivity(IBackgroundTask p_tskTask)
 {
     if (CanRemove(p_tskTask))
     {
         p_tskTask.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(Task_PropertyChanged);
         m_oclTasks.Remove(p_tskTask);
         m_setActiveTasks.Remove(p_tskTask);
     }
 }
        public InfiniteLoopTask(IBackgroundTask innerTask)
        {
            if (innerTask == null)
            {
                throw new ArgumentNullException(nameof(innerTask));
            }

            InnerTask = innerTask;
        }
Exemple #34
0
 public BackgroundTaskItemViewModel(IBackgroundTask task)
 {
     this.task = task;
     this.task.ProgressChanged += Task_ProgressChanged;
     if (this.task.IsBusy == false)
     {
         this.task.RunAsync();
     }
 }
 public ProgressDialogViewModel(IBackgroundTask backgroundTask)
 {
     if (backgroundTask == null)
     {
         throw new ArgumentNullException("backgroundTask");
     }
     this.backgroundTask = backgroundTask;
     backgroundTask.ProgressChanged += WorkerProgressChanged;
     backgroundTask.TaskCompleted += WorkerCompleted;
 }
        public ImportService(IOrchardServices orchardServices,
            IBackgroundTask backgroundTask,
            IBlogImportStrategy blogImportStrategy,
            IEnumerable<IBlogAssembler> blogAssemblers) {
            _backgroundTask = backgroundTask;
            _blogImportStrategy = blogImportStrategy;
            _blogAssemblers = blogAssemblers;
            _orchardServices = orchardServices;

            T = NullLocalizer.Instance;
        }
 /// <summary>
 /// Processes the task.
 /// </summary>
 /// <param name="task">The task.</param>
 public void Process(IBackgroundTask task)
 {
     if (CanProcessTask(task))
     {
         PerformTask(task);
     }
     else if(_nextProcessor != null)
     {
         _nextProcessor.Process(task);
     }
 }
        public int AddTask(IBackgroundTask task)
        {
            int id = ++_id;
            Tasks[id] = task;

            Task.Run(() =>
            {
                ObjectFactory.BuildUp(task);
                task.DoTask();
            });

            return id;
        }
        public static void ExecuteTask(IBackgroundTask backgroundTask)
        {
            if (!Properties.Settings.Default.BackgroundTasksEnabled)
                return;

            try
            {
                backgroundTask.Execute();
            }
            catch (TaskCanceledException)
            {
            }
            catch (Exception exception)
            {
                ExceptionsHandler.Handle(exception, backgroundTask);
            }
        }
		/// <summary>
		/// A simple constructor that initializes the object with the given values.
		/// </summary>
		/// <param name="p_tskTask">The task whose status is to be displayed by this list
		/// view item.</param>
		public ActivityListViewItem(IBackgroundTask p_tskTask)
		{
			Task = p_tskTask;

			ListViewSubItem lsiSubItem = SubItems[0];
			lsiSubItem.Name = ObjectHelper.GetPropertyName(() => p_tskTask.OverallMessage);
			lsiSubItem.Text = p_tskTask.OverallMessage;

			lsiSubItem = SubItems.Add(new ListViewSubItem());
			lsiSubItem.Name = ObjectHelper.GetPropertyName(() => p_tskTask.OverallProgress);
			if (p_tskTask.ShowOverallProgressAsMarquee)
				lsiSubItem.Text = "Working...";
			else
			{
				Int64 intDenominator = p_tskTask.OverallProgressMaximum - p_tskTask.OverallProgressMinimum;
				Int64 intPercent = (intDenominator == 0) ? 0 : p_tskTask.OverallProgress / intDenominator;
				lsiSubItem.Text = intPercent.ToString("P0");
			}

			lsiSubItem = SubItems.Add(new ListViewSubItem());
			lsiSubItem.Name = ObjectHelper.GetPropertyName(() => p_tskTask.ItemMessage);
			if (p_tskTask.ShowItemProgress)
				lsiSubItem.Text = p_tskTask.ItemMessage;

			lsiSubItem = SubItems.Add(new ListViewSubItem());
			lsiSubItem.Name = ObjectHelper.GetPropertyName(() => p_tskTask.ItemProgress);
			if (p_tskTask.ShowItemProgress)
			{
				if (p_tskTask.ShowItemProgressAsMarquee)
					lsiSubItem.Text = "Working...";
				else
				{
					Int64 intDenominator = p_tskTask.ItemProgressMaximum - p_tskTask.ItemProgressMinimum;
					Int64 intPercent = (intDenominator == 0) ? 0 : p_tskTask.ItemProgress / intDenominator;
					lsiSubItem.Text = intPercent.ToString("P0");
				}
			}

			p_tskTask.PropertyChanged += new PropertyChangedEventHandler(Task_PropertyChanged);

			lsiSubItem = SubItems.Add(new ListViewSubItem());
			lsiSubItem.Name = ObjectHelper.GetPropertyName(() => p_tskTask.Status);
			lsiSubItem.Text = p_tskTask.Status.ToString();
		}
		/// <summary>
		/// A simple constructor that initializes the object with the given values.
		/// </summary>
		/// <param name="p_bgtTask">The <see cref="IBackgroundTask"/> whose progress is to be displayed.</param>
		protected ProgressDialog(IBackgroundTask p_bgtTask)
		{
			m_intCreatedThreadId = Thread.CurrentThread.ManagedThreadId;
			Task = p_bgtTask;
			Task.TaskEnded += new EventHandler<TaskEndedEventArgs>(Task_TaskEnded);
			Task.PropertyChanged += new PropertyChangedEventHandler(Task_PropertyChanged);
			InitializeComponent();

			pbrItemProgress.Value = (Int32)Task.ItemProgress;
			lblItemMessage.Text = Task.ItemMessage;
			pbrTotalProgress.Value = (Int32)Task.OverallProgress;
			lblTotalMessage.Text = Task.OverallMessage;
			pbrItemProgress.Maximum = (Int32)Task.ItemProgressMaximum;
			pbrItemProgress.Minimum = (Int32)Task.ItemProgressMinimum;
			pbrItemProgress.Step = Task.ItemProgressStepSize;
			pbrTotalProgress.Maximum = (Int32)Task.OverallProgressMaximum;
			pbrTotalProgress.Minimum = (Int32)Task.OverallProgressMinimum;
			pbrTotalProgress.Step = Task.OverallProgressStepSize;
			pnlItemProgress.Visible = Task.ShowItemProgress;
			pbrTotalProgress.Style = Task.ShowOverallProgressAsMarquee ? ProgressBarStyle.Marquee : ProgressBarStyle.Continuous;
			pbrItemProgress.Style = Task.ShowItemProgressAsMarquee ? ProgressBarStyle.Marquee : ProgressBarStyle.Continuous;
		}
        public RunningAction(IBackgroundTask bgTask, bool isIndeterminate, bool isCancellable)
        {
            _isIndeterminate = isIndeterminate;
            _isCancellable = isCancellable;
            _bgTask = bgTask;

            //receive progress notification from implementor of IBackgroundTask to track progress
            //also if not reported using RunningAction class
            _bgTask.ProgressChanged += (o, e) =>{
                _updatingProgressFromInnerIBackgroundTask = true;
                try
                {
                    CurrentPercentage = e.ProgressPercentage/100.0;
                }
                finally
                {
                    _updatingProgressFromInnerIBackgroundTask = false;
                }
            };

            _bgTask.Starting += (o, e) => Current = this;
            _bgTask.Completed += (o, e) => Current = null;
        }
        /// <summary>
        /// Executes the specified this action on the specified target.
        /// </summary>
        /// <param name="actionMessage">The action message.</param>
        /// <param name="handlingNode">The node.</param>
        /// <param name="context">The context.</param>
        public override void Execute(ActionMessage actionMessage, IInteractionNode handlingNode, object context)
        {
            try
            {
                var parameters = _messageBinder.DetermineParameters(
                    actionMessage,
                    _requirements,
                    handlingNode,
                    context
                    );

                TryUpdateTrigger(actionMessage, handlingNode, true);

                CurrentTask = _method.CreateBackgroundTask(handlingNode.MessageHandler.Unwrap(), parameters);

                foreach (var filter in _filters.PreProcessors)
                {
                    if(filter.Execute(actionMessage, handlingNode, parameters)) 
                        continue;

                    TryUpdateTrigger(actionMessage, handlingNode, false);
                    return;
                }

                DoExecute(actionMessage, handlingNode, parameters);
            }
            catch (Exception ex)
            {
                TryUpdateTrigger(actionMessage, handlingNode, false);
                if(!TryApplyRescue(actionMessage, handlingNode, ex))
                {
                    Log.Error(ex);
                    throw;
                }
                OnCompleted();
            }
        }
 /// <summary>
 /// Attempt to get the instance of the task.
 /// </summary>
 /// <param name="instanceName">
 /// </param>
 /// <returns>
 /// </returns>
 public virtual bool TryGetTask([NotNull] string instanceName, out IBackgroundTask task)
 {
 	return _taskManager.TryGetValue(instanceName, out task);
 }
		/// <summary>
		/// Handles the <see cref="INotifyCollectionChanged.CollectionChanged"/> event of the view model's
		/// installed mod list.
		/// </summary>
		/// <remarks>
		/// This updates the list of mods to refelct changes to the installed mod list.
		/// </remarks>
		/// <param name="sender">The object that raised the event.</param>
		/// <param name="e">A <see cref="NotifyCollectionChangedEventArgs"/> describing the event arguments.</param>
		private void TaskList_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
		{
			switch (e.Action)
			{
				case NotifyCollectionChangedAction.Add:
				case NotifyCollectionChangedAction.Remove:
					lock (m_objLock)
					{
						if ((RunningTask == null) || ((RunningTask.Status != BackgroundTasks.TaskStatus.Queued) && (RunningTask.Status != BackgroundTasks.TaskStatus.Running) && (RunningTask.Status != BackgroundTasks.TaskStatus.Retrying)))
						{
							if ((TaskList != null) && (TaskList.Count > 0))
							{
								lock (TaskList)
								{
									WriteLoadOrderTask NextTask = TaskList.FirstOrDefault();
									RunningTask = NextTask;
									RunningTask.TaskEnded += new EventHandler<TaskEndedEventArgs>(RunningTask_TaskEnded);
									NextTask.Update();
								}
							}
						}
					}
					break;
			}
		}
		/// <summary>
		/// Determines if the given <see cref="IBackgroundTask"/> can be paused.
		/// </summary>
		/// <param name="p_tskTask">The task for which it is to be determined
		/// if it can be paused.</param>
		/// <returns><c>true</c> if the p_tskTask can be paused;
		/// <c>false</c> otherwise.</returns>
		public bool CanPause(IBackgroundTask p_tskTask)
		{
			return p_tskTask.SupportsPause && (p_tskTask.Status == TaskStatus.Running);
		}
		/// <summary>
		/// Pauses a task.
		/// </summary>
		/// <param name="p_tskTask">The task to pause.</param>
		public void PauseActivity(IBackgroundTask p_tskTask)
		{
			if (CanPause(p_tskTask))
				p_tskTask.Pause();
		}
		/// <summary>
		/// Determines if the given <see cref="IBackgroundTask"/> can be resumed.
		/// </summary>
		/// <param name="p_tskTask">The task for which it is to be determined
		/// if it can be resumed.</param>
		/// <returns><c>true</c> if the p_tskTask can be resumed;
		/// <c>false</c> otherwise.</returns>
		public bool CanResume(IBackgroundTask p_tskTask)
		{
			return (p_tskTask.Status == TaskStatus.Paused) || (p_tskTask.Status == TaskStatus.Incomplete);
		}
		/// <summary>
		/// Determines if the given <see cref="IBackgroundTask"/> can be cancelled.
		/// </summary>
		/// <param name="p_tskTask">The task for which it is to be determined
		/// if it can be cancelled.</param>
		/// <returns><c>true</c> if the task can be cancelled;
		/// <c>false</c> otherwise.</returns>
		public bool CanCancelTask(IBackgroundTask p_tskTask)
		{
			return (p_tskTask.Status == TaskStatus.Paused) || (p_tskTask.Status == TaskStatus.Incomplete) || (p_tskTask.InnerTaskStatus == TaskStatus.Retrying) || (p_tskTask.Status == TaskStatus.Queued);
		}
Exemple #50
0
 public static void ShowProgressDialog(IBackgroundTask handler)
 {
     if (IsConfig)
     {
         using (Conf_ProgressDialog dialog = new Conf_ProgressDialog(handler))
             dialog.ShowDialog();
     }
     else
     {
         GUIProgressDialogHandler guiDlg = new GUIProgressDialogHandler(handler);
         guiDlg.ShowDialog();
     }
 }
 public GUIProgressDialogHandler(IBackgroundTask handler)
 {
     this.handler = handler;
 }
		/// <summary>
		/// Determines if the given <see cref="IBackgroundTask"/> can be removed from
		/// the monitor.
		/// </summary>
		/// <param name="p_tskTask">The task for which it is to be determined
		/// if it can be removed from the monitor.</param>
		/// <returns><c>true</c> if the p_tskTask can be removed;
		/// <c>false</c> otherwise.</returns>
		public bool CanRemove(IBackgroundTask p_tskTask)
		{
			return !p_tskTask.IsActive && !CanResume(p_tskTask) && !(p_tskTask.InnerTaskStatus == TaskStatus.Retrying);
		}
		/// <summary>
		/// Resumes a task.
		/// </summary>
		/// <param name="p_tskTask">The task to resume.</param>
		public void ResumeDownload(IBackgroundTask p_tskTask)
		{
			if (CanResume(p_tskTask))
				p_tskTask.Resume();
		}
		/// <summary>
		/// Pauses a task.
		/// </summary>
		/// <param name="p_tskTask">The task to pause.</param>
		public void PauseDownload(IBackgroundTask p_tskTask)
		{
			if (CanPause(p_tskTask))
				p_tskTask.Pause();
		}
		/// <summary>
		/// Pauses a task.
		/// </summary>
		/// <param name="p_tskTask">The task to pause.</param>
		public void QueueDownload(IBackgroundTask p_tskTask)
		{
			if (CanQueue(p_tskTask))
				p_tskTask.Queue();
		}
		/// <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>
		/// Raises the <see cref="TaskStarted"/> event.
		/// </summary>
		/// <param name="p_bgtTask">The task that was started.</param>
		protected void OnTaskStarted(IBackgroundTask p_bgtTask)
		{
			OnTaskStarted(new EventArgs<IBackgroundTask>(p_bgtTask));
		}
		/// <summary>
		/// Determines if the given <see cref="IBackgroundTask"/> can be removed from
		/// the monitor.
		/// </summary>
		/// <param name="p_tskTask">The task for which it is to be determined
		/// if it can be removed from the monitor.</param>
		/// <returns><c>true</c> if the p_tskTask can be removed;
		/// <c>false</c> otherwise.</returns>
		public bool CanRemove(IBackgroundTask p_tskTask)
		{
			return !p_tskTask.IsActive && !CanResume(p_tskTask);
		}
		/// <summary>
		/// Resumes a task.
		/// </summary>
		/// <param name="p_tskTask">The task to resume.</param>
		public void ResumeActivity(IBackgroundTask p_tskTask)
		{
			if (CanResume(p_tskTask))
				p_tskTask.Resume();
		}
		/// <summary>
		/// Determines if the given <see cref="IBackgroundTask"/> can be paused.
		/// </summary>
		/// <param name="p_tskTask">The task for which it is to be determined
		/// if it can be paused.</param>
		/// <returns><c>true</c> if the p_tskTask can be paused;
		/// <c>false</c> otherwise.</returns>
		public bool CanQueue(IBackgroundTask p_tskTask)
		{
			return p_tskTask.SupportsQueue && ((p_tskTask.Status == TaskStatus.Running) || (p_tskTask.InnerTaskStatus == TaskStatus.Running) || (p_tskTask.Status == TaskStatus.Retrying) || (p_tskTask.InnerTaskStatus == TaskStatus.Retrying));
		}