public IList <IFileCultureInfo> Get(ICultureExpression requestedCulture, string directory, string extension)
        {
            string culture = requestedCulture.DisplayName;
            CultureFileCollectionPage culturePage = cultureCache.Get(culture, key => RetrivationResult <CultureFileCollectionPage> .Create(new CultureFileCollectionPage(requestedCulture, perCultureCacheSize)));

            return(culturePage.Get(directory, extension, env));
        }
            internal IList <IFileCultureInfo> Get(string directory, string extension, IHostingEnvironment env)
            {
                string resourceKey = $"{directory}/?.?.{extension}";

                return(cache.Get(resourceKey, key =>
                {
                    IList <IFileCultureInfo> result = ResourceRequestHelper.FindFiles(directory, extension, culture, env);
                    return RetrivationResult <IList <IFileCultureInfo> > .Create(result);
                }));
            }
Beispiel #3
0
 internal virtual string Get(string code, string defaultName)
 {
     return(ContentCache.Get(code, key =>
     {
         if (values.TryReadAs <string>($"{key}.name", out string value) &&
             value != null)
         {
             return RetrivationResult <string> .Create(value);
         }
         return RetrivationResult <string> .SupressResult(defaultName);
     }));
 }
Beispiel #4
0
            internal IFileCultureInfo Get(string directory, string name, string extension, IHostingEnvironment env, ICultureOption cultureOption)
            {
                string resourceKey = $"{directory}/{name}.?.{extension}";

                return(cache.Get(resourceKey, key =>
                {
                    if (ResourceRequestHelper.TryFindFile(directory, name, extension, culture, env, cultureOption, out IFileCultureInfo result))
                    {
                        return RetrivationResult <IFileCultureInfo> .Create(result);
                    }
                    return RetrivationResult <IFileCultureInfo> .Create(null);
                }));
            }
Beispiel #5
0
        public string Get(HttpContext httpContext, string code, string defaultName, ICultureExpression requestedCulture)
        {
            string      culture     = requestedCulture.DisplayName;
            CulturePage culturePage = cultureCache.Get(culture, key =>
            {
                string basePath = matchingOption.ResourceDirectory;
                IList <IFileCultureInfo> files = ResourceRequestHelper.FindFiles(basePath, "json", requestedCulture, httpContext);
                if (files.Count <= 0)
                {
                    files = ResourceRequestHelper.FindFiles(basePath, "json", cultureOption.DefaultCulture, httpContext);
                }
                if (files.Count <= 0)
                {
                    return(RetrivationResult <CulturePage> .Create(new EmptyCulturePage()));
                }

                string filePath;
                IHostingEnvironment env = httpContext.RequestServices.GetRequiredService <IHostingEnvironment>();
                IFileProvider provider  = env.ContentRootFileProvider;
                SetRecord values        = new SetRecord();
                foreach (IFileCultureInfo file in files.Reverse())
                {
                    filePath          = file.RelativePath;
                    IFileInfo current = provider.GetFileInfo(filePath);
                    try
                    {
                        using (Stream fileStream = current.CreateReadStream())
                        {
                            SetRecord fileContent = (SetRecord)Hake.Extension.ValueRecord.Json.Converter.ReadJson(fileStream, !matchingOption.IsCaseSensitive);
                            CombineSetRecord(values, fileContent);
                        }
                    }
                    catch
                    {
                    }
                }
                return(RetrivationResult <CulturePage> .Create(new CulturePage(perCultureCapacity, values)));
            });

            return(culturePage.ContentCache.Get(code, key =>
            {
                if (culturePage.Values.TryReadAs <string>($"{key}.name", out string value) &&
                    value != null)
                {
                    return RetrivationResult <string> .Create(value);
                }
                return RetrivationResult <string> .SupressResult(defaultName);
            }));
        }