mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Partially reverting the changes made related to #20337 to fix the errors caused by the limitations by NHibernate.
This commit is contained in:
@@ -103,6 +103,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Services\Environment\Configuration\DefaultPlatformConfigurationAccessor.cs" />
|
<Compile Include="Services\Environment\Configuration\DefaultPlatformConfigurationAccessor.cs" />
|
||||||
<Compile Include="Services\Environment\Configuration\IPlatformConfigurationAccessor.cs" />
|
<Compile Include="Services\Environment\Configuration\IPlatformConfigurationAccessor.cs" />
|
||||||
|
<Compile Include="Services\Environment\Configuration\PlatformConfiguration.cs" />
|
||||||
<Compile Include="Services\TaskLease\AzureMachineNameProvider.cs" />
|
<Compile Include="Services\TaskLease\AzureMachineNameProvider.cs" />
|
||||||
<Content Include="Web.config" />
|
<Content Include="Web.config" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
@@ -6,11 +6,11 @@ namespace Orchard.Azure.Services.Caching {
|
|||||||
|
|
||||||
public class CacheClientConfiguration {
|
public class CacheClientConfiguration {
|
||||||
|
|
||||||
public static CacheClientConfiguration FromPlatformConfiguration(string tenant, string settingNamePrefix, IPlatformConfigurationAccessor pca) {
|
public static CacheClientConfiguration FromPlatformConfiguration(string tenant, string settingNamePrefix) {
|
||||||
return new CacheClientConfiguration {
|
return new CacheClientConfiguration {
|
||||||
HostIdentifier = pca.GetSetting(Constants.CacheHostIdentifierSettingName, tenant, settingNamePrefix),
|
HostIdentifier = PlatformConfiguration.GetSetting(Constants.CacheHostIdentifierSettingName, tenant, settingNamePrefix),
|
||||||
CacheName = pca.GetSetting(Constants.CacheCacheNameSettingName, tenant, settingNamePrefix),
|
CacheName = PlatformConfiguration.GetSetting(Constants.CacheCacheNameSettingName, tenant, settingNamePrefix),
|
||||||
AuthorizationToken = pca.GetSetting(Constants.CacheAuthorizationTokenSettingName, tenant, settingNamePrefix),
|
AuthorizationToken = PlatformConfiguration.GetSetting(Constants.CacheAuthorizationTokenSettingName, tenant, settingNamePrefix),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
using Microsoft.ApplicationServer.Caching;
|
using Microsoft.ApplicationServer.Caching;
|
||||||
using NHibernate.Cache;
|
using NHibernate.Cache;
|
||||||
using Orchard.Azure.Services.Environment.Configuration;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
@@ -9,11 +8,6 @@ namespace Orchard.Azure.Services.Caching.Database {
|
|||||||
public class AzureCacheProvider : ICacheProvider {
|
public class AzureCacheProvider : ICacheProvider {
|
||||||
|
|
||||||
private DataCache _dataCache;
|
private DataCache _dataCache;
|
||||||
private readonly IPlatformConfigurationAccessor _pca;
|
|
||||||
|
|
||||||
public AzureCacheProvider(IPlatformConfigurationAccessor pca) {
|
|
||||||
_pca = pca;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ICache BuildCache(string regionName, IDictionary<string, string> properties) {
|
public ICache BuildCache(string regionName, IDictionary<string, string> properties) {
|
||||||
|
|
||||||
@@ -45,7 +39,7 @@ namespace Orchard.Azure.Services.Caching.Database {
|
|||||||
if (properties.TryGetValue("compression_enabled", out enableCompressionString))
|
if (properties.TryGetValue("compression_enabled", out enableCompressionString))
|
||||||
enableCompression = Boolean.Parse(enableCompressionString);
|
enableCompression = Boolean.Parse(enableCompressionString);
|
||||||
|
|
||||||
configuration = CacheClientConfiguration.FromPlatformConfiguration(tenantName, Constants.DatabaseCacheSettingNamePrefix, _pca);
|
configuration = CacheClientConfiguration.FromPlatformConfiguration(tenantName, Constants.DatabaseCacheSettingNamePrefix);
|
||||||
configuration.CompressionIsEnabled = enableCompression;
|
configuration.CompressionIsEnabled = enableCompression;
|
||||||
configuration.Validate();
|
configuration.Validate();
|
||||||
}
|
}
|
||||||
|
@@ -18,7 +18,7 @@ namespace Orchard.Azure.Services.Caching.Output {
|
|||||||
private readonly DataCache _cache;
|
private readonly DataCache _cache;
|
||||||
private readonly string _regionAlphaNumeric;
|
private readonly string _regionAlphaNumeric;
|
||||||
|
|
||||||
public AzureOutputCacheStorageProvider(ShellSettings shellSettings, IAzureOutputCacheHolder cacheHolder, IPlatformConfigurationAccessor pca) {
|
public AzureOutputCacheStorageProvider(ShellSettings shellSettings, IAzureOutputCacheHolder cacheHolder) {
|
||||||
|
|
||||||
var region = shellSettings.Name;
|
var region = shellSettings.Name;
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ namespace Orchard.Azure.Services.Caching.Output {
|
|||||||
CacheClientConfiguration cacheConfig;
|
CacheClientConfiguration cacheConfig;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cacheConfig = CacheClientConfiguration.FromPlatformConfiguration(shellSettings.Name, Constants.OutputCacheSettingNamePrefix, pca);
|
cacheConfig = CacheClientConfiguration.FromPlatformConfiguration(shellSettings.Name, Constants.OutputCacheSettingNamePrefix);
|
||||||
cacheConfig.Validate();
|
cacheConfig.Validate();
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
|
@@ -6,24 +6,15 @@ namespace Orchard.Azure.Services.Environment.Configuration {
|
|||||||
public class DefaultPlatformConfigurationAccessor : IPlatformConfigurationAccessor {
|
public class DefaultPlatformConfigurationAccessor : IPlatformConfigurationAccessor {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Trying to read a setting from the following sources in the following order (with and then without tenant name prefix):
|
/// Trying to read a setting using the default implementation.
|
||||||
/// CloudConfigurationManager, ConnectionStrings, AppSettings.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name of the setting to read.</param>
|
/// <param name="name">The name of the setting to read.</param>
|
||||||
/// <param name="tenant">The current tenant's name.</param>
|
/// <param name="tenant">The current tenant's name.</param>
|
||||||
/// <param name="namePrefix">An optional prefix to prepend the setting name with.</param>
|
/// <param name="namePrefix">An optional prefix to prepend the setting name with.</param>
|
||||||
/// <returns>The value of the setting if found in any of the available sources, otherwise null.</returns>
|
/// <returns>The value of the setting if found in any of the available sources, otherwise null.</returns>
|
||||||
|
/// <see cref="PlatformConfiguration" />
|
||||||
public string GetSetting(string name, string tenant, string namePrefix = null) {
|
public string GetSetting(string name, string tenant, string namePrefix = null) {
|
||||||
var tenantName = tenant + ":" + (namePrefix ?? string.Empty) + name;
|
return PlatformConfiguration.GetSetting(name, tenant, namePrefix);
|
||||||
var fallbackName = (namePrefix ?? string.Empty) + name;
|
|
||||||
|
|
||||||
var settingFromCloudConfiguration = CloudConfigurationManager.GetSetting(tenantName) ?? CloudConfigurationManager.GetSetting(fallbackName);
|
|
||||||
if (!string.IsNullOrEmpty(settingFromCloudConfiguration)) return settingFromCloudConfiguration;
|
|
||||||
|
|
||||||
var settingFromConnectionStrings = ConfigurationManager.ConnectionStrings[tenantName] ?? ConfigurationManager.ConnectionStrings[fallbackName];
|
|
||||||
if (settingFromConnectionStrings != null) return settingFromConnectionStrings.ConnectionString;
|
|
||||||
|
|
||||||
return ConfigurationManager.AppSettings[tenantName] ?? ConfigurationManager.AppSettings[fallbackName];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads a setting using the available implementation(s).
|
/// Reads a setting using the available implementation(s).
|
||||||
|
/// Implementations other than DefaultPlatformConfigurationAccessor do not have any effect on the behavior of caching services.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name of the setting to read.</param>
|
/// <param name="name">The name of the setting to read.</param>
|
||||||
/// <param name="tenant">The current tenant's name.</param>
|
/// <param name="tenant">The current tenant's name.</param>
|
||||||
|
@@ -0,0 +1,29 @@
|
|||||||
|
using Microsoft.WindowsAzure;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
|
namespace Orchard.Azure.Services.Environment.Configuration {
|
||||||
|
|
||||||
|
public static class PlatformConfiguration {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Trying to read a setting from the following sources in the following order (with and then without tenant name prefix):
|
||||||
|
/// CloudConfigurationManager, ConnectionStrings, AppSettings.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name of the setting to read.</param>
|
||||||
|
/// <param name="tenant">The current tenant's name.</param>
|
||||||
|
/// <param name="namePrefix">An optional prefix to prepend the setting name with.</param>
|
||||||
|
/// <returns>The value of the setting if found in any of the available sources, otherwise null.</returns>
|
||||||
|
public static string GetSetting(string name, string tenant, string namePrefix = null) {
|
||||||
|
var tenantName = tenant + ":" + (namePrefix ?? string.Empty) + name;
|
||||||
|
var fallbackName = (namePrefix ?? string.Empty) + name;
|
||||||
|
|
||||||
|
var settingFromCloudConfiguration = CloudConfigurationManager.GetSetting(tenantName) ?? CloudConfigurationManager.GetSetting(fallbackName);
|
||||||
|
if (!string.IsNullOrEmpty(settingFromCloudConfiguration)) return settingFromCloudConfiguration;
|
||||||
|
|
||||||
|
var settingFromConnectionStrings = ConfigurationManager.ConnectionStrings[tenantName] ?? ConfigurationManager.ConnectionStrings[fallbackName];
|
||||||
|
if (settingFromConnectionStrings != null) return settingFromConnectionStrings.ConnectionString;
|
||||||
|
|
||||||
|
return ConfigurationManager.AppSettings[tenantName] ?? ConfigurationManager.AppSettings[fallbackName];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user