private void StopCompletedJobs() { for (int i = 0; i < ActiveJobs.Count; i++) { var job = ActiveJobs[i]; if (job.GetCompletionPercentage() >= 1.0f) { Money += job.Job.Job.OfferedReward; var finalDestination = job.Job.Job.To; var finalPlace = WorldState.GetStateForPlace(job.Job.Job.To); job.Job.Job.JobWasCompletedSuccesfully(); // Stay at location if owned + setting to stay there is enabled, or if it is the original location. // else return to original location. if (WorldState.PlaceOwned(finalDestination) && (job.Assignment.StayAtLocation || job.Employee.OriginalLocation == finalDestination)) { ActiveJobs.RemoveAt(i); i--; // Employee is now in the employee list of the destination place. job.Employee.CurrentJob = null; finalPlace.AddEmployee(job.Employee); continue; } else { ActiveJobs.RemoveAt(i); i--; // If the final stop place is not owned, make driver go back to original location. var scheduledJob = new ScheduledJob(job.Job.Job.Reverse(), job.Job.ShipTimes); ActiveJob returnJob = new ActiveJob(scheduledJob, job.Assignment, GetNextLeavingTimeslot(), job.Employee); job.Employee.CurrentJob = returnJob; ActiveJobs.Add(returnJob); finalPlace.EmployeeStateChanged(); continue; } } } }
public void AddJob(string jobName, JobTask job) { lock (JobLock) { bool needSignal = false; if (State == DispatcherState.Running) { needSignal = JobList.Count == 0; job.JobName = jobName; ActiveJobs.Add(jobName); JobList.Add(job); } if (needSignal) { Monitor.Pulse(JobLock); } } }
private void StartJob(PlaceState place, ShipTimeAssignment assignee, ScheduledJob job) { if (!place.Employees.Contains(assignee.AssignedEmployee)) { job.Job.JobWasCompletedUnsuccesfully(); MessageLog.AddError(string.Format("{0} {1} missed their trip to {2} from {3} at {4}", assignee.AssignedEmployee.Name, assignee.AssignedEmployee.Id, job.Job.To.Name, job.Job.From.Name, assignee.Time.ToString("h':'m''"))); return; } var employee = assignee.AssignedEmployee; if (employee.AssignedTruck == null) { MessageLog.AddError(string.Format("{0} {1} does not have a truck to drive to {2} from {3} at {4}", assignee.AssignedEmployee.Name, assignee.AssignedEmployee.Id, job.Job.To.Name, job.Job.From.Name, assignee.Time.ToString("h':'m''"))); return; } if (employee.CurrentJob == null) { employee.CurrentLocation = null; place.Employees.Remove(assignee.AssignedEmployee); var activeJob = new ActiveJob(job, assignee, Time - TimeSpan.FromMinutes(Time.Minute % 15), employee); Money -= activeJob.GasPrice(); employee.CurrentJob = activeJob; ActiveJobs.Add(activeJob); MessageLog.AddInfo(string.Format("{0} left {1}, driving to {2}", assignee.AssignedEmployee.Name, job.Job.From.Name, job.Job.To.Name)); } }
public IDEAQueryExecuter() { var stream = Observable.FromEventPattern <ExecuteOperationModelEventArgs>(this, "ExecuteQueryEvent"); stream.GroupByUntil(k => k.EventArgs.OperationModel, g => Observable.Timer(TimeSpan.FromMilliseconds(50))) .SelectMany(y => y.FirstAsync()) .Subscribe(async arg => { var dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher; await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { var operationModel = arg.EventArgs.OperationModel; operationModel.ResultCauserClone = operationModel.Clone(); operationModel.Result = null; if (ActiveJobs.ContainsKey(operationModel) && arg.EventArgs.StopPreviousExecution) { foreach (var executionId in ActiveJobs[operationModel].Keys) { ActiveJobs[operationModel][executionId].Stop(); ActiveJobs[operationModel][executionId].JobUpdate -= job_JobUpdate; ActiveJobs[operationModel][executionId].JobCompleted -= job_JobCompleted; } ActiveJobs.Remove(operationModel); } // determine if new job is even needed (i.e., are all relevant inputfieldmodels set) OperationJob newJob = null; if (operationModel is HistogramOperationModel) { var histogramOperationModel = (HistogramOperationModel)operationModel; if (((histogramOperationModel.VisualizationType == VisualizationType.table) && (histogramOperationModel.AttributeTransformationModels.Count > 0)) || ((histogramOperationModel.VisualizationType != VisualizationType.table) && histogramOperationModel.GetAttributeUsageTransformationModel(AttributeUsage.X).Any() && histogramOperationModel.GetAttributeUsageTransformationModel(AttributeUsage.Y).Any())) { newJob = new HistogramOperationJob( histogramOperationModel, TimeSpan.FromMilliseconds(MainViewController.Instance.MainModel.ThrottleInMillis), (int)MainViewController.Instance.MainModel.SampleSize); } } else if (operationModel is StatisticalComparisonOperationModel) { var statisticalComparisonOperationModel = (StatisticalComparisonOperationModel)operationModel; newJob = new StatisticalComparisonOperationJob( statisticalComparisonOperationModel, TimeSpan.FromMilliseconds(MainViewController.Instance.MainModel.ThrottleInMillis), (int)MainViewController.Instance.MainModel.SampleSize); } else if (operationModel is ExampleOperationModel) { var exampleOperationModel = (ExampleOperationModel)operationModel; newJob = new ExampleOperationJob( exampleOperationModel, TimeSpan.FromMilliseconds(MainViewController.Instance.MainModel.ThrottleInMillis), (int)MainViewController.Instance.MainModel.SampleSize); } else if (operationModel is RiskOperationModel) { var riskOperationModel = (RiskOperationModel)operationModel; newJob = new RiskOperationJob( riskOperationModel, TimeSpan.FromMilliseconds(MainViewController.Instance.MainModel.ThrottleInMillis)); } else if (operationModel is StatisticalComparisonDecisionOperationModel) { var riskOperationModel = (StatisticalComparisonDecisionOperationModel)operationModel; newJob = new StatisticalComparisonDecisionOperationJob( riskOperationModel, TimeSpan.FromMilliseconds(MainViewController.Instance.MainModel.ThrottleInMillis)); } if (newJob != null) { if (!ActiveJobs.ContainsKey(operationModel)) { ActiveJobs.Add(operationModel, new Dictionary <int, OperationJob>()); } ActiveJobs[operationModel][operationModel.ExecutionId] = newJob; newJob.JobUpdate += job_JobUpdate; newJob.JobCompleted += job_JobCompleted; newJob.Start(); } }); }); }