protected void OnGetInfoFinished(GetInfoCompletedArgs args) { if (GetInfoFinished != null) { GetInfoFinished(this, args); } }
public async Task <bool> GetInfo(AccessToken token, string path, bool fromForeground) { var args = new GetInfoCompletedArgs(); if (NetworkInterface.NetworkInterfaceType == NetworkInterfaceType.None) { args.Canceled = true; OnGetInfoFinished(args); return(true); } try { using (var client = OAuthUtility.CreateOAuthClient(ConsumerKey, ConsumerSecret, token)) { if (!Cts.Token.IsCancellationRequested) { using (Cts.Token.Register(() => client.CancelPendingRequests())) { if (fromForeground) { args.Json = await client.GetStringAsync(BaseUrl + path); } else { var info = client.GetStreamAsync(BaseUrl + path); var reader = new StreamReader(info.Result); args.Json = reader.ReadToEnd(); } args.Canceled = false; //args.Canceled = true; } OnGetInfoFinished(args); } } } catch (Exception) { CancelTask(); args.Canceled = true; OnGetInfoFinished(args); } return(true); }
public async Task<bool> GetInfo(AccessToken token, string path, bool fromForeground) { var args = new GetInfoCompletedArgs(); if (NetworkInterface.NetworkInterfaceType == NetworkInterfaceType.None) { args.Canceled = true; OnGetInfoFinished(args); return true; } try { using (var client = OAuthUtility.CreateOAuthClient(ConsumerKey, ConsumerSecret, token)) { if (!Cts.Token.IsCancellationRequested) { using (Cts.Token.Register(() => client.CancelPendingRequests())) { if (fromForeground) { args.Json = await client.GetStringAsync(BaseUrl + path); } else { var info = client.GetStreamAsync(BaseUrl + path); var reader = new StreamReader(info.Result); args.Json = reader.ReadToEnd(); } args.Canceled = false; //args.Canceled = true; } OnGetInfoFinished(args); } } } catch (Exception) { CancelTask(); args.Canceled = true; OnGetInfoFinished(args); } return true; }
void client_GetDataFinished(object sender, GetInfoCompletedArgs args) { if (args.Canceled) { SetTile(true, "unavailable"); return; } if (string.IsNullOrEmpty(args.Json) || string.Equals(args.Json, "[]")) return; try { _balance.Load(args.Json); SetTile(false, string.Empty); } catch (Exception) { SetTile(true, "error"); } #if(DEBUG) Debug.WriteLine("Live tile: Tile has been updated"); #endif _running = false; }