This commit is contained in:
2024-10-13 16:34:46 +02:00
parent b6755ae77f
commit d7d7db8dd4
12 changed files with 140 additions and 85 deletions

View File

@@ -18,11 +18,13 @@ internal class Stunde : ObservableObject {
public static async Task<Hours> LoadData() {
Preferences.Default.Set("apiKey", "NXw5NDdCcEdLMVNDZTRENmphWG02MjlyeFFDenN8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp");
Preferences.Default.Set("name", "Johannes");
Preferences.Default.Set("surname", "Fink");
Preferences.Default.Set("EmployeeId", 5);
Preferences.Default.Set("apiUrl", "http://hours.dauni.mine.nu:81/appapi");
////Preferences.Default.Set("apiKey", "NXw5NDdCcEdLMVNDZTRENmphWG02MjlyeFFDenN8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp");
//Preferences.Default.Set("apiKey", "NXw5NDdCcEdLMVNDZTRENmphWG02MjlyeFFDenN8aHR0cHM6Ly9zdHVuZGVuLmpkLWxhbmEtdGlzZW5zLml0L2FwcGFwaQ==");//Online
//Preferences.Default.Set("name", "Johannes");
//Preferences.Default.Set("surname", "Fink");
//Preferences.Default.Set("EmployeeId", 5);
////Preferences.Default.Set("apiUrl", "http://hours.dauni.mine.nu:81/appapi");
//Preferences.Default.Set("apiUrl", "https://stunden.jd-lana-tisens.it/appapi");
apiKey = Preferences.Default.Get("apiKey", "NXw5NDdCcEdLMVNDZTRENmphWG02MjlyeFFDenN8aHR0cDovL2hvdXJzLmRhdW5pLm1pbmUubnU6ODEvYXBwYXBp");
EmployeeId = Preferences.Default.Get("employeeId", 5);
@@ -38,14 +40,15 @@ internal class Stunde : ObservableObject {
Hours hours = new Hours();
if (Connectivity.Current.NetworkAccess == NetworkAccess.None) {
await App.Current.MainPage.DisplayAlert("Keine Internetverbindung",
"Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.",
"OK");
throw new Exception("Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.");
//await App.Current.MainPage.DisplayAlert("Keine Internetverbindung",
// "Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.",
// "OK");
} else {
var tokendata = new TokenData(apiKey);
//string data = await Auth.GetApiDataWithAuthAsync(requestUrl, apiKey);
string data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?hours", tokendata.apiKey);
string? data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?hours", tokendata.apiKey);
if (data == "null") {
throw new Exception("Keine Daten erhalten");
@@ -54,7 +57,10 @@ internal class Stunde : ObservableObject {
throw new Exception("Problem mit Token");
}
hours = JsonConvert.DeserializeObject<Hours>(data);
if (data == null) {
throw new Exception("Keine Daten erhalten");
}
hours = JsonConvert.DeserializeObject<Hours>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
}
return hours;
@@ -70,13 +76,14 @@ internal class Stunde : ObservableObject {
Hours hours = new Hours();
if (Connectivity.Current.NetworkAccess == NetworkAccess.None) {
await App.Current.MainPage.DisplayAlert("Keine Internetverbindung",
"Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.",
"OK");
throw new Exception("Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.");
//await App.Current.MainPage.DisplayAlert("Keine Internetverbindung",
// "Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.",
// "OK");
} else {
var tokendata = new TokenData(apiKey);
string data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?basic", tokendata.apiKey);
string? data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?basic", tokendata.apiKey);
if (data == "null") {
throw new Exception("Keine Daten erhalten");
@@ -84,8 +91,10 @@ internal class Stunde : ObservableObject {
if (data == "\"Lalala\"") {
throw new Exception("Problem mit Token");
}
hours = JsonConvert.DeserializeObject<Hours>(data);
if (data == null) {
throw new Exception("Keine Daten erhalten");
}
hours = JsonConvert.DeserializeObject<Hours>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
}
return hours;
@@ -105,14 +114,15 @@ internal class Stunde : ObservableObject {
List<DayTime> daytimes = new List<DayTime>();
if (Connectivity.Current.NetworkAccess == NetworkAccess.None) {
await App.Current.MainPage.DisplayAlert("Keine Internetverbindung",
"Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.",
"OK");
throw new Exception("Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.");
//await App.Current.MainPage.DisplayAlert("Keine Internetverbindung",
// "Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.",
// "OK");
} else {
var tokendata = new TokenData(apiKey);
//string data = await Auth.GetApiDataWithAuthAsync(requestUrl, apiKey);
string data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?date=" + date.ToString("yyyy-MM-dd"), tokendata.apiKey);
string? data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?date=" + date.ToString("yyyy-MM-dd"), tokendata.apiKey);
if (data == "null") {
throw new Exception("Keine Daten für " + date.ToString("ddd. dd. MMM") + " erhalten");
@@ -120,9 +130,11 @@ internal class Stunde : ObservableObject {
if (data == "\"Lalala\"") {
throw new Exception("Problem mit Token");
}
if (data == null) {
throw new Exception("Keine Daten erhalten");
}
//daytimes = System.Text.Json.JsonSerializer.Deserialize<List<DayTime>>(data);
daytimes = JsonConvert.DeserializeObject<List<DayTime>>(data);
daytimes = JsonConvert.DeserializeObject<List<DayTime>>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
}
@@ -138,10 +150,14 @@ internal class Stunde : ObservableObject {
public static async Task<DayTime> LoadEntry(int id) {
var tokendata = new TokenData(apiKey);
var data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?id=" + id, tokendata.apiKey);
string? data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?id=" + id, tokendata.apiKey);
if (data == null) {
throw new Exception("Keine Daten erhalten");
}
//DayTime hours = Hours.daytime.Find(x => x.id == id);
DayTime hours = JsonConvert.DeserializeObject<DayTime>(data);
DayTime hours = JsonConvert.DeserializeObject<DayTime>(data) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
hours.TimeSpanVon = hours.begin.ToTimeSpan();
hours.TimeSpanBis = hours.end.ToTimeSpan();