//Thread de gestion de l'optimisation et de l'inscription pour 1 jour public void Thread_Jour_Assignation(List <Shifts> listShifts, int day) { List <Shifts> listShiftsDay = new List <Shifts>(listShifts); while (listShiftsDay.Count > 0) { //Determine les shifts a assigner List <Shifts> shiftSansDoublonsHeure = Get_List_Shifts_Sans_Doublons_Horaires(listShiftsDay); if (shiftSansDoublonsHeure.Count > 10) { shiftSansDoublonsHeure.RemoveRange(10, shiftSansDoublonsHeure.Count - 10); } Day_Optimisation dayOptimisation = new Day_Optimisation(shiftSansDoublonsHeure); List <Shifts> listShiftsToAssign = dayOptimisation.Get_Best_Combinaison(); foreach (Shifts shift in listShiftsToAssign) { listShiftsDay.Remove(shift); } //Inscription Thread[] arrayThreads = new Thread[listShiftsToAssign.Count]; for (int i = 0; i < arrayThreads.Length; i++) { arrayThreads[i] = new Thread(() => Thread_Assignation(listShiftsToAssign[i])); arrayThreads[i].Start(); } bool threadRunning = true; while (threadRunning) { foreach (Thread t in arrayThreads) { if (t.IsAlive) { threadRunning = true; break; } else { threadRunning = false; } } } //Reduction des Interval de temps + shifts lock (listInterval) { listInterval = gestion_interval.Change_List_Interval_Inscription(listInterval, list_incriptions); listInterval = gestion_interval.Epuration_List_Interval_Day(listShiftsDay, listInterval, day); } listShiftsDay = gestion_interval.Epuration_List_Shifts_Day(listShiftsDay, listInterval); } }
public void PlanningPage() { while (!isPlanningPublish()) { ; } //page chargée while (listInterval.Count > 0) { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(120)); wait.Until(ExpectedConditions.PresenceOfAllElementsLocatedBy(By.CssSelector(".ccc-event-header"))); List <IWebElement> listDepartement = getListDepartmentWanted(); List <Shifts> listShifts = ExtractListShiftsFromDepartment(listDepartement); listInterval = gestionInterval.Change_List_Interval_Inscription(listInterval, listInscription); listInterval = gestionInterval.Change_List_Interval_Inscription(listInterval, listInscription); listInterval = gestionInterval.Epuration_List_Interval(listShifts, listInterval); listShifts = gestionInterval.Epuration_List_Shifts(listShifts, listInterval); if (listShifts.Count > 0) { List <Shifts> shiftSansDoublonsHeure = Get_List_Shifts_Sans_Doublons_Horaires(listShifts); List <List <Shifts> > listShiftsJour = GetListShiftsJour(shiftSansDoublonsHeure); List <Shifts> listShiftsToAssign = new List <Shifts>(); foreach (List <Shifts> listShiftDay in listShiftsJour) { List <Shifts> listOrdered = listShiftDay.OrderByDescending(x => x.Get_Duree_Minutes()).ToList(); if (listOrdered.Count > 10) { listOrdered.RemoveRange(10, listOrdered.Count - 10); } Day_Optimisation dayOptimisation = new Day_Optimisation(listOrdered); listShiftsToAssign.AddRange(dayOptimisation.Get_Best_Combinaison()); } foreach (Shifts s in listShiftsToAssign) { inscriptionShift(s); } } } }