/// <summary> /// Removes every task after the Tasks list /// </summary> /// <param name="job">Respective job the tasks have to deleted from</param> /// <param name="index">The index after the job should be deleted after</param> private static void RemoveTasksAfterIndex(Data.Entity.Job job, int index) { if (index < job.Tasks.Count - 1) { job.Tasks.RemoveRange(index + 1, job.Tasks.Count - (index + 1)); } }
/// <summary> /// Insert a task right after a index in the Tasks list or add in the end /// </summary> /// <param name="job">Referenced job to be considered with</param> /// <param name="index">Index the the new task will be inserted after if possible</param> /// <param name="newDeliveryTask">New task to insert</param> private static void InsertTaskIntoTaskChain(Data.Entity.Job job, int index, DeliveryTask newDeliveryTask) { // First, making sure there are no retry tasks after this. // The reason we are doing this is since someone might make the initial delivery task // set to in progress after he set it to returned or failed which will end in a // sticky situation var tasksToDelete = new List <JobTask>(); for (int i = index + 1; i < job.Tasks.Count; i++) { if (job.Tasks[i].Type == JobTaskTypes.DELIVERY && job.Tasks[i].Variant == DeliveryTaskVariants.Retry) { tasksToDelete.Add(job.Tasks[i]); } } foreach (var task in tasksToDelete) { job.Tasks.Remove(task); } if (index < job.Tasks.Count - 1) { // this means this task is not a terminating task job.Tasks[index + 1].SetPredecessor(newDeliveryTask, validateDependency: false); // Push the job after the delivery task itself. job.AddTask(newDeliveryTask, index + 1, hookPropertyChangedEvent: true); } else { // This was the last job task, so just adding the new task will suffice job.AddTask(newDeliveryTask, hookPropertyChangedEvent: true); job.TerminalTask = newDeliveryTask; } }