protected override void OnCreate(Bundle bundle) { SetTitle(Resource.String.fetchcallslips); SetContentView(Resource.Layout.Main); string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal); _filepath = Path.Combine(path, "CallSlips.txt"); _getDaysOnShelfFilePath = Path.Combine(path, "GetDaysOnShelf.txt"); base.OnCreate(bundle); var prefs = Application.Context.GetSharedPreferences("Violadev", FileCreationMode.Private); _isLoggedIn = prefs.GetBoolean("Authorized", false); Button buttonFetchCallSlips = FindViewById<Button>(Resource.Id.fetchCallSlipsButton); if (_isLoggedIn) { if (System.IO.File.Exists(_filepath) && _filepath != null) { SetContentView(Resource.Layout.Main); _callSlipView = FindViewById<ListView>(Resource.Id.myList); var callSlipAdapter = new CallSlipAdapter(this); _callSlipView.Adapter = callSlipAdapter; } else { GetList(); } } else { var loginActivity = new Intent(this, typeof(LogIn)); StartActivity(loginActivity); } }
//H�mtar ny list fr�n Viola async void GetList() //HandleButtonLoginClick (object sender, EventArgs e) { var prefs = Application.Context.GetSharedPreferences("Violadev", FileCreationMode.Private); var prefEditor = prefs.Edit(); bool success = false; var progressDialog = ProgressDialog.Show(this, "V�nta...", "H�mtar plocklista", true); var phoneCommunicationUrl = new System.Uri(prefs.GetString("PhoneCommunicationUrl", "")); // new System.Uri(((EditText)FindViewById<EditText>(Resource.Id.editTextPhoneCommunicationUrl)).Text); try { // Toast.MakeText(this, Dns.GetHostAddresses("violadev.sub.su.se").First().ToString(), ToastLength.Long).Show(); if (!HasInternetConnection) throw new Exception("Det saknas Internet��tkomst."); string userId = prefs.GetString("UserName", ""); //((EditText) FindViewById<EditText>(Resource.Id.editTextUserId)).Text; string password = prefs.GetString("PassWord", ""); //((EditText) FindViewById<EditText>(Resource.Id.editTextPassword)).Text; ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback((s, ce, ch, ssl) => true); using ( var handler = new HttpClientHandler { Credentials = new NetworkCredential(userId, password, "INTRANET"), ClientCertificateOptions = ClientCertificateOption.Automatic }) using (var client = new HttpClient(handler, true)) { var uri = new System.Uri(phoneCommunicationUrl, $"/api/PhoneCommunication?userid={userId}"); var result = client.GetStringAsync(uri).Result; //string result = "[{\"$type\":\"Viola.CallSlipFetching.CallSLipWithLocation, Viola\",\"AreaName\":\"�rssviten\",\"AreaId\":64,\"AreaDefaultSortOrder\":\"39\",\"CallNumberDefaultSortOrder\":\"0\",\"CallSlipId\":95136,\"SourceId\":\"DirectDelivery\",\"RequestNumber\":\"28730\",\"PatronName\":\"MEHRDAD KAVOUSI\",\"PatronEmail\":\"[email protected]\",\"PatronBarcode\":\"90002854076911\",\"ItemBarcode\":null,\"Location\":\"ARSSVIT\",\"CallNumber\":\"2015: 1.329\",\"Author\":\"Abrahamsson, Bengt, 1937-\",\"Title\":\"Avf�llingen : Lawrence efter Arabien /\",\"ISBN\":\"9789187393242\",\"ItemEnum\":null,\"ItemChronology\":null,\"Pages\":null,\"ItemYear\":\"2015\",\"CSNote\":\"\",\"StatusDescription\":null,\"DateRequested\":null,\"MFHDNote\":null,\"SeriesStatement\":null,\"SequentialDesignation\":null,\"PublicationYear\":null,\"DeliveryType\":\"Direktleverans\",\"PickupLocation\":\"Huvudbiblioteket.\",\"ResearcherAddress\":\"IT-avdelningen (biblioteket); Huvudbiblioteket, Universitetsv�gen 10 D\",\"CallNumberId\":21,\"BranchSigel\":\"H\",\"LibrisId\":0,\"Status\":\"I plocklista\",\"UserId\":\"mkavo\",\"Date\":\"2015-06-28T18:41:11.513Z\",\"PrintType\":null}]"; //client.GetStringAsync(uri).Result; string res = result.ToString(); if (res.Length > 0) { //string s = result; File.WriteAllText(_filepath, res, System.Text.Encoding.Default); prefEditor.PutBoolean("Authorized", true); //prefEditor.PutString("UserName", userId); //prefEditor.PutString("PassWord", password); //prefEditor.PutString("PhoneCommunicationUrl", phoneCommunicationUrl.OriginalString); prefEditor.Commit(); success = true; bool _isLoggedIn = prefs.Contains("Authorized"); } } GetDaysOnShelf(); // RunOnUiThread(() => Toast.MakeText(this, "Toast within progress dialog.", ToastLength.Long).Show()); //HIDE PROGRESS DIALOG } catch (Exception ee) { Toast.MakeText(this, "Fel: " + ee.Message + ee.StackTrace, ToastLength.Long).Show(); } finally { progressDialog.Hide(); if (success) { _callSlipView = FindViewById<ListView>(Resource.Id.myList); //myList => Main.axml var callSlipAdapter = new CallSlipAdapter(this); _callSlipView.Adapter = callSlipAdapter; } else { var loginActivity = new Intent(this, typeof(FetchCallSlips)); loginActivity.AddFlags(ActivityFlags.ClearTop); loginActivity.AddFlags(ActivityFlags.NewTask); loginActivity.AddFlags(ActivityFlags.ClearTask); StartActivity(loginActivity); } } }