public static async Task <JObject> GetAllRecordsForAnEntityAsync(string key, string entityLogicalName) { var cache = RedisSharedConnection.Connection.GetDatabase(); // Try to get the entity from the cache. var json = await cache.StringGetAsync(key).ConfigureAwait(false); var value = string.IsNullOrWhiteSpace(json) ? default(JObject) : JsonConvert.DeserializeObject <JObject>(json); if (value == null) // Cache miss { // If there's a cache miss, get the entity from the original store and cache it. // Code has been omitted because it is data store dependent. // string configpath = Environment.CurrentDirectory + "\\web.config"; string connectionString = ConfigurationManager.ConnectionStrings["default"].ConnectionString; APIOperations operations = new APIOperations(); operations.ConnectToCRMWithConnectionString(connectionString); operations.getWebAPIVersion().Wait(); Task <JObject> returnVal; // get All returnVal = Task.Run(async() => await operations.GetAllRecordsForAnEntity(entityLogicalName, String.Empty)); returnVal.Wait(); value = returnVal.Result; // Avoid caching a null value. if (value != null) { // Put the item in the cache with a custom expiration time that // depends on how critical it is to have stale data. await cache.StringSetAsync(key, JsonConvert.SerializeObject(value)).ConfigureAwait(false); //await cache.StringSetAsync(key, value).ConfigureAwait(false); await cache.KeyExpireAsync(key, TimeSpan.FromMinutes(DefaultExpirationTimeInMinutes)).ConfigureAwait(false); } } return(value); }
/// <summary> /// Gets all for online operations. /// </summary> /// <returns>The all.</returns> /// <param name="operation">Operation.</param> /// <param name="parameters">Parameters.</param> public async Task <List <T> > GetAllRemoteData(APIOperations operation, string parameters) { try { if (!await connectivityFunctionsService.IsConnectedAsync()) { throw new ConnectionException(); } var data = await App.AppHttpClient.GetAsync($"{operation.GetDescription()}{parameters}"); if (data != null && data.IsSuccessStatusCode) { var dataAsString = await data.Content.ReadAsStringAsync(); if (!string.IsNullOrEmpty(dataAsString)) { var jsonObject = JObject.Parse(dataAsString); var entityName = typeof(T).Name.ToLower(); var obj = jsonObject[entityName]; var entities = ((JArray)obj).ToObject <List <T> >(); if (typeof(T) == typeof(Results)) { entities = movieServices.AssociateGenresWithMovies(entities as List <Results>) as List <T>; } if (!App.DisableDatabaseOperations) { entities.ForEach((o) => Add(o as T)); } return(GetAll()); } } throw new FetchRemoteDataException(); } catch { mobileCeterCrashesService.AskBeforeSendCrashReport(); throw new FetchRemoteDataException(); } }
public void GetAPIVersionWithConnectionString() { APIOperations operations = new APIOperations(); try { string connectionString = ConfigurationManager.ConnectionStrings["default"].ConnectionString; //string appconfigPath = Direc operations.ConnectToCRMWithConnectionString(connectionString); Task.WaitAll(Task.Run(async() => await operations.RunAsync())); //operations.getWebAPIVersion().RunSynchronously(); } catch { throw; } }
/// <summary> /// Configures the parameters. /// </summary> /// <returns>The parameters.</returns> /// <param name="operation">Operation.</param> /// <param name="page">Page.</param> /// <param name="query">Query.</param> string ConfigureParameters(APIOperations operation, int page = 1, string query = "") { switch (operation) { case APIOperations.GetMovieListURLAddress: return($"api_key={settingsService.Get<string>("APIKEY")}&page={page}"); case APIOperations.SearchMovieURLAddres: return($"api_key={settingsService.Get<string>("APIKEY")}&query={query}&page={page}"); case APIOperations.Genres: return($"api_key={settingsService.Get<string>("APIKEY")}"); case APIOperations.Configuration: return($"api_key={settingsService.Get<string>("APIKEY")}"); default: throw new InvalidOperationException(); } }
public void GetAPIVersion() { APIOperations operations = new APIOperations(); try { string configpath = Environment.CurrentDirectory + "\\app.config"; //string appconfigPath = Direc operations.ConnectToCRM(new string[1] { configpath }); Task.WaitAll(Task.Run(async() => await operations.RunAsync())); //operations.getWebAPIVersion().RunSynchronously(); } catch { throw; } }
/// <summary> /// Get the specified query, operation and parameters for online operations. /// </summary> /// <returns>The get.</returns> /// <param name="operation">Operation.</param> /// <param name="parameters">Parameters.</param> public async Task <T> GetRemoteData(APIOperations operation, string parameters) { try { if (!await connectivityFunctionsService.IsConnectedAsync()) { throw new ConnectionException(); } var data = await App.AppHttpClient.GetAsync($"{operation.GetDescription()}{parameters}"); if (data != null && data.IsSuccessStatusCode) { var dataAsString = await data.Content.ReadAsStringAsync(); if (!string.IsNullOrEmpty(dataAsString)) { var jsonObject = JObject.Parse(dataAsString); var entityName = typeof(T).Name.ToLower(); var obj = jsonObject[entityName]; var entity = ((JObject)obj).ToObject <T>(); if (!App.DisableDatabaseOperations) { Add(entity); } var all = GetAll(); return(all.Last()); } } throw new FetchRemoteDataException(); } catch { mobileCeterCrashesService.AskBeforeSendCrashReport(); throw new FetchRemoteDataException(); } }