示例#1
0
 protected void OnGetInfoFinished(GetInfoCompletedArgs args)
 {
     if (GetInfoFinished != null)
     {
         GetInfoFinished(this, args);
     }
 }
示例#2
0
文件: Api.cs 项目: JanJoris/VikingApp
 protected void OnGetInfoFinished(GetInfoCompletedArgs args)
 {
     if (GetInfoFinished != null)
     {
         GetInfoFinished(this, args);
     }
 }
示例#3
0
        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);
        }
示例#4
0
文件: Api.cs 项目: JanJoris/VikingApp
 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;
 }
示例#5
0
        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;
        }