//return si il y a les header page ou non public Shift_API_return Get_Shift_API(string URI) { Shift_API_return apiReturn = new Shift_API_return(); int page = -1; int pages = -1; RestRequest request; request = new RestRequest(URI, Method.GET); request.AddHeader("Content-type", "application/json"); request.AddHeader("User-Agent", user_agent); request.RequestFormat = DataFormat.Json; var response = client.Execute(request); foreach (var param in response.Headers) { if (param.Name == "Page") { page = int.Parse(param.Value.ToString()); } else if (param.Name == "Pages") { pages = int.Parse(param.Value.ToString()); } } if (page > 0 && pages > 0) { apiReturn.presenceHeaderPage = true; apiReturn.pagesMax = pages; } Ajout_Log("Nombre pages shifts: " + pages); JArray obj = JArray.Parse(response.Content); if (obj.Count > 0) { foreach (JObject o in obj.Children <JObject>()) { Shifts ajout = new Shifts(); try { ajout.Id = (string)o["id"]; ajout.Full = (bool)o["full"]; ajout.Debut = (DateTime)o["starts_at"]; ajout.Fin = (DateTime)o["ends_at"]; if (gestion_interval.Check_Shift_In_Interval(ajout, listInterval) && !ajout.Full) { if (!list_shifts.Exists(x => x.Id == ajout.Id)) { list_shifts.Add(ajout); apiReturn.shiftComplet = false; } } } catch (Exception) { Ajout_Log("Erreur probleme shift API"); } } } else { apiReturn.finPage = true; Ajout_Text(false, "Tout les shifts recupérés"); } return(apiReturn); }
public void Get_Shifts() { Ajout_Log("Lancement méthode get shift"); tempsGetShifts = Stopwatch.StartNew(); shiftComplet = true; bool scheduleFounded = false; if (sub_ok) { try { list_shifts = new List <Shifts>(); for (int i = 0; i < bloc_location.list_fenetre.Count; i++) { if (bloc_location.list_fenetre[i].recherche_en_cours && bloc_location.list_fenetre[i].schedule != null) { Ajout_Text(false, "Recuperation des shifts en cours"); listInterval = gestion_interval.Set_List_Interval_User(bloc_location.list_fenetre[i], list_incriptions); bool finPage = false; int currentPageApi = 1; scheduleFounded = true; Shift_API_return apiInfos = Get_Shift_API("schedules/" + bloc_location.list_fenetre[i].schedule.Id + "/shifts.json" + String_Department_API(bloc_location.list_fenetre[i]) + "&page=" + currentPageApi); currentPageApi++; if (shiftComplet && !apiInfos.shiftComplet) { shiftComplet = false; } finPage = apiInfos.finPage; if (apiInfos.presenceHeaderPage) { if (apiInfos.pagesMax > 1) { Ajout_Log("Lancement des threads shifts, nombre : " + (apiInfos.pagesMax - 1)); Thread[] arrayThreads = new Thread[apiInfos.pagesMax - 1]; for (int j = 0; j < arrayThreads.Length; j++) { String p = currentPageApi.ToString(); arrayThreads[j] = new Thread(() => Shift_API_Thread("schedules/" + bloc_location.list_fenetre[i].schedule.Id + "/shifts.json" + String_Department_API(bloc_location.list_fenetre[i]) + "&page=" + p)); arrayThreads[j].Start(); currentPageApi++; } bool threadRunning = true; while (threadRunning) { foreach (Thread t in arrayThreads) { if (t.IsAlive) { threadRunning = true; break; } else { threadRunning = false; } } } } Ajout_Text(false, "Tout les shifts recupérés"); } else { while (!finPage) { apiInfos = Get_Shift_API("schedules/" + bloc_location.list_fenetre[i].schedule.Id + "/shifts.json" + String_Department_API(bloc_location.list_fenetre[i]) + "&page=" + currentPageApi); currentPageApi++; if (shiftComplet && !apiInfos.shiftComplet) { shiftComplet = false; } finPage = apiInfos.finPage; } } break; } else if (bloc_location.list_fenetre[i].recherche_en_cours) { Ajout_Text(false, "Pas de planning pour " + bloc_location.list_fenetre[i].location.Name); } } } catch { Ajout_Text(false, "Probleme de connexion"); } } else { Ajout_Text(false, "Vous etes pas abonné, nous ne pouvons pas vous inscrire"); } tempsGetShifts.Stop(); if (shiftComplet && scheduleFounded) { procedureShiftsComplet = true; Ajout_Text(false, "Tout les shifts sont complets - Fin de la procédure d'inscription"); } if (scheduleFounded) { Bilan_Log_Shifts_Get(); Ajout_Text(false, "Temps recuperation shifts : " + tempsGetShifts.ElapsedMilliseconds.ToString() + " ms"); } }