public static Task <bool> UpdatePictures(int mobileIndex, string[] pictures) { if (pictures == null || pictures.Length == 0) { return(Task.FromResult(false)); } int taskNum = Guid.NewGuid().GetHashCode(); var task = new SimulationTask <bool>(taskNum, TimeoutMilliseconds * 2); if (SimulationTaskManager.RegisterSingle(task)) { var obj = new JObject() { { "tasktype", (int)TaskType.UpdatePictures }, { "txtmsg", "" }, }; var list = new JArray(); foreach (var picture in pictures) { list.Add(picture); } obj.Add("list", list); SocketServer.SendTaskInstruct(mobileIndex, (int)TaskType.UpdatePictures, taskNum, obj.ToString(Newtonsoft.Json.Formatting.None)); return(task.Task as Task <bool>); } return(Task.FromResult(false)); }
public static Task <bool> FuzzySearchClick(int mobileIndex, string id, int targetIndex = 0) { int taskNum = Guid.NewGuid().GetHashCode(); var task = new SimulationTask <bool>(taskNum, TimeoutMilliseconds); if (SimulationTaskManager.RegisterSingle(task)) { var obj = new JObject() { { "tasktype", (int)TaskType.FuzzySearchAndClick }, { "txtmsg", "" }, }; var list = new JArray(); list.Add($"{id}"); list.Add($"{targetIndex}"); obj.Add("list", list); SocketServer.SendTaskInstruct(mobileIndex, (int)TaskType.FuzzySearchAndClick, taskNum, obj.ToString(Newtonsoft.Json.Formatting.None)); return(task.Task as Task <bool>); } return(Task.FromResult(false)); }
protected override void Context() { _executionContext = A.Fake <IExecutionContext>(); _configureSimulationTask = A.Fake <IConfigureSimulationTask>(); _createSimulationPresenter = A.Fake <ICreateSimulationPresenter>(); _buildingBlockTask = A.Fake <IBuildingBlockTask>(); _simulationBuildingBlockUpdater = A.Fake <ISimulationBuildingBlockUpdater>(); _applicationController = A.Fake <IApplicationController>(); _simulationParametersToBlockUpdater = A.Fake <ISimulationParametersToBuildingBlockUpdater>(); _blockParametersToSimulationUpdater = A.Fake <IBuildingBlockParametersToSimulationUpdater>(); A.CallTo(() => _applicationController.Start <ICreateSimulationPresenter>()).Returns(_createSimulationPresenter); sut = new SimulationTask(_executionContext, _buildingBlockTask, _applicationController, _simulationBuildingBlockUpdater, _configureSimulationTask, _blockParametersToSimulationUpdater, _simulationParametersToBlockUpdater); }
/// <summary> /// Dismiss a task and therefore release the different resources used (i.e. <see cref="Crewman"/>). /// </summary> /// <param name="time">The current simulation time</param> /// <param name="phase">The current phase of the scenario</param> /// <param name="task">The task dismissed</param> public virtual void TaskDismiss(SimulationTime time, Phase phase, SimulationTask task) { var trigger = this.OnTaskAssignment != null; foreach (var crewman in task.simulationCrewmenAssigned) { Debug.Assert(task.IsAllowedTime(time), "A task must not run outside allowed daily hours!"); crewman.DismissTask(time, phase, task); if (trigger) { this.OnTaskAssignment(time, phase, crewman); } } task.simulationCrewmenAssigned.Clear(); }
public void StopSimulation() { if (!IsSimulating) { return; } lock (simulationControlLock) { if (!IsSimulating) { return; } cancellationTokenSource?.Cancel(); SimulationTask?.Wait(); IsSimulating = false; } }
public void StopSimulation() { if (!IsSimulating) { return; } lock (simulationControlLock) { if (!IsSimulating) { return; } cancellationTokenSource?.Cancel(); try { SimulationTask?.Wait(); } catch (AggregateException e) { } IsSimulating = false; } }
protected internal override SimulationTask CreateTask(int id, SimulationTask refTask, TaskLinkingType linkingType) { return(new BasicTask(id, refTask, linkingType)); }
public override SimulationTask CreateTask(SimulationTask refTask, TaskLinkingType linkingType) { return(new BasicTask(refTask, linkingType)); }
public static RelativeTimeType ParseRelativeTimeType(this XAttribute attribute) { return(SimulationTask.ParseRelativeTimeType(attribute == null ? String.Empty : attribute.Value)); }
public SimulationTaskEvent(SimulationTask task, SimulationTime time, SubtypeType eventSubtype) { this.task = task; this.time = time; this.subtype = eventSubtype; }
internal BasicTask(int id, SimulationTask refTask, TaskLinkingType linkingType = TaskLinkingType.Linked) : base(id, refTask, linkingType) { }
/// <summary> /// Attempt to assign a task to the required number of crew-members, using a score to select the most fitted crew-members. /// </summary> /// <param name="time">The current simulation time</param> /// <param name="phase">The current phase of the scenario</param> /// <param name="task">The task assigned</param> /// <param name="tasksInterruptedCallback">A delegate method to call when having to interrupt tasks occupying the resource</param> /// <returns>A Simulation time at which the task assignment will not be valid anymore, or a negative value (e.g. SimulationTime.MinValue) if the task assignment was not successful</returns> public abstract SimulationTime TaskAssignment(SimulationTime time, Phase phase, SimulationTask task, Simulator.TasksInterruptedCallback tasksInterruptedCallback);
protected void TriggerTaskAssignment(SimulationTime time, Phase phase, Crewman crewman, SimulationTask task = null) { if (this.OnTaskAssignment != null) { this.OnTaskAssignment(time, phase, crewman, task); } }
public void Dispose() { StopSimulation(); cancellationTokenSource?.Dispose(); SimulationTask?.Dispose(); }
public SimulationTaskEvent(SimulationTask task, TimeSpan time, SubtypeType eventSubtype) : this(task, SimulationTime.FromTimeSpan(time), eventSubtype) { }
public BasicTask(SimulationTask refTask, TaskLinkingType linkingType = TaskLinkingType.Linked) : base(refTask, linkingType) { }
public static ScenarioInterruptionPolicies ParseScenarioInterruptionPolicy(this XAttribute attribute) { return(SimulationTask.ParseScenarioInterruptionPolicy(attribute == null ? String.Empty : attribute.Value)); }
public static TaskDuplicatesPolicy ParseTaskDuplicatesPolicy(this XAttribute attribute) { return(SimulationTask.ParseTaskDuplicatesPolicy(attribute == null ? String.Empty : attribute.Value)); }
public override SimulationTime TaskAssignment(SimulationTime time, Phase phase, SimulationTask task, Simulator.TasksInterruptedCallback tasksInterruptedCallback) { //TODO: Implement multitasking Debug.Assert(task.IsAllowedTime(time), "Task assignment must be within allowed daily hours!"); if (task.NumberOfCrewmenNeeded == 0) { base.TriggerTaskAssignment(time, phase, null, task); return(SimulationTime.MaxValue); } var priority = task.Priority; var scores = new BinaryHeap <ScoreEntry>(); foreach (var qualification in task.simulationCurrentQualifications) { var crewman = qualification.Key; var qualificationLevel = qualification.Value; var currentPriority = crewman.TasksAssigned.Count > 0 ? crewman.TasksAssigned[0].Priority : 0; //No multitasking implemented: right now, each crewman has only 1 task at a time Debug.Assert(currentPriority <= 0 || crewman.TasksAssigned[0].simulationCrewmenAssigned.Any(cm => cm.Id == crewman.Id), "If a crewman is assigned to a task, the symetric link should also be true, i.e. the task should be assigned to the same crewman!"); if ((currentPriority == 0) || (priority / 100 > currentPriority / 100) || crewman.TasksAssigned.Contains(task)) { crewman.RefreshStatus(time); var scoreEntry = new ScoreEntry((qualificationLevel * (int)AssignmentCoefficiant.Qualification) + (crewman.CumulatedWorkTime.TotalHours * (int)AssignmentCoefficiant.CumulatedWorkHours), crewman); if (task.NumberOfCrewmenNeeded > scores.Count) { scores.Add(scoreEntry); } else if (scores.Peek().score < scoreEntry.score) { scores.Remove(); //Remove the current minimal score scores.Add(scoreEntry); } } } if (scores.Count < task.NumberOfCrewmenNeeded) { scores.Clear(); return(SimulationTime.MinValue); //The assignment was not successful } for (var i = scores.Count - 1; i >= 0; i--) { var scoreEntry = scores[i]; var crewman = scoreEntry.crewman; if (crewman.TasksAssigned.Count > 0) { var currentTasks = crewman.TasksAssigned.ToList(); tasksInterruptedCallback(currentTasks, tryAssignmentAgainNow: true); //Do not clear the crew-members assigned before calling the interruption crewman.DismissAllTasks(time, phase); //Currently not compatible with multitasking Debug.Assert(!currentTasks.Any(t => t.simulationCrewmenAssigned.Count > 0), "Nobody should remain assigned to a task that has been interrupted!"); } crewman.AssignTask(time, phase, task); task.simulationCrewmenAssigned.Add(crewman); base.TriggerTaskAssignment(time, phase, crewman, task); } scores.Clear(); return(time + assignmentExpiry); }