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; } }
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()); }
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); }
/// <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); }
public Task() { _pTasks = null; _iTask = -1; _pTaskParent = null; _iMode = TaskMode.TaskMode_ST; }
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); }
public TaskRunner(TaskMode Mode) { mode = Mode; if (mode == TaskMode.AsynchronousHighPriority) { signal = new AutoResetEvent(false); thread = new Thread(TaskLoop); thread.Start(); } }
/// <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); }
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); }
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; } }
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; }
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); }
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)); } } }
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); } }
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)); } }
internal UndoableTaskEventArgs(TArgument argument, TaskMode taskMode) : base(argument, taskMode) { }
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; } } }
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); }
/// <summary> /// 带狗粮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgl_check(object sender, RoutedEventArgs e) { dxc.IsChecked = false; TaskMode = TaskMode.DGL; }
public TaskModeEventArgs(StutterTask task, TaskMode mode) { Task = task; Mode = mode; }
public Assignment(TaskMode m, DirectoryInfo source, DirectoryInfo target) { this.Mode = m; this.Source = source; this.Target = target; }
internal TaskResult PerformTask(object argument, TaskMode taskMode) { return(((IInternalTask)this).PerformTask(argument, taskMode)); }
/// <summary> /// 地下城 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dxc_check(object sender, RoutedEventArgs e) { dgl.IsChecked = false; TaskMode = TaskMode.DXC; }
public TaskModeManager(TaskMode mode) { _mode = mode; }
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); } }
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; } } }
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); } }
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); } }
public static void ActivatePeaceMode() { _combatTasks.Clear(); _taskMode = TaskMode.Peace; }
internal TaskEventArgs(TArgument argument, TaskMode taskMode) : this(argument) { this.TaskMode = taskMode; }
public TaskManager() { _state = TaskManagerState.Suspended; _mode = TaskMode.SearchOne; _results = new TaskResultCollection(); }
public TaskManager(ITaskDispatcher dispatcher, TaskMode mode) : this(dispatcher) { _mode = mode; }