//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); } }
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); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetTheme(Resource.Style.MyTheme); Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); SetContentView(Resource.Layout.Form_Exams); drawerLayout = FindViewById <DrawerLayout>(Resource.Id.drawer_layout); toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); Android.Support.V7.App.ActionBar actionBar = this.SupportActionBar; var navigationView = FindViewById <NavigationView>(Resource.Id.nav_view); navigationView.NavigationItemSelected += NavigationView_NavigationItemSelected; navigationView.SetCheckedItem(Resource.Id.nav_exams); var drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, Resource.String.open_drawer, Resource.String.close_drawer); drawerLayout.SetDrawerListener(drawerToggle); drawerToggle.SyncState(); listView = FindViewById <ListView>(Resource.Id.List); Campus_Harburg_Core.Exams_Item xi = new Campus_Harburg_Core.Exams_Item(); xi.Name = "Laden..."; xi.Note = "Daten werden verarbeitet"; xi.Time = ""; Campus_Harburg_Core.Exams_P exa = new Campus_Harburg_Core.Exams_P(); ep.init(fio); Exams_Collection exi = ep.getDisplayList(); exi.list.Sort((s1, s2) => s1.Name.CompareTo(s2.Name)); tableItems.Add(xi); listView.Adapter = new ListAdapter_Exams(this, exi.list); int dayDif = (DateTime.Now - exi.list_time_download).Days; if (dayDif >= 30 && exi.list.Count >= 2) { Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(this); alert.SetTitle("Info"); alert.SetMessage(TextContainer.Exams_TooOld); alert.SetPositiveButton("Ja", (senderAlert, args) => { update(); }); alert.SetNegativeButton("Nein", (senderAlert, args) => { }); Dialog dialog = alert.Create(); dialog.Show(); } else if (exi.list.Count < 2) { Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(this); alert.SetTitle("Info"); alert.SetMessage(TextContainer.Exams_Empty); alert.SetPositiveButton("Ja", (senderAlert, args) => { update(); }); alert.SetNegativeButton("Nein", (senderAlert, args) => { }); Dialog dialog = alert.Create(); dialog.Show(); } }