public IEnumerable <ILocalizedObject> GetAll(CultureInfo culture)
        {
            var result = LocalizationCache.Get <IEnumerable <ILocalizedObject> >(culture.Name);

            if (result == null || !result.Any())
            {
                using (var context = new LocalizationContext())
                {
                    result = context.Objects.Where(obj => obj.LocaleId == culture.LCID && obj.Scope.StartsWith("~/")).ToList();
                }

                LocalizationCache.Set(culture.Name, result);
            }

            return(result);
        }
        public ILocalizedObject Get(int key)
        {
            var obj = LocalizationCache.Get <ILocalizedObject>(key.ToString());

            if (obj == null)
            {
                using (var context = new LocalizationContext())
                {
                    obj = context.Objects.SingleOrDefault(o => o.Key == key);
                }

                LocalizationCache.Set(key.ToString(), obj);
            }

            return(obj);
        }
Пример #3
0
        public IEnumerable <ILocalizedObject> GetAll(CultureInfo culture, string scope = null)
        {
            IEnumerable <ILocalizedObject> result = null;

            if (culture != null && scope == null)
            {
                result = LocalizationCache.Get <IEnumerable <ILocalizedObject> >(culture.Name);
            }

            if (result == null || !result.Any())
            {
                using (var context = new LocalizationContext())
                {
                    var query = context.Objects.Where(obj => obj.Scope.StartsWith("~/"));

                    if (culture != null)
                    {
                        query = query.Where(obj => obj.LocaleId == culture.LCID);
                    }

                    if (scope != null)
                    {
                        query = query.Where(obj => obj.Scope == scope);
                    }

                    result = query.ToList();
                }

                if (culture != null && scope == null)
                {
                    LocalizationCache.Set(culture.Name, result);
                }
            }

            return(result);
        }