public async Task <JObject> GetMyEntityAsync(string key, string entityLogicalName, Guid recordID) { 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) ? string.Empty : (string)json; // ? default(Entity) // : JsonConvert.DeserializeObject<Entity>(json); if (value == string.Empty) // 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; operations.ConnectToCRMWithConnectionString(connectionString); operations.getWebAPIVersion().Wait(); Task <JObject> returnVal; //value = operations.CreateWithAssociationAsync() if (recordID == Guid.Empty) { // get All returnVal = Task.Run(async() => await operations.GetEntity(entityLogicalName, String.Empty)); } else { returnVal = Task.Run(async() => await operations.GetEntityByID(entityLogicalName, String.Empty, recordID)); } 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); }
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; } }