예제 #1
0
파일: TaskEngine.cs 프로젝트: ko9ma7/Gcld
 private void DoEventHandler(TaskEventHandler hander, TaskEventArg e)
 {
     if (hander != null)
     {
         hander.Invoke(this, e);
     }
 }
예제 #2
0
파일: TaskEngine.cs 프로젝트: ko9ma7/Gcld
 public void Start(params TaskBase[] tasks)
 {
     tasks.CheckNotNull("tasks");
     if (tasks.Length == 0)
     {
         return;
     }
     TaskList = tasks.ToList();
     if (_workThread == null)
     {
         _workThread = GetWorkThread(tasks);
         Debug.WriteLine("[" + _workThread.ManagedThreadId.ToString() + "]");
     }
     if (!CheckTaskRunState(Tasks.TaskRunState.Starting))
     {
         return;
     }
     _task         = tasks[0];
     _taskEventArg = new TaskEventArg {
         Context = _task.TaskContext
     };
     OutMessage("任务“{0}”正在启动。".FormatWith(_task.Name));
     TaskRunState = TaskRunState.Starting;
     OnStateChanged(_taskEventArg);
     OnStarting(_taskEventArg);
     _workThread.Start();
 }
예제 #3
0
        private Thread GetWorkThread(IEnumerable <TaskBase> tasks)
        {
            return(new Thread(() =>
            {
                foreach (TaskBase task in tasks)
                {
                    _task = task;
                    _taskEventArg = new TaskEventArg {
                        Context = _task.TaskContext
                    };
                    try
                    {
                        //窗口绑定
                        DmPlugin dm = Window.Dm;
                        bool flag;
                        flag = Delegater.WaitTrue(() => Window.BindHalfBackground(), () => dm.Delay(1000), 10);
                        //flag = Delegater.WaitTrue(() => Window.BindNormal(), () => dm.Delay(1000), 10);
                        if (!flag)
                        {
                            throw new Exception("角色绑定失败,请添加杀软信任,右键以管理员身份运行,Win7系统请确保电脑账户为“Administrator”");
                        }
                        TaskRunState = TaskRunState.Running;
                        OnStateChanged(_taskEventArg);
                        OnStarted(_taskEventArg);
                        OutMessage("任务“{0}”启动成功。".FormatWith(_task.Name));

                        TaskStart();
                        TaskStop();
                        Window.FlashWindow();
                    }
                    catch (ThreadAbortException)
                    {
                        TaskStop(true);
                        WaitForUnBind();
                        break;
                    }
                    catch (Exception ex)
                    {
                        TaskStop();
                        Window.FlashWindow();
                        Logger.Error("任务执行失败,{0}", ex.FormatMessage());
                        OutMessage("任务执行失败,{0}".FormatWith(ex.Message));
                    }
                    Window.Dm.Delay(1000);
                    TaskList.Remove(task);
                }
                WaitForUnBind();
                _workThread = null;
            })
            {
                IsBackground = true
            });
        }
예제 #4
0
파일: TaskEngine.cs 프로젝트: ko9ma7/Gcld
        private Thread GetWorkThread(IEnumerable <TaskBase> tasks)
        {
            return(new Thread(() =>
            {
                //窗口绑定
                DmPlugin dm = Window.Dm;
                bool flag;
                flag = Delegater.WaitTrue(() => Window.BindHalfBackgroundMoniqi(), () => dm.Delay(1000), 10);
                if (!flag)
                {
                    throw new Exception("角色绑定失败,请添加杀软信任,右键以管理员身份运行,Win7系统请确保电脑账户为“Administrator”");
                }
                // dm.DownCpu(20);
                while (true)
                {
                    Cycle = 0;
                    if (AutoLogin != null)
                    {
                        bool isLogin = AutoLogin();
                        if (isLogin == false)
                        {
                            Logger.Error("任务执行失败,{0}", "登录失败!");
                            OutMessage("任务执行失败,{0}".FormatWith("登录失败!"));
                            break;
                        }
                    }
                    while (true)
                    {
                        Cycle++;
                        foreach (TaskBase task in tasks)
                        {
                            _task = task;
                            _taskEventArg = new TaskEventArg {
                                Context = _task.TaskContext
                            };
                            try
                            {
                                TaskRunState = TaskRunState.Running;
                                OnStateChanged(_taskEventArg);
                                OnStarted(_taskEventArg);

                                OutMessage("任务“{0}”启动成功。".FormatWith(_task.Name));
                                TaskStart();
                                TaskStop(true);
                                Window.FlashWindow();
                            }
                            catch (ThreadAbortException)
                            {
                                TaskStop(true);
                                WaitForUnBind();
                                break;
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex.Message);
                                TaskStop();
                                Window.FlashWindow();
                                Logger.Error("任务执行失败,{0}", ex.FormatMessage());
                                OutMessage("任务执行失败,{0}".FormatWith(ex.Message));
                            }
                            Window.Dm.Delay(1000);
                            TaskList.Remove(task);
                        }

                        //切换角色
                        if (ChangeRole != null)
                        {
                            bool isChange = ChangeRole();
                            if (isChange == false)
                            {
                                Logger.Error("切换角色失败!");
                                OutMessage("切换角色失败!");
                                if (AutoLogin != null)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            WaitForUnBind();
                            _workThread = null;
                            return;
                        }
                        Thread.Sleep(5000);
                    }
                    Thread.Sleep(5000);
                }
                WaitForUnBind();
                _workThread = null;
            })
            {
                IsBackground = true
            });
        }
예제 #5
0
파일: TaskEngine.cs 프로젝트: ko9ma7/Gcld
        protected virtual void OnStateChanged(TaskEventArg e)
        {
            TaskEventHandler handler = StateChanged;

            DoEventHandler(handler, e);
        }
예제 #6
0
파일: TaskEngine.cs 프로젝트: ko9ma7/Gcld
        protected virtual void OnStopping(TaskEventArg e)
        {
            TaskEventHandler handler = Stopping;

            DoEventHandler(handler, e);
        }
예제 #7
0
파일: TaskEngine.cs 프로젝트: ko9ma7/Gcld
        protected virtual void OnContinued(TaskEventArg e)
        {
            TaskEventHandler handler = Continued;

            DoEventHandler(handler, e);
        }
예제 #8
0
파일: TaskEngine.cs 프로젝트: ko9ma7/Gcld
        protected virtual void OnPaused(TaskEventArg e)
        {
            TaskEventHandler handler = Paused;

            DoEventHandler(handler, e);
        }