public void ItShouldComputeTheResourcePath() { var path = ResourcePathHelper.ComputeBasePath(Assembly, BaseName); var expectedPath = BaseName .Replace(Assembly.GetName().Name + ".", string.Empty, StringComparison.Ordinal) .Replace('.', '/'); Assert.Equal(expectedPath, path); }
///<inheritdoc/> public async ValueTask <IReadOnlyDictionary <string, string>?> TryLoadAsync( HttpHostedJsonLocalizationOptions options, Assembly assembly, string baseName, CultureInfo cultureInfo) { if (assembly == null) { throw new ArgumentNullException(nameof(assembly)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } var assemblyName = assembly.GetName().Name; var rootPath = (options.ApplicationAssembly == assembly) ? string.Empty : $"_content/{assemblyName}/"; if (!string.IsNullOrEmpty(options.ResourcesPath)) { rootPath = $"{rootPath}{options.ResourcesPath}/"; } var basePath = $"{rootPath}{ResourcePathHelper.ComputeBasePath(assembly, baseName)}"; return(await CultureInfoHelper.WalkThoughCultureInfoParentsAsync(cultureInfo, cultureName => { var uri = string.IsNullOrEmpty(cultureName) ? new Uri($"{basePath}.json", UriKind.Relative) : new Uri($"{basePath}{options.CultureSeparator}{cultureName}.json", UriKind.Relative); this.logger.LogDebug($"Loading static assets data from {uri}"); lock (Cache) { if (!Cache.TryGetValue(uri, out var loadingTask)) { loadingTask = TryLoadFromUriAsync(uri, options.JsonSerializerOptions); Cache.Add(uri, loadingTask); } else if (loadingTask.IsFaulted) { loadingTask = TryLoadFromUriAsync(uri, options.JsonSerializerOptions); Cache[uri] = loadingTask; } return loadingTask; } }) .ConfigureAwait(false)); }
///<inheritdoc/> public async ValueTask <IReadOnlyDictionary <string, string>?> TryLoadAsync( EmbeddedJsonLocalizationOptions options, Assembly assembly, string baseName, CultureInfo cultureInfo) { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (cultureInfo == null) { throw new ArgumentNullException(nameof(cultureInfo)); } var embeddedFileProvider = GetFileProvider(assembly); var basePath = ResourcePathHelper.ComputeBasePath(assembly, baseName); return(await LoadStringMapAsync(embeddedFileProvider, options.ResourcesPath, basePath, cultureInfo, options.JsonSerializerOptions) .ConfigureAwait(false)); }