/// <summary> /// Bildet Home Seite und gibt diese zurück /// </summary> /// <returns></returns> public static async Task <byte[]> BuildQuote() { string page = string.Empty; try { IEnumerable <string> file = await FileHelperClass.LoadFileFromStorage("SmartMirrorServer\\Websites\\quote.html"); Api.Quote.Quote result = DataAccess.DeserializeModuleData(typeof(Api.Quote.Quote), await DataAccess.GetModuleData(Modules.Quote)); foreach (string line in file) { string tag = line; if (tag.Contains("quote") || tag.Contains("author")) { tag = tag.Replace("quote", result.Text); tag = tag.Replace("author", result.Author); } page += tag; } } catch (Exception exception) { if (Application.Notifications.ExceptionNotifications) { Notification.Notification.SendPushNotification("Fehler aufgetreten.", $"{exception.StackTrace}"); } } return(Encoding.UTF8.GetBytes(page)); }
/// <summary> /// Bildet Home Seite und gibt diese zurück /// </summary> /// <returns></returns> public static async Task <byte[]> BuildNews(Request request) { string page = string.Empty; try { IEnumerable <string> file = await FileHelperClass.LoadFileFromStorage("SmartMirrorServer\\Websites\\news.html"); foreach (string line in file) { string tag = line; if (tag.Contains("News")) { tag = tag.Replace("News", await getNews(request)); } page += tag; } } catch (Exception exception) { if (Application.Notifications.ExceptionNotifications) { Notification.Notification.SendPushNotification("Fehler aufgetreten.", $"{exception.StackTrace}"); } } return(Encoding.UTF8.GetBytes(page)); }
/// <summary> /// Bildet Home Seite und gibt diese zurück /// </summary> /// <returns></returns> public static async Task <byte[]> BuildHome() { string page = string.Empty; Debug.WriteLine("Home Seite wird gebildet."); try { IEnumerable <string> file = await FileHelperClass.LoadFileFromStorage("SmartMirrorServer\\Websites\\home.html"); foreach (string line in file) { string tag = line; if (tag.Contains("Modul0")) { tag = tag.Replace("Modul0", await getModul(ModulLocation.UPPERLEFT)); } else if (tag.Contains("Modul1")) { tag = tag.Replace("Modul1", await getModul(ModulLocation.UPPERRIGHT)); } else if (tag.Contains("Modul2")) { tag = tag.Replace("Modul2", await getModul(ModulLocation.MIDDLELEFT)); } else if (tag.Contains("Modul3")) { tag = tag.Replace("Modul3", await getModul(ModulLocation.MIDDLERIGHT)); } else if (tag.Contains("Modul4")) { tag = tag.Replace("Modul4", await getModul(ModulLocation.LOWERLEFT)); } else if (tag.Contains("Modul5")) { tag = tag.Replace("Modul5", await getModul(ModulLocation.LOWERRIGHT)); } page += tag; } } catch (Exception exception) { if (Application.Notifications.ExceptionNotifications) { Notification.Notification.SendPushNotification("Fehler aufgetreten.", $"{exception.StackTrace}"); } } Debug.WriteLine("Home Seite fertig gebildet."); return(Encoding.UTF8.GetBytes(page)); }
/// <summary> /// Bildet Help Seite und gibt diese zurück /// </summary> /// <returns></returns> public static async Task <byte[]> BuildHelp() { string page = string.Empty; try { IEnumerable <string> file = await FileHelperClass.LoadFileFromStorage("SmartMirrorServer\\Websites\\help.html"); page = string.Join("", file); } catch (Exception exception) { if (Application.Notifications.ExceptionNotifications) { Notification.Notification.SendPushNotification("Fehler aufgetreten.", $"{exception.StackTrace}"); } } return(Encoding.UTF8.GetBytes(page)); }
/// <summary> /// Bildet Home Seite und gibt diese zurück /// </summary> /// <returns></returns> public static async Task <byte[]> BuildTime() { string page = string.Empty; try { IEnumerable <string> file = await FileHelperClass.LoadFileFromStorage("SmartMirrorServer\\Websites\\time.html"); //Sun sun = DataAccess.DeserializeModuleData(typeof(Sun), await DataAccess.GetModuleData(Modules.TIME)); Module sunModule = DataAccess.GetModule(Modules.TIME); Sun sun = new Sun(sunModule); foreach (string line in file) { string tag = line; if (tag.Contains("Datum")) { tag = tag.Replace("Datum", DateTime.Now.ToString("D")); } else if (tag.Contains("sunrisetime") || tag.Contains("sunsettime")) { tag = tag.Replace("sunrisetime", sun.Sunrise); tag = tag.Replace("sunsettime", sun.Sunset); } page += tag; } } catch (Exception exception) { if (Application.Notifications.ExceptionNotifications) { Notification.Notification.SendPushNotification("Fehler aufgetreten.", $"{exception.StackTrace}"); } } return(Encoding.UTF8.GetBytes(page)); }
/// <summary> /// Bildet Home Seite und gibt diese zurück /// </summary> /// <returns></returns> public static async Task <byte[]> BuildWeather() { string page = string.Empty; try { IEnumerable <string> file = await FileHelperClass.LoadFileFromStorage("SmartMirrorServer\\Websites\\weather.html"); SingleResult <CurrentWeatherResult> currentResult = DataAccess.DeserializeModuleData(typeof(SingleResult <CurrentWeatherResult>), await DataAccess.GetModuleData(Modules.Weather)); foreach (string line in file) { string tag = line; if (tag.Contains("CityId")) { tag = tag.Replace("CityId", currentResult.Item.CityId.ToString()); } else if (tag.Contains("City")) { tag = tag.Replace("City", currentResult.Item.City); } else if (tag.Contains("Description")) { tag = tag.Replace("Description", currentResult.Item.Description); } else if (tag.Contains("WeatherIcon")) { tag = tag.Replace("WeatherIcon", WeatherHelperClass.ChooseWeatherIcon(currentResult.Item.Icon)); } else if (tag.Contains("Temperature")) { tag = tag.Replace("Temperature", Math.Round(currentResult.Item.Temp, 1).ToString(CultureInfo.InvariantCulture)); } else if (tag.Contains("TempMin")) { tag = tag.Replace("TempMin", Math.Round(currentResult.Item.TempMin, 1).ToString(CultureInfo.InvariantCulture)); } if (tag.Contains("TempMax")) { tag = tag.Replace("TempMax", Math.Round(currentResult.Item.TempMax, 1).ToString(CultureInfo.InvariantCulture)); } else if (tag.Contains("Humidity")) { tag = tag.Replace("Humidity", currentResult.Item.Humidity.ToString(CultureInfo.InvariantCulture)); } else if (tag.Contains("WindSpeed")) { tag = tag.Replace("WindSpeed", currentResult.Item.WindSpeed.ToString(CultureInfo.InvariantCulture)); } else if (tag.Contains("Cloudiness")) { tag = tag.Replace("Cloudiness", currentResult.Item.Cloudinesss.ToString()); } else if (tag.Contains("Pressure")) { tag = tag.Replace("Pressure", currentResult.Item.Pressure.ToString(CultureInfo.InvariantCulture)); } else if (tag.Contains("PrecipitationIcon")) { tag = tag.Replace("PrecipitationIcon", currentResult.Item.Snow > 0 ? "snowflake.png" : "rain.png"); } if (tag.Contains("Precipitation")) { tag = tag.Replace("Precipitation", currentResult.Item.Snow > 0 ? currentResult.Item.Snow.ToString(CultureInfo.InvariantCulture) : currentResult.Item.Rain.ToString(CultureInfo.InvariantCulture)); } page += tag; } } catch (Exception exception) { if (Application.Notifications.ExceptionNotifications) { Notification.Notification.SendPushNotification("Fehler aufgetreten.", $"{exception.StackTrace}"); } } return(Encoding.UTF8.GetBytes(page)); }
/// <summary> /// Bildet Home Seite und gibt diese zurück /// </summary> /// <returns></returns> public static async Task <byte[]> BuildSettings(Request request) { string page = string.Empty; try { IEnumerable <string> file = await FileHelperClass.LoadFileFromStorage("SmartMirrorServer\\Websites\\settings.html"); bool tabOneActive = false; bool tabTwoActive = false; List <LocationTable> locationData = DataAccess.GetLocationData(); if (request.PostQuery.Value.Count == 0 || request.PostQuery.Value.ContainsKey("upperleft")) { tabOneActive = true; } else if (request.PostQuery.Value.ContainsKey("City")) { tabTwoActive = true; } foreach (string line in file) { string tag = line; if (tag.Contains("activebooltab1")) { tag = tag.Replace("activebooltab1", tabOneActive ? "is-active" : ""); } if (tag.Contains("activebooltab2")) { tag = tag.Replace("activebooltab2", tabTwoActive ? "is-active" : ""); } if (tag.Contains("cityValue")) { tag = tag.Replace("cityValue", locationData[0].City); } if (tag.Contains("stateValue")) { tag = tag.Replace("stateValue", locationData[0].State); } if (tag.Contains("countryValue")) { tag = tag.Replace("countryValue", locationData[0].Country); } if (tag.Contains("languageValue")) { tag = tag.Replace("languageValue", locationData[0].Language); } page += tag; } } catch (Exception exception) { if (Application.Notifications.ExceptionNotifications) { Notification.Notification.SendPushNotification("Fehler aufgetreten.", $"{exception.StackTrace}"); } } return(Encoding.UTF8.GetBytes(page)); }