Esempio n. 1
0
        public void CancelTask()
        {
            try {
                if (repo.Active)
                {
                    repo.CancelDownloads();
                    Active = false;
                    Status = "Task cancelled";
                    ComicConvert.ImgsToCbz(repo.Location, OutputFileName);
                    if (TaskCancelled != null)
                    {
                        TaskCancelled.Invoke(this, new EventArgs());
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }

            Active = false;
            Status = "Task cancelled";
            if (TaskCancelled != null)
            {
                TaskCancelled.Invoke(this, new EventArgs());
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 取消下载任务
 /// </summary>
 public void Cancel()
 {
     lock (_external_lock)
     {
         lock (_thread_flag_lock)
         {
             //Tracer.GlobalTracer.TraceInfo("---CANCELLED---");
             if (((_download_thread_flag & 0xffffff) & (_DOWNLOAD_THREAD_FLAG_STOPPED | _DOWNLOAD_THREAD_FLAG_FINISHED)) != 0)
             {
                 return;
             }
             if ((_download_thread_flag & 0xffffff) == _DOWNLOAD_THREAD_FLAG_READY)
             {
                 _download_thread_flag = (_download_thread_flag | _DOWNLOAD_THREAD_FLAG_STOPPED) & ~_DOWNLOAD_THREAD_FLAG_READY;
                 return;
             }
             else if ((_download_thread_flag & 0xffffff) == _DOWNLOAD_THREAD_FLAG_PAUSED)
             {
                 _download_thread_flag = (_download_thread_flag | _DOWNLOAD_THREAD_FLAG_STOPPED) & ~_DOWNLOAD_THREAD_FLAG_PAUSED;
                 return;
             }
             else if (((_download_thread_flag & 0xffffff) & (_DOWNLOAD_THREAD_FLAG_STARTED | _DOWNLOAD_THREAD_FLAG_START_REQUESTED)) != 0)
             {
                 _download_thread_flag |= _DOWNLOAD_THREAD_FLAG_STOP_REQUESTED;
             }
         }
         _monitor_thread_created.Wait();
         _monitor_thread.Join();
         _monitor_thread_created.Reset();
         Dispose();
     }
     try { TaskCancelled?.Invoke(this, new EventArgs()); }
     catch { }
 }
Esempio n. 3
0
        private void Handle(TaskCancelled message)
        {
            RequireActivation(true);
            if (message.ParentTaskInstanceId != this.InstanceId)
            {
                throw new Exception();
            }
            TransitionInfo ti = GetTransition(message.FromTaskInstanceId);

            if (ti == null)
            {
                throw new Exception();
            }
            lock (this)
            {
                log.Info("Child task {0} has been cancelled", ti.InstanceId);
                if (ti.Status == TransitionStatus.Cancelled)
                {
                    return;
                }
                if (!ti.IsTransitionActive)
                {
                    log.Warn("Transition {0} ({1}) is not active: {2}", ti.InstanceId, ti.TaskId, ti.Status);
                    return;
                }
                ti.Status = TransitionStatus.Cancelled;
                OnTransitionStatusChanged(ti.InstanceId);
                return;
            }
        }
        public void Handle(TaskCancelled @event)
        {
            if (@event.QueueId != queueId)
            {
                return;
            }

            timer.Stop();
        }
Esempio n. 5
0
        /// <summary>
        /// Add a <see cref="TaskCancelled"/> callback
        /// </summary>
        /// <param name="callback"><see cref="TaskCancelled"/> callback to add</param>
        /// <returns>The <see cref="TaskContext"/></returns>
        public TaskContext Cancelled(TaskCancelled callback)
        {
            if (IsCancelled)
            {
                callback(this);
            }

            _cancelled += callback;
            return(this);
        }
Esempio n. 6
0
        public void Cancel()
        {
            lock (_external_lock)
            {
                lock (_thread_flag_lock)
                {
                    //cancelled state
                    if ((_upload_thread_flag & (_UPLOAD_THREAD_FLAG_CANCELLED | _UPLOAD_THREAD_FLAG_FINISHED)) != 0)
                    {
                        return;
                    }
                    //ready state
                    if ((_upload_thread_flag & _UPLOAD_THREAD_FLAG_READY) != 0)
                    {
                        _upload_thread_flag = (_upload_thread_flag | _UPLOAD_THREAD_FLAG_CANCELLED) & ~_UPLOAD_THREAD_FLAG_READY;
                        return;
                    }
                    //paused state
                    if ((_upload_thread_flag & _UPLOAD_THREAD_FLAG_PAUSED) != 0)
                    {
                        _upload_thread_flag = (_upload_thread_flag | _UPLOAD_THREAD_FLAG_CANCELLED) & ~_UPLOAD_THREAD_FLAG_PAUSED;
                        return;
                    }
                    if ((_upload_thread_flag & (_UPLOAD_THREAD_FLAG_STARTED | _UPLOAD_THREAD_FLAG_START_REQUESTED)) != 0)
                    {
                        Tracer.GlobalTracer.TraceInfo("---CANCELLED---");
                        _upload_thread_flag |= _UPLOAD_THREAD_FLAG_CANCEL_REQUESTED;
                    }

                    _monitor_thread_created.Wait();
                    _monitor_thread_exited.Wait();
                    _monitor_thread_exited.Reset();
                    _monitor_thread_created.Reset();
                    Dispose();
                }
            }
            try { TaskCancelled?.Invoke(this, new EventArgs()); } catch { }
        }
        public void RaiseTaskCancelled(Task task, [CallerMemberName] string taskName = default)
        {
            var status = $"[Cancelled] Task: {taskName}. status: {task.Status}".AppendMainThreadAlert();

            TaskCancelled?.Invoke(this, new TaskStatusChangedEventArgs(task, status));
        }
Esempio n. 8
0
        /// <summary>
        /// Add a <see cref="TaskCancelled"/> callback
        /// </summary>
        /// <param name="callback"><see cref="TaskCancelled"/> callback to add</param>
        /// <returns>The <see cref="TaskContext"/></returns>
        public TaskContext Cancelled(TaskCancelled callback)
        {
            if (IsCancelled) callback(this);

            _cancelled += callback;
            return this;
        }
        /// <summary>
        /// Handle notification about child task been cancelled.
        /// What should happen then?
        /// Transition info should be updated to reflect the fact that child task
        /// has been cancelled. However, no tokens should be returned to task's input places,
        /// because it would re-enable the task, and that's not what we want.
        /// If all tasks are cancelled and there will be no more tokens, composite task
        /// will complete. If it cannot complete due to missing output data, it will fail.
        /// </summary>
        /// <param name="tce"></param>
        private void HandleChildTaskCancelled(TaskCancelled tce)
        {
            if (tce.ParentTaskInstanceId != this.InstanceId)
                throw new Exception("Parent task correlation id is incorrect");
            TransitionInfo ti = GetTransitionInfo(tce.FromTaskInstanceId);
            if (ti == null)
                throw new Exception("Child task not found");
            log.Debug("Child task {0} cancelled. Current transition status: {1}", tce.FromTaskInstanceId, ti.Status);

            if (ti.Status == TransitionStatus.Enabling)
            {
                ti.Status = TransitionStatus.Enabled; 
            }
                
            if (ti.Status == TransitionStatus.Cancelled)
            {
                return; //nothing tbd
            }
            else if (ti.Status == TransitionStatus.Started || ti.Status == TransitionStatus.FailedActive)
            {
                ti.Status = TransitionStatus.Cancelled; //do nothing more, the task has consumed the tokens already
            }
            else if (ti.Status == TransitionStatus.Enabled)
            {
                ConsumeTaskInputTokens(ti.InstanceId);
                Debug.Assert(ti.Status == TransitionStatus.Started);
            }
            else if (ti.Status == TransitionStatus.Cancelling)
            {
                //everyth. ok.
            }
            else
            {
                log.Warn("Child task {0} ({1}) cancelled, but current transition status is {2}. Ignoring the notification - status inconsistent", tce.FromTaskInstanceId, ti.TaskId, ti.Status);
                return;
            }
            ti.Status = TransitionStatus.Cancelled;
            if (Status == TaskStatus.Enabled || Status == TaskStatus.Selected)
            {
                ProduceTaskOutputTokens(ti.InstanceId);
            }
            ContinueTaskExecution();
            //OnInternalStatusChanged();
            //DetectTaskCompletion();
        }
Esempio n. 10
0
 private void Handle(TaskCancelled message)
 {
     HandleChildTaskCancelled(message);
 }
Esempio n. 11
0
 private void _on_task_cancelled(object sender, EventArgs e)
 {
     try { TaskCancelled?.Invoke(sender, e); }
     catch { }
 }
 private void OnTaskCancelled()
 {
     TaskCancelled?.Invoke(this, EventArgs.Empty);
 }
Esempio n. 13
0
 private void Handle(TaskCancelled message)
 {
     RequireActivation(true);
     if (message.ParentTaskInstanceId != this.InstanceId) throw new Exception();
     TransitionInfo ti = GetTransition(message.FromTaskInstanceId);
     if (ti == null) throw new Exception();
     lock (this)
     {
         log.Info("Child task {0} has been cancelled", ti.InstanceId);
         if (ti.Status == TransitionStatus.Cancelled)
             return;
         if (!ti.IsTransitionActive)
         {
             log.Warn("Transition {0} ({1}) is not active: {2}", ti.InstanceId, ti.TaskId, ti.Status);
             return;
         }
         ti.Status = TransitionStatus.Cancelled;
         OnTransitionStatusChanged(ti.InstanceId);
         return;
     }
 }