private static DbCommandOptimizer GetDbCommandOptimizer(DataContext dataContext) { var contextTypeName = dataContext.GetType().Name; var dbOptimizer = CommonObjectCache.InitObjectCache(contextTypeName, () => CreateDbOptimizer(dataContext)); return(dbOptimizer); }
public static void PreloadTranslations(Control control, bool applyTranslations) { var moduleName = PermissionUtil.ModuleName; var languagePair = Thread.CurrentThread.CurrentCulture.Name; var cache = CommonObjectCache.InitObjectCache(trnCacheKey, () => new Dictionary <String, String>()); var controls = UserInterfaceUtil.TraverseChildren(control); var query = from ctl in controls let trn = ctl as ITranslatable where trn != null && !String.IsNullOrWhiteSpace(trn.Text) let defText = GetClearText(trn.TrnKey, languagePair, trn.Text) let trnKey = (String.IsNullOrWhiteSpace(trn.TrnKey) ? CryptographyUtil.ComputeMD5(defText) : trn.TrnKey) let cacheKey = String.Format("{0}|{1}|{2}", moduleName, trnKey, languagePair) select new { TrnKey = trnKey, CacheKey = cacheKey, DefaultText = defText, Translatable = trn, }; var list = query.ToList(); var lookup = list.ToLookup(n => n.CacheKey); var notInCacheControls = (from n in lookup where !ContainsCacheTranslation(cache, n.Key) select n).ToList(); var notInCacheContracts = (from n in notInCacheControls let p = n.FirstOrDefault() let m = new TranslationContract { TrnKey = p.TrnKey, DefaultText = p.DefaultText } select m).ToList(); var contracts = CommonProxy.GetTranslations(moduleName, languagePair, notInCacheContracts); foreach (var contract in contracts) { var cacheKey = String.Format("{0}|{1}|{2}", moduleName, contract.TrnKey, languagePair); SetCacheTranslation(cache, cacheKey, contract.TranslatedText); if (applyTranslations) { foreach (var item in lookup[cacheKey]) { var translatable = item.Translatable; translatable.TrnKey = item.TrnKey; translatable.Text = contract.TranslatedText; } } } }
private static bool ContainsCacheTranslation(String cacheKey) { var cache = CommonObjectCache.InitObjectCache(trnCacheKey, () => new Dictionary <String, String>()); return(ContainsCacheTranslation(cache, cacheKey)); }
private static void SetCacheTranslation(String cacheKey, String translateText) { var cache = CommonObjectCache.InitObjectCache(trnCacheKey, () => new Dictionary <String, String>()); SetCacheTranslation(cache, cacheKey, translateText); }
public static void RegisterConverter(Type type, Func <Object, Type, Object, Type> func) { var mapping = CommonObjectCache.InitObjectCache("$[UIPropertyMapping_Converters]", () => new Dictionary <Type, Func <Object, Type, Object, Type> >()); mapping[type] = func; }
public static void RegisterSetter(Type type, Action <Control, Type, Object> action) { var mapping = CommonObjectCache.InitObjectCache("$[UIPropertyMapping_Setters]", () => new Dictionary <Type, Action <Control, Type, Object> >()); mapping[type] = action; }
public static void RemoveConverter(Type type) { var mapping = CommonObjectCache.InitObjectCache("$[UIPropertyMapping_Converters]", () => new Dictionary <Type, Func <Object, Type, Object, Type> >()); mapping.Remove(type); }
public static void RemoveSetter(Type type) { var mapping = CommonObjectCache.InitObjectCache("$[UIPropertyMapping_Setters]", () => new Dictionary <Type, Action <Control, Type, Object> >()); mapping.Remove(type); }
public static Func <Object, Type, Object> GetConverter(Type type) { var mapping = CommonObjectCache.InitObjectCache("$[UIPropertyMapping_Converters]", () => new Dictionary <Type, Func <Object, Type, Object> >()); return(mapping.GetValueOrDefault(type)); }
public static Action <Control, Type, Object> GetSetter(Type type) { var mapping = CommonObjectCache.InitObjectCache("$[UIPropertyMapping_Setters]", () => new Dictionary <Type, Action <Control, Type, Object> >()); return(mapping.GetValueOrDefault(type)); }