Ejemplo n.º 1
0
 private TaskInterval(int interval = 0, int month = 0, int day = 0, TimeSpan?time = null)
 {
     if (interval > 0)
     {
         _mode     = TaskMode.Interval;
         _interval = interval;
     }
     else if (month > 0)
     {
         _mode  = TaskMode.Month;
         _month = month;
         _day   = day;
         _time  = time ?? TimeSpan.Zero;
     }
     else if (day > 0)
     {
         _mode = TaskMode.Day;
         _day  = day;
         _time = time ?? TimeSpan.Zero;
     }
     else
     {
         _mode = TaskMode.Hour;
         _time = time ?? TimeSpan.Zero;
     }
 }
Ejemplo n.º 2
0
        public bool Run()
        {
            switch (_iMode)
            {
            case TaskMode.TaskMode_Init:
                if (Init())
                {
                    _iMode = TaskMode.TaskMode_Update;
                }
                break;

            case TaskMode.TaskMode_Update:
                if (!Update())
                {
                    _iMode = TaskMode.TaskMode_UnInit;
                }
                break;

            case TaskMode.TaskMode_UnInit:
                if (Close())
                {
                }
                break;
            }
            return(IsRun());
        }
Ejemplo n.º 3
0
 public bool Close()
 {
     if (_pTasks != null)
     {
         for (int i = 0; i < _pTasks.taskNum; i++)
         {
             DebugUtils.dbgAssert(null != _pTasks.tasks);
             if (_pTasks.tasks[i] != null && this == _pTasks.tasks[i]._pTaskParent && !_pTasks.tasks[i].Close())
             {
                 return(false);
             }
         }
     }
     _iMode = TaskMode.TaskMode_UnInit;
     if (!UnInit())
     {
         return(false);
     }
     if (_pTasks != null)
     {
         DebugUtils.dbgAssert(null != _pTasks.tasks);
         DebugUtils.dbgAssert(_iTask >= 0 && _iTask < _pTasks.taskNum);
         _pTasks.tasks[_iTask] = null;
     }
     _pTasks      = null;
     _iTask       = -1;
     _pTaskParent = null;
     _iMode       = TaskMode.TaskMode_ST;
     return(true);
 }
Ejemplo n.º 4
0
 /// <summary>
 ///     Use this method in your NoHarmonyLoad() method to replace a specified behavior by a new specified one.
 /// </summary>
 /// <typeparam name="AddType">Behavior type to add</typeparam>
 /// <typeparam name="RemoveType">Behavior type to remove</typeparam>
 /// <param name="m">Not required. The replace mode to use. (Do not pick add or remove)</param>
 public void ReplaceBehavior <AddType, RemoveType>(TaskMode m = TaskMode.Replace)
     where AddType : CampaignBehaviorBase, new()
     where RemoveType : CampaignBehaviorBase
 {
     BehaviorDelegates.Add(NHLBehavior <AddType, RemoveType>);
     BehaviorModes.Add(m);
 }
Ejemplo n.º 5
0
 public Task()
 {
     _pTasks      = null;
     _iTask       = -1;
     _pTaskParent = null;
     _iMode       = TaskMode.TaskMode_ST;
 }
Ejemplo n.º 6
0
        TaskResult IInternalTask.PerformTask(object argument, TaskMode taskMode)
        {
            this.Argument = (T)argument;
            TaskEventArgs <T> e = new TaskEventArgs <T>(this.Argument, taskMode);

            this.OnExecute(e);
            return(e.TaskResult);
        }
Ejemplo n.º 7
0
        public TaskRunner(TaskMode Mode)
        {
            mode = Mode;

            if (mode == TaskMode.AsynchronousHighPriority)
            {
                signal = new AutoResetEvent(false);
                thread = new Thread(TaskLoop);
                thread.Start();
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Use this method in your NoHarmonyLoad() method to replace a specified model by a new specified one.
 /// </summary>
 /// <typeparam name="AddType">Model type to add</typeparam>
 /// <typeparam name="RemoveType">Model type to be replaced</typeparam>
 /// <param name="m">Not required. The replace mode to use. (Do not pick add or remove)</param>
 public void ReplaceModel <AddType, RemoveType>(TaskMode m = TaskMode.Replace)
     where AddType : GameModel, new()
     where RemoveType : GameModel
 {
     if (TaskMode.Add == m || m == TaskMode.Remove)
     {
         return;
     }
     ModelDelegates.Add(NHLModel <AddType, RemoveType>);
     ModelModes.Add(m);
 }
Ejemplo n.º 9
0
 public bool Open(Tasks pTasks, int iTask, Task pTaskParent)
 {
     _pTasks = pTasks;
     DebugUtils.dbgAssert(_iMode == TaskMode.TaskMode_ST);
     if (pTasks != null)
     {
         pTasks.tasks[iTask] = this;
     }
     _iTask       = iTask;
     _pTaskParent = pTaskParent;
     _iMode       = TaskMode.TaskMode_Init;
     return(true);
 }
Ejemplo n.º 10
0
 public Assignment(TaskMode m, Profile prof)
 {
     Mode = m;
     if (m == TaskMode.STORE)
     {
         Source = prof.GameFolder;
         Target = prof.StorageFolder;
     }
     if (m == TaskMode.RESTORE || m == TaskMode.LINK)
     {
         Source = prof.StorageFolder;
         Target = prof.GameFolder;
     }
 }
Ejemplo n.º 11
0
        private void initPanelEvents(TaskMode mode, IPanelEventHandler panel)
        {
            if (panel == null)
            {
                return;
            }

            panel.handler         = mode;
            panel.StartTask      += mode.StartTask;
            panel.StopTask       += mode.StopTask;
            panel.PauseTask      += mode.PauseTask;
            panel.Continue       += mode.ContinueTask;
            panel.SetNextButton  += mode.SetAutomaticShifting;
            mode.SetTimeLabel    += panel.SetTimeLabel;
            mode.QuestionTimeOut += choicesUserControl.QuestionTimeOut;
            previousButton.Click += mode.PreviousQuestion;
            nextButton.Click     += mode.NextQuestion;
        }
Ejemplo n.º 12
0
        private TaskStatus NHLBehavior <AddType, RemoveType>(Campaign campaign, TaskMode mode)
            where RemoveType : CampaignBehaviorBase
            where AddType : CampaignBehaviorBase, new()
        {
            CampaignBehaviorManager cbm = (CampaignBehaviorManager)campaign.CampaignBehaviorManager;

            if (mode != TaskMode.Add)
            {
                var cgb = campaign.GetCampaignBehavior <RemoveType>();
                CampaignEvents.RemoveListeners(cgb);
                cbm.RemoveBehavior <RemoveType>();
            }
            if (mode != TaskMode.Remove)
            {
                cbm.AddBehavior(new AddType());
            }
            return(TaskStatus.Completed);
        }
Ejemplo n.º 13
0
        public static void ActivateCombatMode()
        {
            if (_taskMode == TaskMode.Combat)
                return;
            _combatTasks.Clear();
            _taskMode = TaskMode.Combat;

            // Requests the combat tasks
            List<Tower> towers = WorldMap.Instance.GetTowers();

            foreach (Tower t in towers)
            {
                foreach (TowerSlot ts in t.GetTowerSlots())
                {
                    TaskManager.AddCombatTask(new MoveToTowerTask(null, t));
                }
            }
        }
Ejemplo n.º 14
0
        private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.OriginalSource == tabControl)
            {
                if (currentMode == TaskModeFactory.Mode.Unknow || currentMode == TaskModeFactory.Mode.RaceMode)
                {
                    return;
                }

                if (tabControl.SelectedIndex == 1) //Trainer
                {
                    currentMode = TaskModeFactory.Mode.TrainingMode;
                }
                else if (tabControl.SelectedIndex == 2) //Race
                {
                    currentMode = TaskModeFactory.Mode.RaceMode;
                }
                TaskMode mode = availableTaskModes[currentMode];
                ChangeRunningState(mode.ModeName, TaskMode.State.Default);
            }
        }
Ejemplo n.º 15
0
        private void InitTaskModes()
        {
            availableTaskModes = new Dictionary <TaskModeFactory.Mode, TaskMode>();

            //Training Mode
            var trainingMode = TaskModeFactory.CreateMode(TaskModeFactory.Mode.TrainingMode);
            var racingMode   = TaskModeFactory.CreateMode(TaskModeFactory.Mode.RaceMode);

            availableTaskModes[TaskModeFactory.Mode.TrainingMode] = trainingMode;
            availableTaskModes[TaskModeFactory.Mode.RaceMode]     = racingMode;

            foreach (var item in availableTaskModes)
            {
                TaskMode mode = item.Value;

                //Set Events
                mode.Finished            += Finished;
                mode.SetProgressBarValue += SetProgressBarValue;
                mode.ChangeRunningState  += ChangeRunningState;
                mode.LoadQuestion        += LoadCurrentQuestion;
                mode.SetIndexLabel       += SetIndexLabel;
                initPanelEvents(mode, GetIPanelEventHandler(item.Key));
            }
        }
Ejemplo n.º 16
0
 internal UndoableTaskEventArgs(TArgument argument, TaskMode taskMode)
     : base(argument, taskMode)
 {
 }
Ejemplo n.º 17
0
        protected internal virtual void ExecuteInternal(List <UndoableTaskBase <T> > taskList, TaskMode taskMode)
        {
            List <UndoableTaskBase <T> > source = new List <UndoableTaskBase <T> >();

            foreach (UndoableTaskBase <T> task in taskList)
            {
                try
                {
                    int num = (int)task.PerformTask((object)null, taskMode);
                    source.Add(task);
                }
                catch (Exception)
                {
                    SequentiallyCompositeUndoableTask <T> .SafelyUndoTasks(source.Cast <IUndoableTask>());

                    throw;
                }
            }
        }
Ejemplo n.º 18
0
        private TaskStatus NHLModel <AddType, RemoveType>(IGameStarter gameI, TaskMode mode)
            where RemoveType : GameModel
            where AddType : GameModel, new()
        {
            IList <GameModel> models = gameI.Models as IList <GameModel>;
            TaskStatus        st     = TaskStatus.Pending;
            int rm = 0;

            for (int index = 0; index < models.Count; ++index)
            {
                if (mode != TaskMode.Remove && models[index] is AddType)
                {
                    Log(LogLvl.Warning, typeof(AddType) + " already installed, skipping.");
                    if (mode == TaskMode.RemoveAndAdd)
                    {
                        st = TaskStatus.Warning;
                    }
                    else
                    {
                        return(TaskStatus.Warning);
                    }
                }

                if (models[index] is RemoveType)
                {
                    if (mode == TaskMode.Replace || mode == TaskMode.ReplaceOrAdd)
                    {
                        models[index] = new AddType();
                        Log(
                            LogLvl.Info,
                            typeof(RemoveType) +
                            " found and replaced with " +
                            typeof(AddType) +
                            ".");
                        return(TaskStatus.Completed);
                    }

                    if (mode == TaskMode.Remove || mode == TaskMode.RemoveAndAdd)
                    {
                        models.RemoveAt(index); // C# rearrange the for loop on it's own.
                        rm++;
                        index--;
                    }
                }
            }

            if (mode != TaskMode.Replace && mode != TaskMode.Remove && st == TaskStatus.Pending)
            {
                gameI.AddModel(new AddType());
                Log(LogLvl.Info, typeof(AddType) + " added.");
            }

            if (mode == TaskMode.RemoveAndAdd)
            {
                if (rm == 0)
                {
                    Log(LogLvl.Warning, typeof(RemoveType) + " not found.");
                    st = TaskStatus.Warning;
                }

                if (st == TaskStatus.Pending)
                {
                    st = TaskStatus.Completed;
                }

                return(st);
            }

            if (mode == TaskMode.Remove && rm == 0)
            {
                Log(LogLvl.Warning, typeof(RemoveType) + " not found.");
                return(TaskStatus.Warning);
            }

            return(TaskStatus.Completed);
        }
Ejemplo n.º 19
0
 /// <summary>
 /// 带狗粮
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dgl_check(object sender, RoutedEventArgs e)
 {
     dxc.IsChecked = false;
     TaskMode      = TaskMode.DGL;
 }
Ejemplo n.º 20
0
 public TaskModeEventArgs(StutterTask task, TaskMode mode)
 {
     Task = task;
     Mode = mode;
 }
Ejemplo n.º 21
0
 public Assignment(TaskMode m, DirectoryInfo source, DirectoryInfo target)
 {
     this.Mode   = m;
     this.Source = source;
     this.Target = target;
 }
Ejemplo n.º 22
0
 internal TaskResult PerformTask(object argument, TaskMode taskMode)
 {
     return(((IInternalTask)this).PerformTask(argument, taskMode));
 }
Ejemplo n.º 23
0
 /// <summary>
 /// 地下城
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dxc_check(object sender, RoutedEventArgs e)
 {
     dgl.IsChecked = false;
     TaskMode      = TaskMode.DXC;
 }
Ejemplo n.º 24
0
 public TaskModeManager(TaskMode mode)
 {
     _mode = mode;
 }
Ejemplo n.º 25
0
 protected internal virtual void ExecuteInternal(Dictionary <TaskBase <T>, T> taskDictionary, TaskMode taskMode)
 {
     if (this.Parallel)
     {
         CompositeTask <T> .ExecuteInParallel(taskDictionary, taskMode);
     }
     else
     {
         CompositeTask <T> .ExecuteInSequence(taskDictionary, taskMode);
     }
 }
Ejemplo n.º 26
0
        private static void ExecuteSequentially(Dictionary <UndoableTaskBase <T>, T> taskDictionary, TaskMode taskMode)
        {
            List <UndoableTaskBase <T> > list = new List <UndoableTaskBase <T> >();

            foreach (KeyValuePair <UndoableTaskBase <T>, T> current in taskDictionary)
            {
                IInternalTask key = current.Key;
                try
                {
                    key.PerformTask(current.Value, taskMode);
                    list.Add(current.Key);
                }
                catch (Exception)
                {
                    CompositeUndoableTask <T> .SafelyUndoTasks(list.Cast <IUndoableTask>());

                    throw;
                }
            }
        }
Ejemplo n.º 27
0
        private static void ExecuteInParallel(Dictionary <TaskBase <T>, T> taskDictionary, TaskMode taskMode)
        {
            List <TaskBase <T> > performedTasks = new List <TaskBase <T> >();
            object           performedTasksLock = new object();
            List <Exception> exceptions         = new List <Exception>();
            object           exceptionsLock     = new object();
            Dictionary <KeyValuePair <TaskBase <T>, T>, AutoResetEvent> dictionary = taskDictionary.ToDictionary((KeyValuePair <TaskBase <T>, T> x) => x, (KeyValuePair <TaskBase <T>, T> x) => new AutoResetEvent(false));

            foreach (KeyValuePair <TaskBase <T>, T> current in taskDictionary)
            {
                AutoResetEvent autoResetEvent = dictionary[current];
                IInternalTask  task           = current.Key;
                TaskBase <T>   undoableTask   = current.Key;
                T arg = current.Value;
                ThreadPool.QueueUserWorkItem(delegate(object param0)
                {
                    try
                    {
                        task.PerformTask(arg, taskMode);
                        lock (performedTasksLock)
                        {
                            performedTasks.Add(undoableTask);
                        }
                    }
                    catch (Exception item)
                    {
                        lock (exceptionsLock)
                        {
                            exceptions.Add(item);
                        }
                    }
                    autoResetEvent.Set();
                });
            }
            foreach (AutoResetEvent current2 in dictionary.Values)
            {
                current2.WaitOne();
            }
            if (exceptions.Count > 0)
            {
                throw new CompositeException("Unable to undo tasks", exceptions);
            }
        }
Ejemplo n.º 28
0
 private static void ExecuteInSequence(Dictionary <TaskBase <T>, T> taskDictionary, TaskMode taskMode)
 {
     foreach (KeyValuePair <TaskBase <T>, T> current in taskDictionary)
     {
         IInternalTask key = current.Key;
         key.PerformTask(current.Value, taskMode);
     }
 }
Ejemplo n.º 29
0
 public static void ActivatePeaceMode()
 {
     _combatTasks.Clear();
     _taskMode = TaskMode.Peace;
 }
Ejemplo n.º 30
0
 internal TaskEventArgs(TArgument argument, TaskMode taskMode)
     : this(argument)
 {
     this.TaskMode = taskMode;
 }
Ejemplo n.º 31
0
 public TaskManager()
 {
     _state   = TaskManagerState.Suspended;
     _mode    = TaskMode.SearchOne;
     _results = new TaskResultCollection();
 }
Ejemplo n.º 32
0
 public TaskManager(ITaskDispatcher dispatcher, TaskMode mode)
     : this(dispatcher)
 {
     _mode = mode;
 }