Exemple #1
0
        public static IStringLocalizer XToCache(XAssembly xassembly, IMemoryCache cache, ISession session, IStringLocalizerFactory factory)
        {
            AssemblyName     name            = new AssemblyName(xassembly.XFullName);
            string           baseName        = string.Format("{0}.Properties.Resources", name.Name);
            IStringLocalizer stringLocalizer = factory.Create(baseName, name.Name);
            _XStringModel    xstring         = new _XStringModel(stringLocalizer);
            string           key             = typeof(_XStringModel).FullName + "#" + xstring.GetHashCode();

            using (ICacheEntry entry = cache.CreateEntry(key))
            {
                entry.SetValue(xstring);
            }
            session.SetString("string", key);
            return(stringLocalizer);
        }
Exemple #2
0
        public static IStringLocalizer XFromSession(IMemoryCache cache, ISession session)
        {
            IStringLocalizer stringLocalizer = null;
            string           key             = session.GetString("string");

            if (key != null)
            {
                _XStringModel xstring = null;
                if (cache.TryGetValue(key, out xstring) && xstring != null)
                {
                    stringLocalizer = xstring.XString;
                }
            }
            return(stringLocalizer);
        }