public void WaitForStart() { ScheduleTask t = this; while (true) { ScheduleActivity ac = t.Activities[0]; bool canStart = true; foreach (LinkedListNode <UnitReservation> ur in ac.UnitReservations) { if (ur.Previous != null && (ur.Previous.Value.Activity.Status != Status.Cancelled && ur.Previous.Value.Activity.Status != Status.Processed && ur.Previous.Value.Activity.WaitingForCompleted != true)) { canStart = false; } } foreach (ScheduleTask pt in t.TasksRunAfterEnd) { if (pt.Status != Status.Processed && pt.Status != Status.Cancelled) { canStart = false; } } foreach (ScheduleTask pt in t.TasksRunAfterStart) { if (pt.Status == Status.Scheduled) { canStart = false; } } if (Scheduler.CurrentExecuteTime < t.Activities[0].PlannedStart || Scheduler.IsRunning == false) { canStart = false; } if (canStart) { break; } else { Thread.Sleep(600); } } Status = Status.Running; FireTaskStarted(this, new TaskEventArg(this)); }
public void FreeUnits(int[] units, ScheduleTask task, ScheduleActivity activity) { for (int i = 0; i < units.Length; i++) { if (_unitStatus[units[i]] != false) { throw new Exception(string.Format("task {2} activity {3} resource {0} unit {1} is not in useing", Name, units[i], activity.Task.ID, activity.Name)); } _unitStatus[units[i]] = true; lockedBy.Remove(units[i]); } if (ResourceFreed != null) { for (int i = 0; i < units.Length; i++) { ResourceFreed(this, new ResourceEventArgs(Name, units[i], true, task, activity)); } } }
//runtime public bool LockUnits(int[] units, ScheduleTask task, ScheduleActivity activity) { for (int i = 0; i < units.Length; i++) { if (_unitStatus[units[i]] != true) { throw new Exception(string.Format("task {2} activity {3} resource {0} unit {1} is in using", Name, units[i], activity.Task.ID, activity.Name)); } _unitStatus[units[i]] = false; lockedBy[units[i]] = activity; } if (ResourceLocked != null) { for (int i = 0; i < units.Length; i++) { ResourceLocked(this, new ResourceEventArgs(Name, units[i], false, task, activity)); } } return(true); }
//Добавление события в планировщик, сортировка по начальному времени public void AddEvent(ScheduleTask note) { bool eventAdded = false; if (notes.Count > 0) { for (int i = 0; i < notes.Count; i++) { if (notes[i].BeginTime > note.BeginTime) { notes.Insert(i, note); eventAdded = true; break; } } } if (!eventAdded) { notes.Add(note); } }
public ResourceEventArgs(string name, int unit, bool free, ScheduleTask task, ScheduleActivity activity) { _name = name; _unit = unit; _isFree = free; }
public TaskEventArg(ScheduleTask task) { Task = task; }
//обновление информации о записи public void UpdateEvent(int position, ScheduleTask scheduleTask) { notes.RemoveAt(position); AddEvent(scheduleTask); }
public RuntimeTask(ScheduleTask t) { _task = t; }
public TaskExecuter(Scheduler scheduler, ScheduleTask task) { _task = task; _scheduler = scheduler; }