diff --git a/src/OrchardCore/OrchardCore.Abstractions/OrchardCoreConstants.cs b/src/OrchardCore/OrchardCore.Abstractions/OrchardCoreConstants.cs new file mode 100644 index 00000000000..384c6b3b4be --- /dev/null +++ b/src/OrchardCore/OrchardCore.Abstractions/OrchardCoreConstants.cs @@ -0,0 +1,14 @@ +namespace OrchardCore; + +public class OrchardCoreConstants +{ + public class Shell + { + public const string TenantsFileName = "tenants.json"; + } + + public class Configuration + { + public const string ApplicationSettingsFileName = "appsettings.json"; + } +} diff --git a/src/OrchardCore/OrchardCore.Infrastructure/Shells.Database/Configuration/DatabaseShellConfigurationSources.cs b/src/OrchardCore/OrchardCore.Infrastructure/Shells.Database/Configuration/DatabaseShellConfigurationSources.cs index e1433bb7f0c..6a9dfe129be 100644 --- a/src/OrchardCore/OrchardCore.Infrastructure/Shells.Database/Configuration/DatabaseShellConfigurationSources.cs +++ b/src/OrchardCore/OrchardCore.Infrastructure/Shells.Database/Configuration/DatabaseShellConfigurationSources.cs @@ -140,7 +140,7 @@ public async Task RemoveAsync(string tenant) private async Task TryMigrateFromFileAsync(string tenant, JsonObject configurations) { var tenantFolder = Path.Combine(_container, tenant); - var appsettings = Path.Combine(tenantFolder, "appsettings.json"); + var appsettings = Path.Combine(tenantFolder, OrchardCoreConstants.Configuration.ApplicationSettingsFileName); if (!File.Exists(appsettings)) { diff --git a/src/OrchardCore/OrchardCore.Infrastructure/Shells.Database/Configuration/DatabaseShellsSettingsSources.cs b/src/OrchardCore/OrchardCore.Infrastructure/Shells.Database/Configuration/DatabaseShellsSettingsSources.cs index 8f7d90872f4..7148942297e 100644 --- a/src/OrchardCore/OrchardCore.Infrastructure/Shells.Database/Configuration/DatabaseShellsSettingsSources.cs +++ b/src/OrchardCore/OrchardCore.Infrastructure/Shells.Database/Configuration/DatabaseShellsSettingsSources.cs @@ -36,7 +36,7 @@ public DatabaseShellsSettingsSources( _shellContextFactory = shellContextFactory; - _tenants = Path.Combine(shellOptions.Value.ShellsApplicationDataPath, "tenants.json"); + _tenants = Path.Combine(shellOptions.Value.ShellsApplicationDataPath, OrchardCoreConstants.Shell.TenantsFileName); } public async Task AddSourcesAsync(IConfigurationBuilder builder) diff --git a/src/OrchardCore/OrchardCore.Shells.Azure/Configuration/BlobShellConfigurationSources.cs b/src/OrchardCore/OrchardCore.Shells.Azure/Configuration/BlobShellConfigurationSources.cs index b5f3541f482..fabac0bde01 100644 --- a/src/OrchardCore/OrchardCore.Shells.Azure/Configuration/BlobShellConfigurationSources.cs +++ b/src/OrchardCore/OrchardCore.Shells.Azure/Configuration/BlobShellConfigurationSources.cs @@ -37,7 +37,7 @@ public BlobShellConfigurationSources( public async Task AddSourcesAsync(string tenant, IConfigurationBuilder builder) { - var appSettings = IFileStoreExtensions.Combine(null, _container, tenant, "appsettings.json"); + var appSettings = IFileStoreExtensions.Combine(null, _container, tenant, OrchardCoreConstants.Configuration.ApplicationSettingsFileName); var fileInfo = await _shellsFileStore.GetFileInfoAsync(appSettings); if (fileInfo == null && _blobOptions.MigrateFromFiles) @@ -57,7 +57,7 @@ public async Task AddSourcesAsync(string tenant, IConfigurationBuilder builder) public async Task SaveAsync(string tenant, IDictionary data) { - var appsettings = IFileStoreExtensions.Combine(null, _container, tenant, "appsettings.json"); + var appsettings = IFileStoreExtensions.Combine(null, _container, tenant, OrchardCoreConstants.Configuration.ApplicationSettingsFileName); var fileInfo = await _shellsFileStore.GetFileInfoAsync(appsettings); @@ -94,7 +94,7 @@ public async Task SaveAsync(string tenant, IDictionary data) public async Task RemoveAsync(string tenant) { - var appsettings = IFileStoreExtensions.Combine(null, _container, tenant, "appsettings.json"); + var appsettings = IFileStoreExtensions.Combine(null, _container, tenant, OrchardCoreConstants.Configuration.ApplicationSettingsFileName); var fileInfo = await _shellsFileStore.GetFileInfoAsync(appsettings); if (fileInfo != null) @@ -105,7 +105,7 @@ public async Task RemoveAsync(string tenant) private async Task TryMigrateFromFileAsync(string tenant, string destFile) { - var tenantFile = Path.Combine(_fileStoreContainer, tenant, "appsettings.json"); + var tenantFile = Path.Combine(_fileStoreContainer, tenant, OrchardCoreConstants.Configuration.ApplicationSettingsFileName); if (!File.Exists(tenantFile)) { return false; diff --git a/src/OrchardCore/OrchardCore.Shells.Azure/Configuration/BlobShellsConfigurationSources.cs b/src/OrchardCore/OrchardCore.Shells.Azure/Configuration/BlobShellsConfigurationSources.cs index 25b028162c2..3c8b423f49f 100644 --- a/src/OrchardCore/OrchardCore.Shells.Azure/Configuration/BlobShellsConfigurationSources.cs +++ b/src/OrchardCore/OrchardCore.Shells.Azure/Configuration/BlobShellsConfigurationSources.cs @@ -11,6 +11,9 @@ namespace OrchardCore.Shells.Azure.Configuration { public class BlobShellsConfigurationSources : IShellsConfigurationSources { + private static readonly string _appSettings = + Path.GetFileNameWithoutExtension(OrchardCoreConstants.Configuration.ApplicationSettingsFileName); + private readonly IShellsFileStore _shellsFileStore; private readonly BlobShellStorageOptions _blobOptions; @@ -27,28 +30,28 @@ IOptions shellOptions _shellsFileStore = shellsFileStore; _environment = hostingEnvironment.EnvironmentName; _blobOptions = blobOptions; - _fileSystemAppSettings = Path.Combine(shellOptions.Value.ShellsApplicationDataPath, "appsettings"); + _fileSystemAppSettings = Path.Combine(shellOptions.Value.ShellsApplicationDataPath, _appSettings); } public async Task AddSourcesAsync(IConfigurationBuilder builder) { - var appSettingsFileInfo = await _shellsFileStore.GetFileInfoAsync("appsettings.json"); + var appSettingsFileInfo = await _shellsFileStore.GetFileInfoAsync(OrchardCoreConstants.Configuration.ApplicationSettingsFileName); if (appSettingsFileInfo == null && _blobOptions.MigrateFromFiles) { - if (await TryMigrateFromFileAsync($"{_fileSystemAppSettings}.json", "appsettings.json")) + if (await TryMigrateFromFileAsync($"{_fileSystemAppSettings}.json", OrchardCoreConstants.Configuration.ApplicationSettingsFileName)) { - appSettingsFileInfo = await _shellsFileStore.GetFileInfoAsync("appsettings.json"); + appSettingsFileInfo = await _shellsFileStore.GetFileInfoAsync(OrchardCoreConstants.Configuration.ApplicationSettingsFileName); } } if (appSettingsFileInfo != null) { - var stream = await _shellsFileStore.GetFileStreamAsync("appsettings.json"); + var stream = await _shellsFileStore.GetFileStreamAsync(OrchardCoreConstants.Configuration.ApplicationSettingsFileName); builder.AddTenantJsonStream(stream); } - var environmentAppSettingsFileName = $"appsettings.{_environment}.json"; + var environmentAppSettingsFileName = $"{_appSettings}.{_environment}.json"; var environmentAppSettingsFileInfo = await _shellsFileStore.GetFileInfoAsync(environmentAppSettingsFileName); if (environmentAppSettingsFileInfo == null && _blobOptions.MigrateFromFiles) { diff --git a/src/OrchardCore/OrchardCore.Shells.Azure/Configuration/BlobShellsSettingsSources.cs b/src/OrchardCore/OrchardCore.Shells.Azure/Configuration/BlobShellsSettingsSources.cs index c741bace9db..fe9c5d27ae7 100644 --- a/src/OrchardCore/OrchardCore.Shells.Azure/Configuration/BlobShellsSettingsSources.cs +++ b/src/OrchardCore/OrchardCore.Shells.Azure/Configuration/BlobShellsSettingsSources.cs @@ -14,8 +14,6 @@ namespace OrchardCore.Shells.Azure.Configuration { public class BlobShellsSettingsSources : IShellsSettingsSources { - private const string TenantsBlobName = "tenants.json"; - private readonly IShellsFileStore _shellsFileStore; private readonly BlobShellStorageOptions _blobOptions; @@ -27,17 +25,18 @@ public BlobShellsSettingsSources(IShellsFileStore shellsFileStore, { _shellsFileStore = shellsFileStore; _blobOptions = blobOptions; - _tenantsFileSystemName = Path.Combine(shellOptions.Value.ShellsApplicationDataPath, TenantsBlobName); + _tenantsFileSystemName = Path.Combine(shellOptions.Value.ShellsApplicationDataPath, OrchardCoreConstants.Shell.TenantsFileName); } public async Task AddSourcesAsync(IConfigurationBuilder builder) { - var fileInfo = await _shellsFileStore.GetFileInfoAsync(TenantsBlobName); + var fileInfo = await _shellsFileStore.GetFileInfoAsync(OrchardCoreConstants.Shell.TenantsFileName); + if (fileInfo == null && _blobOptions.MigrateFromFiles) { if (await TryMigrateFromFileAsync()) { - fileInfo = await _shellsFileStore.GetFileInfoAsync(TenantsBlobName); + fileInfo = await _shellsFileStore.GetFileInfoAsync(OrchardCoreConstants.Shell.TenantsFileName); } else { @@ -47,7 +46,7 @@ public async Task AddSourcesAsync(IConfigurationBuilder builder) if (fileInfo != null) { - var stream = await _shellsFileStore.GetFileStreamAsync(TenantsBlobName); + var stream = await _shellsFileStore.GetFileStreamAsync(OrchardCoreConstants.Shell.TenantsFileName); builder.AddTenantJsonStream(stream); } } @@ -58,11 +57,11 @@ public async Task SaveAsync(string tenant, IDictionary data) { JsonObject tenantsSettings; - var fileInfo = await _shellsFileStore.GetFileInfoAsync(TenantsBlobName); + var fileInfo = await _shellsFileStore.GetFileInfoAsync(OrchardCoreConstants.Shell.TenantsFileName); if (fileInfo != null) { - using var stream = await _shellsFileStore.GetFileStreamAsync(TenantsBlobName); + using var stream = await _shellsFileStore.GetFileStreamAsync(OrchardCoreConstants.Shell.TenantsFileName); tenantsSettings = await JObject.LoadAsync(stream); } else @@ -88,17 +87,17 @@ public async Task SaveAsync(string tenant, IDictionary data) var tenantsSettingsString = tenantsSettings.ToJsonString(JOptions.Default); using var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(tenantsSettingsString)); - await _shellsFileStore.CreateFileFromStreamAsync(TenantsBlobName, memoryStream); + await _shellsFileStore.CreateFileFromStreamAsync(OrchardCoreConstants.Shell.TenantsFileName, memoryStream); } public async Task RemoveAsync(string tenant) { - var fileInfo = await _shellsFileStore.GetFileInfoAsync(TenantsBlobName); + var fileInfo = await _shellsFileStore.GetFileInfoAsync(OrchardCoreConstants.Shell.TenantsFileName); if (fileInfo != null) { JsonObject tenantsSettings; - using (var stream = await _shellsFileStore.GetFileStreamAsync(TenantsBlobName)) + using (var stream = await _shellsFileStore.GetFileStreamAsync(OrchardCoreConstants.Shell.TenantsFileName)) { tenantsSettings = await JObject.LoadAsync(stream); } @@ -108,7 +107,7 @@ public async Task RemoveAsync(string tenant) var tenantsSettingsString = tenantsSettings.ToJsonString(JOptions.Default); using var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(tenantsSettingsString)); - await _shellsFileStore.CreateFileFromStreamAsync(TenantsBlobName, memoryStream); + await _shellsFileStore.CreateFileFromStreamAsync(OrchardCoreConstants.Shell.TenantsFileName, memoryStream); } } @@ -120,7 +119,7 @@ private async Task TryMigrateFromFileAsync() } using var file = File.OpenRead(_tenantsFileSystemName); - await _shellsFileStore.CreateFileFromStreamAsync(TenantsBlobName, file); + await _shellsFileStore.CreateFileFromStreamAsync(OrchardCoreConstants.Shell.TenantsFileName, file); return true; } diff --git a/src/OrchardCore/OrchardCore/Shell/Configuration/ShellsSettingsSources.cs b/src/OrchardCore/OrchardCore/Shell/Configuration/ShellsSettingsSources.cs index 2deb101741f..66948c5f939 100644 --- a/src/OrchardCore/OrchardCore/Shell/Configuration/ShellsSettingsSources.cs +++ b/src/OrchardCore/OrchardCore/Shell/Configuration/ShellsSettingsSources.cs @@ -14,7 +14,7 @@ public class ShellsSettingsSources : IShellsSettingsSources public ShellsSettingsSources(IOptions shellOptions) { - _tenants = Path.Combine(shellOptions.Value.ShellsApplicationDataPath, "tenants.json"); + _tenants = Path.Combine(shellOptions.Value.ShellsApplicationDataPath, OrchardCoreConstants.Shell.TenantsFileName); } public Task AddSourcesAsync(IConfigurationBuilder builder)