Exemplo n.º 1
0
        private static void WriteCache(String fileName, DynamicProxyLoader factory)
        {
            var proxyCache = CommonObjectCache.InitObject(ProxyCacheKey, ConcurrencyHelper.CreateDictionary <String, DynamicProxyLoader>);
            var hashCode   = fileName.ComputeMd5();

            proxyCache[hashCode] = factory;
        }
Exemplo n.º 2
0
        private static DbCommandOptimizer GetDbCommandOptimizer(DataContext dataContext)
        {
            var contextTypeName = dataContext.GetType().Name;

            var dbOptimizer = CommonObjectCache.InitObjectCache(contextTypeName, () => CreateDbOptimizer(dataContext));

            return(dbOptimizer);
        }
Exemplo n.º 3
0
        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;
                    }
                }
            }
        }
Exemplo n.º 4
0
        private static DynamicProxyLoader ReadCache(String fileName)
        {
            var proxyCache = CommonObjectCache.InitObject(ProxyCacheKey, ConcurrencyHelper.CreateDictionary <String, DynamicProxyLoader>);
            var hashCode   = fileName.ComputeMd5();

            var factory = proxyCache.GetValueOrDefault(hashCode);

            return(factory);
        }
Exemplo n.º 5
0
        public static ExpressionNode GetOrParse(String expression)
        {
            var hashCode = expression.ComputeMd5();
            var cache    = CommonObjectCache.InitObject(CacheKey, ConcurrencyHelper.CreateDictionary <String, ExpressionNode>);

            ExpressionNode node;

            if (!cache.TryGetValue(hashCode, out node))
            {
                node            = Parse(expression);
                cache[hashCode] = node;
            }

            return(node);
        }
Exemplo n.º 6
0
        private static bool ContainsCacheTranslation(String cacheKey)
        {
            var cache = CommonObjectCache.InitObjectCache(trnCacheKey, () => new Dictionary <String, String>());

            return(ContainsCacheTranslation(cache, cacheKey));
        }
Exemplo n.º 7
0
        private static void SetCacheTranslation(String cacheKey, String translateText)
        {
            var cache = CommonObjectCache.InitObjectCache(trnCacheKey, () => new Dictionary <String, String>());

            SetCacheTranslation(cache, cacheKey, translateText);
        }
Exemplo n.º 8
0
        private static String GetCacheTranslation(String cacheKey)
        {
            var cache = CommonObjectCache.InitObject(TrnCacheKey, () => new Dictionary <String, String>());

            return(GetCacheTranslation(cache, cacheKey));
        }
Exemplo n.º 9
0
        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;
        }
Exemplo n.º 10
0
        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;
        }
Exemplo n.º 11
0
        public static void RemoveConverter(Type type)
        {
            var mapping = CommonObjectCache.InitObjectCache("$[UIPropertyMapping_Converters]", () => new Dictionary <Type, Func <Object, Type, Object, Type> >());

            mapping.Remove(type);
        }
Exemplo n.º 12
0
        public static void RemoveSetter(Type type)
        {
            var mapping = CommonObjectCache.InitObjectCache("$[UIPropertyMapping_Setters]", () => new Dictionary <Type, Action <Control, Type, Object> >());

            mapping.Remove(type);
        }
Exemplo n.º 13
0
        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));
        }
Exemplo n.º 14
0
        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));
        }