コード例 #1
0
ファイル: DataSource.cs プロジェクト: AlexKven/OneAppAway-RTM
 //private Task<RetrievedData<T>> GenericGetDataAsync<T, F>(string id, DataSourcePreference preference, CancellationToken cancellationToken, Func<Func<Task<RetrievedData<T>>>> runFunction,  )
 //{
 //    var result = new RetrievedData<T>();
 //    foreach (var source in Sources)
 //    {
 //        if (result.HasData)
 //            continue;
 //        if ((preference & DataSourcePreference.MemoryCache) == 0 && source.IsMemoryCache)
 //            continue;
 //        if ((preference & DataSourcePreference.Offline) == 0 && source.IsOfflineSource)
 //            continue;
 //        if ((preference & DataSourcePreference.Online) == 0 && !source.IsOfflineSource)
 //            continue;
 //        if ((source.GetTransitStopFunction & DataSourceFunctionType.Provision) == DataSourceFunctionType.Provision)
 //            result = await source.GetTransitStop(id, cancellationToken);
 //    }
 //    if (result.HasData)
 //    {
 //        foreach (var source in Sources)
 //        {
 //            if (!result.HasData)
 //                continue;
 //            if ((preference & DataSourcePreference.MemoryCache) == 0 && source.IsMemoryCache)
 //                continue;
 //            if ((preference & DataSourcePreference.Offline) == 0 && source.IsOfflineSource)
 //                continue;
 //            if ((preference & DataSourcePreference.Online) == 0 && !source.IsOfflineSource)
 //                continue;
 //            if ((source.GetTransitStopFunction & DataSourceFunctionType.Correction) == DataSourceFunctionType.Correction)
 //                result = await source.CorrectTransitStop(result.Data, cancellationToken);
 //        }
 //    }
 //    return result;
 //}
 
 public static async Task<RetrievedData<TransitStop>> GetTransitStopAsync(string id, DataSourcePreference preference, CancellationToken cancellationToken)
 {
     var result = new RetrievedData<TransitStop>();
     foreach (var source in Sources)
     {
         if (cancellationToken.IsCancellationRequested)
             throw new OperationCanceledException();
         if (result.HasData || !source.IsQualified(preference))
             continue;
         if ((source.GetTransitStopFunction & DataSourceFunctionType.Provision) == DataSourceFunctionType.Provision)
             result = await source.GetTransitStop(id, cancellationToken);
     }
     if (result.HasData)
     {
         if (cancellationToken.IsCancellationRequested)
             throw new OperationCanceledException();
         foreach (var source in Sources)
         {
             if (!result.HasData || !source.IsQualified(preference))
                 continue;
             if ((source.GetTransitStopFunction & DataSourceFunctionType.Correction) == DataSourceFunctionType.Correction)
                 result = await source.CorrectTransitStop(result.Data, cancellationToken);
         }
     }
     return result;
 }
コード例 #2
0
 public HomeDataService(RetrievedData rData)
 {
     if(this.HomeRepository == null)
     {
         this.HomeRepository = new HomeRepository(rData);
     }
 }
        public static RetrievedData GetData(string accessToken)
        {
            RetrievedData retrievedData = null;

            try
            {
                using (var client = new HttpClient())
                {
                    var accessTokenDic = new Dictionary <string, string>
                    {
                        { "access_token", accessToken }
                    };

                    var encodedAccessToken = new FormUrlEncodedContent(accessTokenDic);

                    var response = client.PostAsync(Constants.Url.homeDataEndPointUrl, encodedAccessToken);

                    var responseString = response.Result.Content.ReadAsStringAsync();
                    responseString.Wait();

                    retrievedData = JsonConvert.DeserializeObject <RetrievedData>(responseString.Result);
                }
            }
            catch (Exception)
            {
                // Handle Exception
            }

            return(retrievedData);
        }
コード例 #4
0
 public static RetrievedData <TSub> Cast <T, TSub>(this RetrievedData <T> list)
 {
     return(new RetrievedData <TSub>
     {
         DataBatch = list.DataBatch.Cast <TSub>().ToList(),
         TotalCount = list.TotalCount
     });
 }
コード例 #5
0
            public void Add(Dictionary <string, object> dict)
            {
                if (dict == null || dict.Count == 0)
                {
                    return;
                }

                lock (RetrievedData)
                    RetrievedData.Add(dict);
            }
コード例 #6
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            string accessToken = LoginHelper.ValidateLogin(userID.Text, password.Text);

            if (!string.IsNullOrWhiteSpace(accessToken))
            {
                RetrievedData retrievedData = RetrieveDataHelper.GetData(accessToken);
                homeDataService = new HomeDataService(retrievedData);

                var    intent         = new Intent(this, typeof(WelcomeHomeActivity));
                string serializedData = JsonConvert.SerializeObject(homeDataService);
                intent.PutExtra("HomeDataService", serializedData);
                StartActivity(intent);
            }
            else
            {
                Android.Widget.Toast.MakeText(this, "Login Failed! Please Check ID or Password.", Android.Widget.ToastLength.Short).Show();
            }
        }
コード例 #7
0
 //[JsonConstructor]
 public HomeRepository(RetrievedData rData)
 {
     this.Home = rData.Body.Homes;
     this.User = rData.Body.User;
 }