public static void GetStoringen(ExtendedShellInfo tileData, WorkloadInfo <ExtendedShellInfo, int?> token) { try { if (DeviceNetworkInformation.IsNetworkAvailable && (DeviceNetworkInformation.IsWiFiEnabled || DeviceNetworkInformation.IsCellularDataEnabled)) { string url = NSApi.BaseUrl + "/ns-api-storingen?actual=true&planned=false"; if (!string.IsNullOrEmpty(tileData.Name)) { url = string.Format(NSApi.BaseUrl + "/ns-api-storingen?actual=true&planned=false&station={0}", tileData.Name); } Uri address = new Uri(url, UriKind.Absolute); WebClient webclient = new WebClient(); //webclient.Credentials = new NetworkCredential(NSApi.Login, NSApi.Password); webclient.DownloadStringCompleted += (s, e) => webclient_DownloadStringCompleted(e, token); webclient.DownloadStringAsync(address); } else { token.NotifySuccess(null); } } catch (Exception ex) { token.NotifySuccess(null); } }
private static void UpdateTiles() { var workManager = new AsyncWorkManager <ExtendedShellInfo, int?>(); ShellTile appTile = ShellTile.ActiveTiles.First(); WorkloadInfo <ExtendedShellInfo, int?> result = null; if (appTile != null) { try { ExtendedShellInfo info = new ExtendedShellInfo() { Name = string.Empty, ShellTile = appTile }; result = workManager.AddWorkItem(StoringCountService.GetStoringen, info); } catch { } } //Wait for all tasks to complete workManager.WaitAll(); if (result.IsComplete && result.Result.HasValue) { ResetTiles(result.Result.Value); } ////Update tiles //foreach (var foundTile in ShellTile.ActiveTiles.Where(x => x.NavigationUri.ToString().Contains("StationTijden"))) //{ // int begin = foundTile.NavigationUri.ToString().IndexOf("id="); // if (begin > 0) // { // string name = foundTile.NavigationUri.ToString().Substring(begin + 3); // ExtendedShellInfo info = new ExtendedShellInfo() // { // Name = name, // ShellTile = foundTile // }; // workManager.AddWorkItem(StoringCountService.GetStoringen, info); // } //} }