static public async Task <bool> AllNewsItems(bool Preload, bool IgnoreDate, bool Silent, bool EnableUI) { try { if (!Silent) { await EventProgressDisableUI("Downloading latest items...", true); } Debug.WriteLine("Downloading latest items..."); //Date time calculations Int64 UnixTimeTicks = 0; DateTime RemoveItemsRange = DateTime.UtcNow.AddDays(-Convert.ToDouble(AppVariables.ApplicationSettings["RemoveItemsRange"])); if (AppVariables.ApplicationSettings["LastItemsUpdate"].ToString() == "Never") { UnixTimeTicks = (RemoveItemsRange.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks) / 10000000; //Second } else { UnixTimeTicks = ((Convert.ToDateTime(AppVariables.ApplicationSettings["LastItemsUpdate"], AppVariables.CultureInfoEnglish).AddMinutes(-15)).Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks) / 10000000; //Second } //Set the last update time string string LastUpdate = DateTime.UtcNow.ToString(AppVariables.CultureInfoEnglish); string[][] RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppVariables.ApplicationSettings["ConnectApiAuth"].ToString() } }; string DownloadString = await AVDownloader.DownloadStringAsync(20000, "News Scroll", RequestHeader, new Uri(ApiConnectionUrl + "stream/contents?output=json&n=" + AppVariables.ItemsMaximumLoad + "&ot=" + UnixTimeTicks)); bool UpdatedItems = await DownloadToTableItemList(Preload, IgnoreDate, DownloadString, Silent, EnableUI); if (UpdatedItems) { //Save the last update time string AppVariables.ApplicationSettings["LastItemsUpdate"] = LastUpdate; if (EnableUI) { await EventProgressEnableUI(); } return(true); } else { await EventProgressEnableUI(); return(false); } } catch { await EventProgressEnableUI(); return(false); } }
static public async Task <bool> SingleItem(string DownloadId, bool Preload, bool IgnoreDate, bool Silent, bool EnableUI) { try { string DownloadItems = DownloadId.Replace(" ", String.Empty).Replace("tag:google.com,2005:reader/item/", String.Empty); string[][] RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppVariables.ApplicationSettings["ConnectApiAuth"].ToString() } }; Uri DownloadUri = new Uri(ApiConnectionUrl + "stream/items/contents?output=json&i=" + DownloadItems); string DownloadString = await AVDownloader.DownloadStringAsync(7500, "News Scroll", RequestHeader, DownloadUri); return(await DownloadToTableItemList(Preload, IgnoreDate, DownloadString, Silent, EnableUI)); } catch { return(false); } }
static public async Task <bool> ItemsStarred(bool Preload, bool Silent, bool EnableUI) { try { if (!Silent) { EventProgressDisableUI("Downloading starred status...", true); } Debug.WriteLine("Downloading starred status..."); string[][] RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppSettingLoad("ConnectApiAuth").ToString() } }; string DownloadString = await AVDownloader.DownloadStringAsync(15000, "News Scroll", RequestHeader, new Uri(ApiConnectionUrl + "stream/items/ids?output=json&s=user/-/state/com.google/starred&n=" + AppVariables.StarredMaximumLoad)); if (!string.IsNullOrWhiteSpace(DownloadString)) { JObject WebJObject = JObject.Parse(DownloadString); if (WebJObject["itemRefs"] != null && WebJObject["itemRefs"].HasValues) { if (!Silent) { EventProgressDisableUI("Updating " + WebJObject["itemRefs"].Count() + " star status...", true); } Debug.WriteLine("Updating " + WebJObject["itemRefs"].Count() + " star status..."); //Check and set the received star item ids List <TableItems> TableEditItems = await vSQLConnection.Table <TableItems>().ToListAsync(); string DownloadItemIds = string.Empty; List <string> StarItemsID = new List <string>(); foreach (JToken JTokenRoot in WebJObject["itemRefs"]) { string FoundItemId = JTokenRoot["id"].ToString().Replace(" ", string.Empty).Replace("tag:google.com,2005:reader/item/", string.Empty); StarItemsID.Add(FoundItemId); //Check if star item exists if (!TableEditItems.Any(x => x.item_id == FoundItemId)) { DownloadItemIds += "&i=" + FoundItemId; } } //Update the star status in database string StarUpdateString = string.Empty; foreach (string StarItem in StarItemsID) { StarUpdateString += "'" + StarItem + "',"; } StarUpdateString = AVFunctions.StringRemoveEnd(StarUpdateString, ","); if (StarItemsID.Any()) { int UpdatedItems = await vSQLConnection.ExecuteAsync("UPDATE TableItems SET item_star_status = ('1'), item_read_status = ('1') WHERE item_id IN (" + StarUpdateString + ") AND item_star_status = ('0')"); Debug.WriteLine("Updated star items: " + UpdatedItems); } //Update the unstar status in database List <string> UnstarItemsID = TableEditItems.Where(x => x.item_star_status == true).Select(x => x.item_id).Except(StarItemsID).ToList(); string UnstarUpdateString = string.Empty; foreach (string UnstarItem in UnstarItemsID) { UnstarUpdateString += "'" + UnstarItem + "',"; } UnstarUpdateString = AVFunctions.StringRemoveEnd(UnstarUpdateString, ","); if (UnstarItemsID.Any()) { int UpdatedItems = await vSQLConnection.ExecuteAsync("UPDATE TableItems SET item_star_status = ('0') WHERE item_id IN (" + UnstarUpdateString + ") AND item_star_status = ('1')"); Debug.WriteLine("Updated unstar items: " + UpdatedItems); } //Download all missing starred items if (!string.IsNullOrWhiteSpace(DownloadItemIds)) { if (!Silent) { EventProgressDisableUI("Downloading starred items...", true); } Debug.WriteLine("Downloading starred items..."); bool UpdatedItems = await MultiItems(DownloadItemIds, true, true, Silent, EnableUI); if (!UpdatedItems) { EventProgressEnableUI(); return(false); } } } if (EnableUI) { EventProgressEnableUI(); } return(true); } else { EventProgressEnableUI(); return(false); } } catch { EventProgressEnableUI(); return(false); } }
static public async Task <bool> Feeds(bool Silent, bool EnableUI) { try { if (!Silent) { await EventProgressDisableUI("Downloading latest feeds...", true); } System.Diagnostics.Debug.WriteLine("Downloading latest feeds..."); string[][] RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppVariables.ApplicationSettings["ConnectApiAuth"].ToString() } }; string DownloadString = await AVDownloader.DownloadStringAsync(10000, "News Scroll", RequestHeader, new Uri(ApiConnectionUrl + "subscription/list?output=json")); JObject WebJObject = JObject.Parse(DownloadString); if (WebJObject["subscriptions"] != null && WebJObject["subscriptions"].HasValues) { if (!Silent) { await EventProgressDisableUI("Processing " + WebJObject["subscriptions"].Count() + " feeds...", true); } System.Diagnostics.Debug.WriteLine("Processing " + WebJObject["subscriptions"].Count() + " feeds..."); List <string> ApiFeedIdList = new List <string>(); IReadOnlyList <IStorageItem> LocalFileList = await ApplicationData.Current.LocalFolder.GetItemsAsync(); List <TableFeeds> TableUpdatedFeeds = new List <TableFeeds>(); List <TableFeeds> TableCurrentFeeds = await SQLConnection.Table <TableFeeds>().ToListAsync(); foreach (JToken JTokenRoot in WebJObject["subscriptions"]) { string FeedId = JTokenRoot["sortid"].ToString(); string FeedTitle = JTokenRoot["title"].ToString(); string HtmlUrl = WebUtility.HtmlDecode(JTokenRoot["htmlUrl"].ToString()); HtmlUrl = WebUtility.UrlDecode(HtmlUrl); Uri FullUrl = new Uri(HtmlUrl); ApiFeedIdList.Add(FeedId); TableFeeds TableResult = TableCurrentFeeds.Where(x => x.feed_id == FeedId).FirstOrDefault(); if (TableResult == null) { //System.Diagnostics.Debug.WriteLine("Adding feed: " + FeedTitle); TableFeeds AddFeed = new TableFeeds(); AddFeed.feed_id = FeedId; AddFeed.feed_title = FeedTitle; AddFeed.feed_link = FullUrl.Scheme + "://" + FullUrl.Host; AddFeed.feed_ignore_status = false; if (JTokenRoot["categories"] != null && JTokenRoot["categories"].HasValues) { AddFeed.feed_folder = JTokenRoot["categories"][0]["label"].ToString(); } TableUpdatedFeeds.Add(AddFeed); } else { //System.Diagnostics.Debug.WriteLine("Updating feed: " + FeedTitle); TableResult.feed_title = FeedTitle; TableResult.feed_link = FullUrl.Scheme + "://" + FullUrl.Host; if (JTokenRoot["categories"] != null && JTokenRoot["categories"].HasValues) { TableResult.feed_folder = JTokenRoot["categories"][0]["label"].ToString(); } TableUpdatedFeeds.Add(TableResult); } //Check and download feed logo if (!LocalFileList.Any(x => x.Name == FeedId + ".png")) { try { if (!Silent) { await EventProgressDisableUI("Downloading " + FeedTitle + " icon...", true); } Uri IconUrl = new Uri("https://s2.googleusercontent.com/s2/favicons?domain=" + FullUrl.Host); byte[] HttpFeedIcon = await AVDownloader.DownloadByteAsync(3000, "News Scroll", null, IconUrl); if (HttpFeedIcon != null && HttpFeedIcon.Length > 75) { await AVFile.SaveBytes(FeedId + ".png", HttpFeedIcon); System.Diagnostics.Debug.WriteLine("Downloaded transparent logo: " + HttpFeedIcon.Length + "bytes/" + IconUrl); } else { System.Diagnostics.Debug.WriteLine("No logo found for: " + IconUrl); } } catch { } } } //Update the feeds in database if (TableUpdatedFeeds.Any()) { await SQLConnection.InsertAllAsync(TableUpdatedFeeds, "OR REPLACE"); } //Delete removed feeds from the database List <string> DeletedFeeds = TableCurrentFeeds.Select(x => x.feed_id).Except(ApiFeedIdList).ToList(); System.Diagnostics.Debug.WriteLine("Found deleted feeds: " + DeletedFeeds.Count()); foreach (string DeleteFeedId in DeletedFeeds) { await DeleteFeed(DeleteFeedId); } } if (EnableUI) { await EventProgressEnableUI(); } return(true); } catch { await EventProgressEnableUI(); return(false); } }
static public async Task <bool> ItemsRead(ObservableCollection <Items> UpdateList, bool Silent, bool EnableUI) { try { if (!Silent) { await EventProgressDisableUI("Downloading read status...", true); } Debug.WriteLine("Downloading read status..."); //Wait for busy database await ApiUpdate.WaitForBusyDatabase(); //Get all stored items from the database List <TableItems> CurrentItems = await SQLConnection.Table <TableItems>().ToListAsync(); if (CurrentItems.Any()) { //Get last stored item date minus starred items TableItems LastStoredItem = CurrentItems.Where(x => x.item_star_status == false).OrderByDescending(x => x.item_datetime).LastOrDefault(); if (LastStoredItem != null) { //Date time calculations DateTime RemoveItemsRange = LastStoredItem.item_datetime.AddHours(-1); //Debug.WriteLine("Downloading read items till: " + LastStoredItem.item_title + "/" + RemoveItemsRange); Int64 UnixTimeTicks = (RemoveItemsRange.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks) / 10000000; //Second string[][] RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppVariables.ApplicationSettings["ConnectApiAuth"].ToString() } }; Uri DownloadUri = new Uri(ApiConnectionUrl + "stream/items/ids?output=json&s=user/-/state/com.google/read&n=" + AppVariables.ItemsMaximumLoad + "&ot=" + UnixTimeTicks); string DownloadString = await AVDownloader.DownloadStringAsync(10000, "News Scroll", RequestHeader, DownloadUri); if (!String.IsNullOrWhiteSpace(DownloadString)) { JObject WebJObject = JObject.Parse(DownloadString); if (WebJObject["itemRefs"] != null && WebJObject["itemRefs"].HasValues) { if (!Silent) { await EventProgressDisableUI("Updating " + WebJObject["itemRefs"].Count() + " read status...", true); } Debug.WriteLine("Updating " + WebJObject["itemRefs"].Count() + " read status..."); //Check and set the received read item ids string ReadUpdateString = String.Empty; List <String> ReadItemsList = new List <String>(); foreach (JToken JTokenRoot in WebJObject["itemRefs"]) { string FoundItemId = JTokenRoot["id"].ToString().Replace(" ", String.Empty).Replace("tag:google.com,2005:reader/item/", String.Empty); ReadUpdateString += "'" + FoundItemId + "',"; ReadItemsList.Add(FoundItemId); } //Update the read status in database if (ReadItemsList.Any()) { ReadUpdateString = AVFunctions.StringRemoveEnd(ReadUpdateString, ","); Int32 UpdatedItems = await SQLConnection.ExecuteAsync("UPDATE TableItems SET item_read_status = ('1') WHERE item_id IN (" + ReadUpdateString + ") AND item_read_status = ('0')"); Debug.WriteLine("Updated read items: " + UpdatedItems); } //Update the read status in list await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { try { List <Items> ReadItemsIDList = UpdateList.Where(x => x.item_read_status == Visibility.Collapsed && ReadItemsList.Any(y => y == x.item_id)).ToList(); foreach (Items ReadItem in ReadItemsIDList) { ReadItem.item_read_status = Visibility.Visible; } } catch { } }); //Update the unread status in database string UnreadUpdateString = String.Empty; List <String> UnreadItemsList = (await SQLConnection.Table <TableItems>().ToListAsync()).Where(x => x.item_read_status == true && x.item_datetime > RemoveItemsRange).Select(x => x.item_id).Except(ReadItemsList).ToList(); foreach (String UnreadItem in UnreadItemsList) { UnreadUpdateString += "'" + UnreadItem + "',"; } if (UnreadItemsList.Any()) { UnreadUpdateString = AVFunctions.StringRemoveEnd(UnreadUpdateString, ","); Int32 UpdatedItems = await SQLConnection.ExecuteAsync("UPDATE TableItems SET item_read_status = ('0') WHERE item_id IN (" + UnreadUpdateString + ") AND item_read_status = ('1')"); Debug.WriteLine("Updated unread items: " + UpdatedItems); } //Update the unread status in list await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { try { List <Items> UnreadItemsIDList = UpdateList.Where(x => x.item_read_status == Visibility.Visible && UnreadItemsList.Any(y => y == x.item_id)).ToList(); foreach (Items UnreadItem in UnreadItemsIDList) { UnreadItem.item_read_status = Visibility.Collapsed; } } catch { } }); } } } } if (EnableUI) { await EventProgressEnableUI(); } return(true); } catch { await EventProgressEnableUI(); return(false); } }
//Download Bing wallpaper async Task DownloadBingWallpaper() { try { Debug.WriteLine("Downloading Bing update."); //Check for internet connection if (!DownloadInternetCheck()) { BackgroundStatusUpdateSettings(null, null, "Never", null, "NoWifiEthernet"); return; } //Load and set Download Information string DownloadBingRegion = "en-US"; switch (setDownloadBingRegion) { case 0: { DownloadBingRegion = vCultureInfoReg.Name; break; } case 2: { DownloadBingRegion = "en-GB"; break; } case 3: { DownloadBingRegion = "en-AU"; break; } case 4: { DownloadBingRegion = "de-DE"; break; } case 5: { DownloadBingRegion = "en-CA"; break; } case 6: { DownloadBingRegion = "ja-JP"; break; } case 7: { DownloadBingRegion = "zh-CN"; break; } case 8: { DownloadBingRegion = "fr-FR"; break; } case 9: { DownloadBingRegion = "pt-BR"; break; } case 10: { DownloadBingRegion = "nz-NZ"; break; } } string DownloadBingResolution = "1920x1080"; switch (setDownloadBingResolution) { case 1: { DownloadBingResolution = "1280x720"; break; } case 2: { DownloadBingResolution = "1080x1920"; break; } case 3: { DownloadBingResolution = "720x1280"; break; } case 4: { DownloadBingResolution = "1024x768"; break; } } //Download and read Bing Wallpaper XML XDocument XDocumentBing = XDocument.Parse(await AVDownloader.DownloadStringAsync(5000, "TimeMe", null, new Uri("https://www.bing.com/HPImageArchive.aspx?format=xml&n=1&mkt=" + DownloadBingRegion))); //Read and check current Bing wallpaper XElement XElement = XDocumentBing.Descendants("image").First(); string BingUrlName = XElement.Element("urlBase").Value + "_" + DownloadBingResolution + ".jpg"; string BingDescription = XElement.Element("copyright").Value; if (BgStatusBingDescription != BingDescription) { //Download and Save Bing Wallpaper image IBuffer BingWallpaperFile = await AVDownloader.DownloadBufferAsync(5000, "TimeMe", new Uri("https://www.bing.com" + BingUrlName)); if (BingWallpaperFile != null) { //Save the Bing wallpaper image StorageFile BingSaveFile = await AVFile.SaveBuffer("TimeMeTilePhoto.png" + new String(' ', new Random().Next(1, 50)), BingWallpaperFile); //Set background photo as device wallpaper try { if (setDeviceWallpaper) { await UserProfilePersonalizationSettings.Current.TrySetWallpaperImageAsync(BingSaveFile); } } catch { Debug.WriteLine("Failed to update Device wallpaper."); } //Set background photo as lockscreen wallpaper try { if (setLockWallpaper) { if (setDevStatusMobile) { await UserProfilePersonalizationSettings.Current.TrySetLockScreenImageAsync(await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Tiles/TimeMeTileColor.png"))); } await UserProfilePersonalizationSettings.Current.TrySetLockScreenImageAsync(BingSaveFile); } } catch { Debug.WriteLine("Failed to update Lock screen wallpaper."); } //Save Bing photo name BgStatusPhotoName = BingUrlName; vApplicationSettings["BgStatusPhotoName"] = BgStatusPhotoName; //Save Bing description status BgStatusBingDescription = BingDescription; vApplicationSettings["BgStatusBingDescription"] = BgStatusBingDescription; //Notification - Bing description ShowNotiBingDescription(); //Force live tile update TileLive_ForceUpdate = true; } else { Debug.WriteLine("Failed downloading the Bing wallpaper."); BackgroundStatusUpdateSettings(null, null, "Never", null, "FailedDownloadBingWallpaper"); return; } } //Save Bing update status BgStatusDownloadBing = DateTimeNow.ToString(vCultureInfoEng); vApplicationSettings["BgStatusDownloadBing"] = BgStatusDownloadBing; } catch (Exception ex) { Debug.WriteLine("Failed updating the Bing wallpaper."); BackgroundStatusUpdateSettings(null, null, "Never", null, "CatchDownloadBingWallpaper" + ex.Message); } }
//Download location async Task <bool> DownloadLocation() { try { Debug.WriteLine("Downloading Location update."); //Check for internet connection if (!DownloadInternetCheck()) { BackgroundStatusUpdateSettings(null, "Never", null, null, "NoWifiEthernet"); return(false); } //Load and set current GPS location if (setWeatherGpsLocation) { try { //Get current GPS position from geolocator Geolocator Geolocator = new Geolocator(); Geolocator.DesiredAccuracy = PositionAccuracy.Default; Geoposition ResGeoposition = await Geolocator.GetGeopositionAsync(TimeSpan.FromMinutes(setBackgroundDownloadIntervalMin), TimeSpan.FromSeconds(6)); DownloadWeatherLocation = ResGeoposition.Coordinate.Point.Position.Latitude.ToString().Replace(",", ".") + "," + ResGeoposition.Coordinate.Point.Position.Longitude.ToString().Replace(",", "."); } catch { DownloadGpsUpdateFailed = true; } } else { if (String.IsNullOrEmpty(setWeatherNonGpsLocation)) { DownloadGpsUpdateFailed = true; } else { DownloadWeatherLocation = setWeatherNonGpsLocation; } } //Load and set manual location if (DownloadGpsUpdateFailed) { string PreviousLocation = BgStatusWeatherCurrentLocationFull.Replace("!", ""); if (PreviousLocation != "N/A" && !String.IsNullOrEmpty(PreviousLocation)) { DownloadWeatherLocation = PreviousLocation; } else { Debug.WriteLine("Failed no previous location has been set."); BackgroundStatusUpdateSettings(null, "Failed", null, null, "GpsPrevUpdateFailed"); return(false); } } //Download and save the weather location string LocationResult = await AVDownloader.DownloadStringAsync(5000, "TimeMe", null, new Uri("https://service.weather.microsoft.com/" + DownloadWeatherLanguage + "/locations/search/" + DownloadWeatherLocation + DownloadWeatherUnits)); //Check if there is location data available JObject LocationJObject = JObject.Parse(LocationResult); if (LocationJObject["responses"][0]["locations"] == null || !LocationJObject["responses"][0]["locations"].Any()) { Debug.WriteLine("Failed no overall info for location found."); BackgroundStatusUpdateSettings(null, "Failed", null, null, "GpsNoLocationOverall"); return(false); } else { JToken HttpJTokenGeo = LocationJObject["responses"][0]["locations"][0]; //Set current location coords if (HttpJTokenGeo["coordinates"]["lat"] != null && HttpJTokenGeo["coordinates"]["lon"] != null) { DownloadWeatherLocation = HttpJTokenGeo["coordinates"]["lat"].ToString().Replace(",", ".") + "," + HttpJTokenGeo["coordinates"]["lon"].ToString().Replace(",", "."); } else { if (!setWeatherGpsLocation || DownloadGpsUpdateFailed) { Debug.WriteLine("Failed no gps coords for location found."); BackgroundStatusUpdateSettings(null, "Failed", null, null, "GpsNoLocationCoords"); return(false); } } //Set weather current location if (HttpJTokenGeo["displayName"] != null) { string LocationName = HttpJTokenGeo["displayName"].ToString(); if (!String.IsNullOrEmpty(LocationName)) { BgStatusWeatherCurrentLocationFull = LocationName; vApplicationSettings["BgStatusWeatherCurrentLocationFull"] = BgStatusWeatherCurrentLocationFull; if (LocationName.Contains(",")) { LocationName = LocationName.Split(',')[0]; } BgStatusWeatherCurrentLocation = LocationName; vApplicationSettings["BgStatusWeatherCurrentLocation"] = BgStatusWeatherCurrentLocation; } else { Debug.WriteLine("Failed empty location name found."); BackgroundStatusUpdateSettings(null, "Failed", null, null, "NoLocationNameEmpty"); return(false); } } else { Debug.WriteLine("Failed no location name found."); BackgroundStatusUpdateSettings(null, "Failed", null, null, "NoLocationNameFound"); return(false); } } //Save Location status BgStatusDownloadLocation = DateTimeNow.ToString(vCultureInfoEng); vApplicationSettings["BgStatusDownloadLocation"] = BgStatusDownloadLocation; return(true); } catch (Exception ex) { Debug.WriteLine("Failed updating the location info."); BackgroundStatusUpdateSettings(null, "Failed", null, null, "CatchDownloadLocation" + ex.Message); return(false); } }
//Download weather and forecast async Task DownloadWeather() { try { Debug.WriteLine("Downloading Weather update."); //Check for internet connection if (!DownloadInternetCheck()) { BackgroundStatusUpdateSettings("Never", null, null, null, "NoWifiEthernet"); return; } //Check if location is available if (String.IsNullOrEmpty(DownloadWeatherLocation)) { BackgroundStatusUpdateSettings("Never", null, null, null, "NoWeatherLocation"); return; } //Download and save weather summary string WeatherSummaryResult = await AVDownloader.DownloadStringAsync(5000, "TimeMe", null, new Uri("https://service.weather.microsoft.com/" + DownloadWeatherLanguage + "/weather/summary/" + DownloadWeatherLocation + DownloadWeatherUnits)); if (!String.IsNullOrEmpty(WeatherSummaryResult)) { //Update weather summary status UpdateWeatherSummaryStatus(WeatherSummaryResult); //Notification - Current Weather ShowNotiWeatherCurrent(); //Save weather summary data await AVFile.SaveText("TimeMeWeatherSummary.js", WeatherSummaryResult); } else { Debug.WriteLine("Failed no weather summary found."); BackgroundStatusUpdateSettings("Failed", null, null, null, "NoWeatherSummary"); return; } //Download and save weather forecast string WeatherForecastResult = await AVDownloader.DownloadStringAsync(5000, "TimeMe", null, new Uri("https://service.weather.microsoft.com/" + DownloadWeatherLanguage + "/weather/forecast/daily/" + DownloadWeatherLocation + DownloadWeatherUnits)); if (!String.IsNullOrEmpty(WeatherForecastResult)) { //Save weather forecast data await AVFile.SaveText("TimeMeWeatherForecast.js", WeatherForecastResult); } else { Debug.WriteLine("Failed no weather forecast found."); BackgroundStatusUpdateSettings("Failed", null, null, null, "NoWeatherForecast"); return; } //Save Weather status BgStatusDownloadWeather = DateTimeNow.ToString(vCultureInfoEng); vApplicationSettings["BgStatusDownloadWeather"] = BgStatusDownloadWeather; BgStatusDownloadWeatherTime = BgStatusDownloadWeather; vApplicationSettings["BgStatusDownloadWeatherTime"] = BgStatusDownloadWeather; } catch (Exception ex) { Debug.WriteLine("Failed updating the weather info."); BackgroundStatusUpdateSettings("Failed", null, null, null, "CatchDownloadWeather" + ex.Message); } //Update weather summary status void UpdateWeatherSummaryStatus(string WeatherSummaryResult) { try { //Check if there is summary data available JObject SummaryJObject = JObject.Parse(WeatherSummaryResult); if (SummaryJObject["responses"][0]["weather"] != null) { //Set Weather Provider Information JToken HttpJTokenProvider = SummaryJObject["responses"][0]["weather"][0]["provider"]; if (HttpJTokenProvider["name"] != null) { string Provider = HttpJTokenProvider["name"].ToString(); if (!String.IsNullOrEmpty(Provider)) { BgStatusWeatherProvider = Provider; vApplicationSettings["BgStatusWeatherProvider"] = BgStatusWeatherProvider; } else { BgStatusWeatherProvider = "N/A"; vApplicationSettings["BgStatusWeatherProvider"] = BgStatusWeatherProvider; } } //Set Weather Current Conditions string Icon = ""; string Condition = ""; string Temperature = ""; string WindSpeedDirection = ""; JToken UnitsJToken = SummaryJObject["units"]; JToken HttpJTokenCurrent = SummaryJObject["responses"][0]["weather"][0]["current"]; if (HttpJTokenCurrent["icon"] != null) { Icon = HttpJTokenCurrent["icon"].ToString(); } if (HttpJTokenCurrent["cap"] != null) { Condition = HttpJTokenCurrent["cap"].ToString(); } if (HttpJTokenCurrent["temp"] != null) { Temperature = HttpJTokenCurrent["temp"].ToString() + "°"; } if (HttpJTokenCurrent["windSpd"] != null && HttpJTokenCurrent["windDir"] != null) { WindSpeedDirection = HttpJTokenCurrent["windSpd"].ToString() + " " + UnitsJToken["speed"].ToString() + " " + AVFunctions.DegreesToCardinal(Convert.ToDouble((HttpJTokenCurrent["windDir"].ToString()))); } //Set Weather Forecast Conditions string RainChance = ""; string TemperatureLow = ""; string TemperatureHigh = ""; JToken HttpJTokenForecast = SummaryJObject["responses"][0]["weather"][0]["forecast"]["days"][0]; if (HttpJTokenForecast["precip"] != null) { RainChance = HttpJTokenForecast["precip"].ToString() + "%"; } if (HttpJTokenForecast["tempLo"] != null) { TemperatureLow = HttpJTokenForecast["tempLo"].ToString() + "°"; } if (HttpJTokenForecast["tempHi"] != null) { TemperatureHigh = HttpJTokenForecast["tempHi"].ToString() + "°"; } //Set Weather Icon if (!String.IsNullOrEmpty(Icon)) { BgStatusWeatherCurrentIcon = Icon; vApplicationSettings["BgStatusWeatherCurrentIcon"] = BgStatusWeatherCurrentIcon; } else { BgStatusWeatherCurrentIcon = "0"; vApplicationSettings["BgStatusWeatherCurrentIcon"] = BgStatusWeatherCurrentIcon; } //Set Weather Temperature and Condition if (!String.IsNullOrEmpty(Temperature) && !String.IsNullOrEmpty(Condition)) { BgStatusWeatherCurrent = AVFunctions.ToTitleCase(Condition) + ", " + Temperature; vApplicationSettings["BgStatusWeatherCurrent"] = BgStatusWeatherCurrent; } else { BgStatusWeatherCurrent = "N/A"; vApplicationSettings["BgStatusWeatherCurrent"] = BgStatusWeatherCurrent; } //Set Weather Temperature if (!String.IsNullOrEmpty(Temperature)) { BgStatusWeatherCurrentTemp = Temperature; vApplicationSettings["BgStatusWeatherCurrentTemp"] = BgStatusWeatherCurrentTemp; } else { BgStatusWeatherCurrentTemp = "N/A"; vApplicationSettings["BgStatusWeatherCurrentTemp"] = BgStatusWeatherCurrentTemp; } //Set Weather Condition if (!String.IsNullOrEmpty(Condition)) { BgStatusWeatherCurrentText = AVFunctions.ToTitleCase(Condition); vApplicationSettings["BgStatusWeatherCurrentText"] = BgStatusWeatherCurrentText; } else { BgStatusWeatherCurrentText = "N/A"; vApplicationSettings["BgStatusWeatherCurrentText"] = BgStatusWeatherCurrentText; } //Set Weather Wind Speed and Direction if (!String.IsNullOrEmpty(WindSpeedDirection)) { BgStatusWeatherCurrentWindSpeed = WindSpeedDirection; vApplicationSettings["BgStatusWeatherCurrentWindSpeed"] = BgStatusWeatherCurrentWindSpeed; } else { BgStatusWeatherCurrentWindSpeed = "N/A"; vApplicationSettings["BgStatusWeatherCurrentWindSpeed"] = BgStatusWeatherCurrentWindSpeed; } //Set Weather Rain Chance if (!String.IsNullOrEmpty(RainChance)) { BgStatusWeatherCurrentRainChance = RainChance; vApplicationSettings["BgStatusWeatherCurrentRainChance"] = BgStatusWeatherCurrentRainChance; } else { BgStatusWeatherCurrentRainChance = "N/A"; vApplicationSettings["BgStatusWeatherCurrentRainChance"] = BgStatusWeatherCurrentRainChance; } //Set Weather Temp Low if (!String.IsNullOrEmpty(TemperatureLow)) { BgStatusWeatherCurrentTempLow = TemperatureLow; vApplicationSettings["BgStatusWeatherCurrentTempLow"] = BgStatusWeatherCurrentTempLow; } else { BgStatusWeatherCurrentTempLow = "N/A"; vApplicationSettings["BgStatusWeatherCurrentTempLow"] = BgStatusWeatherCurrentTempLow; } //Set Weather Temp High if (!String.IsNullOrEmpty(TemperatureHigh)) { BgStatusWeatherCurrentTempHigh = TemperatureHigh; vApplicationSettings["BgStatusWeatherCurrentTempHigh"] = BgStatusWeatherCurrentTempHigh; } else { BgStatusWeatherCurrentTempHigh = "N/A"; vApplicationSettings["BgStatusWeatherCurrentTempHigh"] = BgStatusWeatherCurrentTempHigh; } } } catch { } } }