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.InitObject(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.InitObject(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 = $"{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 = $"{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.InitObject(TrnCacheKey, () => new Dictionary <String, String>());

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

            SetCacheTranslation(cache, cacheKey, translateText);
        }