Esempio n. 1
0
        private JobTaskResult RunAction(IEnumerable <Task <JobTaskResult> > parentTasks)
        {
            if (parentTasks.Any(x => x.Result.ActionCanceled))
            {
                State = JobState.ActionSkipped;
                OnActionFailed?.Invoke(this, new JobFailedArgs {
                    Exception = new Exception("Skipped because one of parent tasks failed")
                });
                return(JobTaskResult.Failed());
            }

            var result        = new JobTaskResult();
            var withSemaphore = jobsContext.UseActionSemaphore;

            if (withSemaphore)
            {
                State = JobState.ActionWaitForSemaphore;
                jobsContext.ActionSemaphore.Wait();
            }

            try
            {
                OnActionExecuting?.Invoke(this, new JobArgs());
                State = JobState.ActionExecuting;
                Action(new JobActionFeed(result));

                if (result.ActionCanceled)
                {
                    state = JobState.ActionCanceled;
                }
                else
                {
                    OnActionExecuted?.Invoke(this, new JobArgs());
                    state = JobState.ActionExecuted;
                }
            }
            catch (Exception ex)
            {
                var args = new JobFailedArgs
                {
                    Exception = ex
                };

                result.ActionCanceled = true;
                OnActionFailed?.Invoke(this, args);
                State = JobState.ActionFailed;
            }

            if (withSemaphore)
            {
                jobsContext.ActionSemaphore.Release();
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// 执行action
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        public bool Execute(KancolleAction action)
        {
            Application.Current.Dispatcher.Invoke(new Action(() => {
                var host = webBrowser.GetBrowser().GetHost();
                switch (action.ActionType)
                {
                case ActionTypes.Click:
                    //host.SendMouseMoveEvent((int)action.ActionPosition.X, (int)action.ActionPosition.Y, false, CefEventFlags.None);
                    host.SendMouseClickEvent((int)action.ActionPosition.X, (int)action.ActionPosition.Y, MouseButtonType.Left, false, 1, CefEventFlags.None);
                    host.SendMouseClickEvent((int)action.ActionPosition.X, (int)action.ActionPosition.Y, MouseButtonType.Left, true, 1, CefEventFlags.None);
                    break;

                case ActionTypes.Move:
                    host.SendMouseMoveEvent((int)action.ActionPosition.X, (int)action.ActionPosition.Y, false, CefEventFlags.None);
                    break;
                }

                OnActionExecuted?.InvokeAll(action);
            }));

            return(true);
        }
Esempio n. 3
0
 public void PublishEvent(T t)
 {
     OnActionExecuted?.Invoke(this, t);
 }