From 4f4f1c870b8942d1632802e32fb1bb7e921b3506 Mon Sep 17 00:00:00 2001 From: Lombiq Date: Tue, 25 Mar 2014 21:25:46 +0100 Subject: [PATCH] Partially reverting the changes made related to #20337 to fix the errors caused by the limitations by NHibernate. --- .../Orchard.Azure/Orchard.Azure.csproj | 1 + .../Caching/CacheClientConfiguration.cs | 8 ++--- .../Caching/Database/AzureCacheProvider.cs | 8 +---- .../Output/AzureOutputCacheStorageProvider.cs | 4 +-- .../DefaultPlatformConfigurationAccessor.cs | 15 ++-------- .../IPlatformConfigurationAccessor.cs | 1 + .../Configuration/PlatformConfiguration.cs | 29 +++++++++++++++++++ 7 files changed, 41 insertions(+), 25 deletions(-) create mode 100644 src/Orchard.Web/Modules/Orchard.Azure/Services/Environment/Configuration/PlatformConfiguration.cs diff --git a/src/Orchard.Web/Modules/Orchard.Azure/Orchard.Azure.csproj b/src/Orchard.Web/Modules/Orchard.Azure/Orchard.Azure.csproj index a37eca615..e562191ea 100644 --- a/src/Orchard.Web/Modules/Orchard.Azure/Orchard.Azure.csproj +++ b/src/Orchard.Web/Modules/Orchard.Azure/Orchard.Azure.csproj @@ -103,6 +103,7 @@ + diff --git a/src/Orchard.Web/Modules/Orchard.Azure/Services/Caching/CacheClientConfiguration.cs b/src/Orchard.Web/Modules/Orchard.Azure/Services/Caching/CacheClientConfiguration.cs index 59aa1b1c8..89711d7f2 100644 --- a/src/Orchard.Web/Modules/Orchard.Azure/Services/Caching/CacheClientConfiguration.cs +++ b/src/Orchard.Web/Modules/Orchard.Azure/Services/Caching/CacheClientConfiguration.cs @@ -6,11 +6,11 @@ namespace Orchard.Azure.Services.Caching { public class CacheClientConfiguration { - public static CacheClientConfiguration FromPlatformConfiguration(string tenant, string settingNamePrefix, IPlatformConfigurationAccessor pca) { + public static CacheClientConfiguration FromPlatformConfiguration(string tenant, string settingNamePrefix) { return new CacheClientConfiguration { - HostIdentifier = pca.GetSetting(Constants.CacheHostIdentifierSettingName, tenant, settingNamePrefix), - CacheName = pca.GetSetting(Constants.CacheCacheNameSettingName, tenant, settingNamePrefix), - AuthorizationToken = pca.GetSetting(Constants.CacheAuthorizationTokenSettingName, tenant, settingNamePrefix), + HostIdentifier = PlatformConfiguration.GetSetting(Constants.CacheHostIdentifierSettingName, tenant, settingNamePrefix), + CacheName = PlatformConfiguration.GetSetting(Constants.CacheCacheNameSettingName, tenant, settingNamePrefix), + AuthorizationToken = PlatformConfiguration.GetSetting(Constants.CacheAuthorizationTokenSettingName, tenant, settingNamePrefix), }; } diff --git a/src/Orchard.Web/Modules/Orchard.Azure/Services/Caching/Database/AzureCacheProvider.cs b/src/Orchard.Web/Modules/Orchard.Azure/Services/Caching/Database/AzureCacheProvider.cs index 2b37587d3..ecfe6084d 100644 --- a/src/Orchard.Web/Modules/Orchard.Azure/Services/Caching/Database/AzureCacheProvider.cs +++ b/src/Orchard.Web/Modules/Orchard.Azure/Services/Caching/Database/AzureCacheProvider.cs @@ -1,6 +1,5 @@ using Microsoft.ApplicationServer.Caching; using NHibernate.Cache; -using Orchard.Azure.Services.Environment.Configuration; using System; using System.Collections.Generic; @@ -9,11 +8,6 @@ namespace Orchard.Azure.Services.Caching.Database { public class AzureCacheProvider : ICacheProvider { private DataCache _dataCache; - private readonly IPlatformConfigurationAccessor _pca; - - public AzureCacheProvider(IPlatformConfigurationAccessor pca) { - _pca = pca; - } public ICache BuildCache(string regionName, IDictionary properties) { @@ -45,7 +39,7 @@ namespace Orchard.Azure.Services.Caching.Database { if (properties.TryGetValue("compression_enabled", out enableCompressionString)) enableCompression = Boolean.Parse(enableCompressionString); - configuration = CacheClientConfiguration.FromPlatformConfiguration(tenantName, Constants.DatabaseCacheSettingNamePrefix, _pca); + configuration = CacheClientConfiguration.FromPlatformConfiguration(tenantName, Constants.DatabaseCacheSettingNamePrefix); configuration.CompressionIsEnabled = enableCompression; configuration.Validate(); } diff --git a/src/Orchard.Web/Modules/Orchard.Azure/Services/Caching/Output/AzureOutputCacheStorageProvider.cs b/src/Orchard.Web/Modules/Orchard.Azure/Services/Caching/Output/AzureOutputCacheStorageProvider.cs index c1414b8a0..66629ae2a 100644 --- a/src/Orchard.Web/Modules/Orchard.Azure/Services/Caching/Output/AzureOutputCacheStorageProvider.cs +++ b/src/Orchard.Web/Modules/Orchard.Azure/Services/Caching/Output/AzureOutputCacheStorageProvider.cs @@ -18,7 +18,7 @@ namespace Orchard.Azure.Services.Caching.Output { private readonly DataCache _cache; private readonly string _regionAlphaNumeric; - public AzureOutputCacheStorageProvider(ShellSettings shellSettings, IAzureOutputCacheHolder cacheHolder, IPlatformConfigurationAccessor pca) { + public AzureOutputCacheStorageProvider(ShellSettings shellSettings, IAzureOutputCacheHolder cacheHolder) { var region = shellSettings.Name; @@ -33,7 +33,7 @@ namespace Orchard.Azure.Services.Caching.Output { CacheClientConfiguration cacheConfig; try { - cacheConfig = CacheClientConfiguration.FromPlatformConfiguration(shellSettings.Name, Constants.OutputCacheSettingNamePrefix, pca); + cacheConfig = CacheClientConfiguration.FromPlatformConfiguration(shellSettings.Name, Constants.OutputCacheSettingNamePrefix); cacheConfig.Validate(); } catch (Exception ex) { diff --git a/src/Orchard.Web/Modules/Orchard.Azure/Services/Environment/Configuration/DefaultPlatformConfigurationAccessor.cs b/src/Orchard.Web/Modules/Orchard.Azure/Services/Environment/Configuration/DefaultPlatformConfigurationAccessor.cs index cbe688827..cdfa41a52 100644 --- a/src/Orchard.Web/Modules/Orchard.Azure/Services/Environment/Configuration/DefaultPlatformConfigurationAccessor.cs +++ b/src/Orchard.Web/Modules/Orchard.Azure/Services/Environment/Configuration/DefaultPlatformConfigurationAccessor.cs @@ -6,24 +6,15 @@ namespace Orchard.Azure.Services.Environment.Configuration { public class DefaultPlatformConfigurationAccessor : IPlatformConfigurationAccessor { /// - /// Trying to read a setting from the following sources in the following order (with and then without tenant name prefix): - /// CloudConfigurationManager, ConnectionStrings, AppSettings. + /// Trying to read a setting using the default implementation. /// /// The name of the setting to read. /// The current tenant's name. /// An optional prefix to prepend the setting name with. /// The value of the setting if found in any of the available sources, otherwise null. + /// public 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]; + return PlatformConfiguration.GetSetting(name, tenant, namePrefix); } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Azure/Services/Environment/Configuration/IPlatformConfigurationAccessor.cs b/src/Orchard.Web/Modules/Orchard.Azure/Services/Environment/Configuration/IPlatformConfigurationAccessor.cs index 4149f7d80..1b32d7589 100644 --- a/src/Orchard.Web/Modules/Orchard.Azure/Services/Environment/Configuration/IPlatformConfigurationAccessor.cs +++ b/src/Orchard.Web/Modules/Orchard.Azure/Services/Environment/Configuration/IPlatformConfigurationAccessor.cs @@ -4,6 +4,7 @@ /// /// Reads a setting using the available implementation(s). + /// Implementations other than DefaultPlatformConfigurationAccessor do not have any effect on the behavior of caching services. /// /// The name of the setting to read. /// The current tenant's name. diff --git a/src/Orchard.Web/Modules/Orchard.Azure/Services/Environment/Configuration/PlatformConfiguration.cs b/src/Orchard.Web/Modules/Orchard.Azure/Services/Environment/Configuration/PlatformConfiguration.cs new file mode 100644 index 000000000..b52773685 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Azure/Services/Environment/Configuration/PlatformConfiguration.cs @@ -0,0 +1,29 @@ +using Microsoft.WindowsAzure; +using System.Configuration; + +namespace Orchard.Azure.Services.Environment.Configuration { + + public static class PlatformConfiguration { + + /// + /// Trying to read a setting from the following sources in the following order (with and then without tenant name prefix): + /// CloudConfigurationManager, ConnectionStrings, AppSettings. + /// + /// The name of the setting to read. + /// The current tenant's name. + /// An optional prefix to prepend the setting name with. + /// The value of the setting if found in any of the available sources, otherwise null. + 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]; + } + } +} \ No newline at end of file