public void SubmitTask() { int taskId = _rnd.Next(10000); string taskName = $"({taskId} for {Name})"; DeveloperTask newTask = new DeveloperTask(taskName); if (TaskExecutor != null) { TaskExecutor.AddTask(newTask); DeveloperTasks.Add(newTask); } }
public void ChangePriority() { if (DeveloperTasks.Count > 0) { int taskIndex = _rnd.Next(0, DeveloperTasks.Count - 1); DeveloperTask checkTask = DeveloperTasks[taskIndex]; // make those developers work faster on some random task! if (TaskExecutor != null) { TaskExecutor.IncreasePriority(checkTask.Name); Console.WriteLine($"{Name} intervened and changed priority for task {checkTask.Name}"); } } }
public void CheckTaskStatus() { if (DeveloperTasks.Count > 0) { int taskIndex = _rnd.Next(0, DeveloperTasks.Count - 1); DeveloperTask checkTask = DeveloperTasks[taskIndex]; if (TaskExecutor != null && TaskExecutor.IsTaskDone(checkTask.Name)) { Console.WriteLine($"Task {checkTask.Name} is done for {Name}"); // remove it from the todo list DeveloperTasks.Remove(checkTask); } } }
private void ExecuteTask() { // look over the tasks and do the highest priority var queryResult = from t in DeveloperTasks where t.Status == false orderby t.Priority select t; if (queryResult.Count <DeveloperTask>() > 0) { // do the task DeveloperTask task = queryResult.First <DeveloperTask>(); task.Status = true; task.Priority = -1; Console.WriteLine($"Task {task.Name} executed by developer."); } }
/// <summary> /// Allows people to check if the task is done /// </summary> /// <param name="taskName">name of the task</param> /// <returns>False if the taks is undone or not in the list, true if done</returns> public bool IsTaskDone(string taskName) { try { Lock.EnterReadLock(); var taskQuery = from t in DeveloperTasks where t.Name == taskName select t; if (taskQuery.Count <DeveloperTask>() > 0) { DeveloperTask task = taskQuery.First <DeveloperTask>(); Console.WriteLine($"Task {task.Name} status was reported."); return(task.Status); } } finally { Lock.ExitReadLock(); } return(false); }
public void AddTask(DeveloperTask newTask) { try { Lock.EnterWriteLock(); // if we already have this task (unique by name) // then just accept the add as sometimes people // give you the same task more than once :) var taskQuery = from t in DeveloperTasks where t == newTask select t; if (taskQuery.Count <DeveloperTask>() == 0) { Console.WriteLine($"Task {newTask.Name} was added to developer"); DeveloperTasks.Add(newTask); } } finally { Lock.ExitWriteLock(); } }
/// <summary> /// Increase the priority of the task /// </summary> /// <param name="taskName">name of the task</param> public void IncreasePriority(string taskName) { try { Lock.EnterUpgradeableReadLock(); var taskQuery = from t in DeveloperTasks where t.Name == taskName select t; if (taskQuery.Count <DeveloperTask>() > 0) { DeveloperTask task = taskQuery.First <DeveloperTask>(); Lock.EnterWriteLock(); task.Priority++; Console.WriteLine($"Task {task.Name}" + $" priority was increased to {task.Priority}" + " for developer"); Lock.ExitWriteLock(); } } finally { Lock.ExitUpgradeableReadLock(); } }
public override bool Equals(object obj) { DeveloperTask task = obj as DeveloperTask; return(this.Name == task?.Name); }