public void Thread_Assignation(Shifts shift) { JObject envoie_json = new JObject( new JProperty("user_id", int.Parse(info_utilisateur.Id)), new JProperty("do", "assign")); var request = new RestRequest("shifts/" + shift.Id + "/applications.json", Method.POST); request.AddHeader("Content-type", "application/json"); request.AddHeader("User-Agent", user_agent); request.RequestFormat = DataFormat.Json; request.AddParameter("application/json", envoie_json, ParameterType.RequestBody); var response = client.Execute(request); JObject o = JObject.Parse(response.Content); if (o["errors"] == null && (string)o["state"] == "assigned") { Inscription ajout = new Inscription(); ajout.Debut = (DateTime)o["shift_starts_at"]; ajout.Fin = (DateTime)o["shift_ends_at"]; ajout.Temps = ajout.Fin - ajout.Debut; list_incriptions.Add(ajout); } }
public bool Check_Shift_In_Interval(Shifts shift, List <Time_Interval> list_interval) { foreach (Time_Interval caca in list_interval) { if (caca.Debut <= shift.Debut && caca.Fin >= shift.Fin) { return(true); } } return(false); }
public bool Chevauchement_Shift(Shifts shift_1, Shifts shift_2) { if (shift_1.Debut < shift_2.Debut && shift_1.Fin > shift_2.Debut) { return(true); } if (shift_1.Fin > shift_2.Debut && shift_1.Fin < shift_2.Debut) { return(true); } if (shift_1.Debut >= shift_2.Debut && shift_1.Fin <= shift_2.Fin) { return(true); } if (shift_1.Debut <= shift_2.Debut && shift_1.Fin >= shift_2.Fin) { return(true); } return(false); }
public void Shift_API_Thread(string URI) { 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); 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); shiftComplet = false; } } } catch (Exception) { } } } }
public void inscriptionShift(Shifts shift) { IWebElement shiftElement = driver.FindElement(By.CssSelector("." + shift.id)); shiftElement.Click(); WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(120)); try { wait.Until <IWebElement>(ExpectedConditions.ElementToBeClickable(By.Id("applied-users"))); if (driver.FindElements(By.CssSelector(".action-assign")).Count > 0) { IWebElement assignButton = driver.FindElement(By.CssSelector(".action-assign")); assignButton.Click(); wait = new WebDriverWait(driver, TimeSpan.FromSeconds(120)); wait.Until <IWebElement>(ExpectedConditions.ElementToBeClickable(By.CssSelector(".close"))); } while (driver.FindElements(By.CssSelector(".close")).Count > 0) { IWebElement closeButton = driver.FindElement(By.CssSelector(".close")); closeButton.Click(); } } catch (Exception) { IWebElement closeButton = driver.FindElement(By.CssSelector(".close")); closeButton.Click(); } wait = new WebDriverWait(driver, TimeSpan.FromSeconds(120)); wait.Until(ExpectedConditions.PresenceOfAllElementsLocatedBy(By.CssSelector(".shift"))); Thread.Sleep(TimeSpan.FromSeconds(0.3)); }
//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); }