private static T GetFromDatabase <T>(string key, string folder) { try { using (var ctx = new MixCacheDbContext()) { var cache = ctx.MixCache.FirstOrDefault(m => m.Id == $"{folder}/{key}"); if (cache != null) { try { JObject jobj = JObject.Parse(cache.Value); return(jobj.ToObject <T>()); } catch (Exception ex) { Console.Write(ex); return(default);
/// <summary> /// Step 1 /// - Init Culture /// - Init System pages /// </summary> /// <param name="siteName"></param> /// <param name="culture"></param> /// <returns></returns> public static async Task <RepositoryResponse <bool> > InitCms(string siteName, InitCulture culture) { RepositoryResponse <bool> result = new RepositoryResponse <bool>(); MixCmsContext context = null; MixCmsAccountContext accountContext = null; MixCacheDbContext cacheContext = null; try { string cnn = MixService.GetConnectionString(MixConstants.CONST_CMS_CONNECTION); if (!string.IsNullOrEmpty(cnn)) { context = MixService.GetDbContext(); accountContext = MixService.GetAccountDbContext(); cacheContext = MixCacheService.GetCacheDbContext(); await context.Database.MigrateAsync(); await accountContext.Database.MigrateAsync(); await cacheContext.Database.MigrateAsync(); var countCulture = context.MixCulture.Count(); var pendingMigration = context.Database.GetPendingMigrations().Count(); if (pendingMigration == 0) { return(await InitSiteData(siteName, culture)); } } return(result); } catch (Exception ex) // TODO: Add more specific exeption types instead of Exception only { result.IsSucceed = false; result.Exception = ex; return(result); } finally { context?.Dispose(); accountContext?.Dispose(); } }