//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; }
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); }
public static RetrievedData <TSub> Cast <T, TSub>(this RetrievedData <T> list) { return(new RetrievedData <TSub> { DataBatch = list.DataBatch.Cast <TSub>().ToList(), TotalCount = list.TotalCount }); }
public void Add(Dictionary <string, object> dict) { if (dict == null || dict.Count == 0) { return; } lock (RetrievedData) RetrievedData.Add(dict); }
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(); } }
//[JsonConstructor] public HomeRepository(RetrievedData rData) { this.Home = rData.Body.Homes; this.User = rData.Body.User; }