//public List<string> SortByDependencies(List<Job> jobs, List<string> jobNames) //{ // List<string> dependencyList = new List<string>(); // foreach (var job in jobs) // { // if (job.HasDependency) // { // if (dependencyList.Contains(job.DependencyName)) throw new // dependencyList.Add(job.DependencyName); // jobNames = ReorderList(job, jobNames); // } // } // return jobNames; //} private List<string> ReorderList(Job job, List<string> jobNames) { var positionOfJob = jobNames.IndexOf(job.Name); var positionOfDependency = jobNames.IndexOf(job.DependencyName); if (positionOfDependency > positionOfJob) { jobNames = MoveDependencyInFrontOfCurrentJob(job, jobNames, positionOfJob); } return jobNames; }
private List<string> MoveDependencyInFrontOfCurrentJob(Job job, List<string> jobNames, int positionOfJob) { jobNames.Remove(job.DependencyName); jobNames.Insert(positionOfJob, job.DependencyName); return jobNames; }