//Durchsicht die Liste nach einem bestimmten Titel und gibt die gefilterte Liste zurück public Exams_Collection search(String text) { List <Exams_Item> list = info.list; Exams_Collection copy = new Exams_Collection(); copy.list = new List <Exams_Item>(); copy.list_data = ""; copy.list_title = "Suchergebnisse"; copy.list_title_sec = "für " + text; foreach (Exams_Item item in list) { string searchWithinThis = item.Name; searchWithinThis = searchWithinThis.ToUpper(); string searchForThis = text; searchForThis = searchForThis.ToUpper(); int firstCharacter = searchWithinThis.IndexOf(searchForThis); if (firstCharacter != -1) { copy.list.Add(item); } } return(copy); }
//Liest die Klausurenliste aus einer Datei public async Task <Exams_Collection> readList() { try { string text = await fileIO.readText("exams.json"); Exams_Collection list = JsonConvert.DeserializeObject <Exams_Collection>(text); return(list); } catch (Exception ex) { Exams_Collection nl = new Exams_Collection(); nl.list_data = "** E-01 **"; nl.list_title = "Fehler"; List <Exams_Item> li = new List <Exams_Item>(); Exams_Item xi = new Exams_Item(); xi.Name = "Aktualisierung notwendig"; xi.Place = ""; xi.Time = ""; xi.Extra = ""; xi.change = "Es sind keine Offlinedaten verfügbar. Zum Abrufen der Daten auf 'Aktualisieren' drücken."; li.Add(xi); nl.list = li; return(nl); } }
//Gibt die vollständige Liste sortiert nach Namen zurück public Exams_Collection getDisplayListByName() { Exams_Collection exi = info; exi.list.Sort((s1, s2) => s1.Name.CompareTo(s2.Name)); info.list_title_sec = ""; return(exi); }
public async Task <bool> update() { Exams_Collection tempList = await ex.downloadList(); if (tempList.list.Count != 0) { ex.writeList(tempList); info = tempList; return(true); } else { return(false); } }
//Initialisiert die Liste mit den gespeicherten Werten public async Task init(API_InternalFile fio) { ex.fileIO = fio; info = await ex.readList(); }
public async Task <Exams_Collection> downloadList() { Exams_Collection ei = new Exams_Collection(); ei.list_data = "** E-02 **"; ei.list_title = "Fehler"; List <Exams_Item> li = new List <Exams_Item>(1000); ei.list = li; try { HttpClientHandler handler = new HttpClientHandler(); var cookieContainer = new CookieContainer(); handler.CookieContainer = cookieContainer; HttpClient client = new HttpClient(handler); HttpResponseMessage response = await client.GetAsync(new Uri("https://intranet.tuhh.de/stud/pruefung/index.php3")); var htxt = await response.Content.ReadAsStringAsync(); HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument(); htmlDoc.OptionFixNestedTags = true; //HTML aus String laden htmlDoc.LoadHtml(htxt); if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() > 0) { } else { foreach (HtmlNode cols in htmlDoc.DocumentNode.Descendants("h2")) { String rawString = WebTools.removeHTML(cols.InnerText); Char delimiter = ':'; String[] substrings = rawString.Split(delimiter); ei.list_title = substrings[1]; } foreach (HtmlNode table in htmlDoc.DocumentNode.Descendants("tbody")) { foreach (HtmlNode row in table.Descendants("tr")) { List <string> facts = new List <string>(); foreach (HtmlNode cell in row.Descendants("td")) { facts.Add(cell.InnerHtml); } if (facts.Count >= 4) { Exams_Item x = new Exams_Item(); String blank = facts[2]; String[] split = blank.Split(new string[] { "<br>" }, StringSplitOptions.None); x.Time = WebTools.removeHTML(facts[1]); x.Name = WebTools.removeHTML(facts[0]); x.Extra = WebTools.removeHTML(split[0]); x.Note = WebTools.removeHTML(facts[3]); if (split.Length > 1) { x.change = WebTools.removeHTML(split[1]); } else { x.change = ""; } li.Add(x); } } } DateTime now = DateTime.Today; String dateString = now.Day + "." + now.Month + "." + now.Year; ei.list_data = dateString; ei.list_time_download = DateTime.Today; } } catch { } return(ei); }
//Schreib die Klausurenliste in eine Datei public async void writeList(Exams_Collection list) { string json = JsonConvert.SerializeObject(list, Formatting.Indented); await fileIO.writeText("exams.json", json); }