Fixing Azure features

This commit is contained in:
Sebastien Ros 2013-09-06 13:44:27 -07:00
parent df2f4f6f70
commit d1d51e6f92
5 changed files with 50 additions and 61 deletions

View File

@ -53,10 +53,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\windowsazure\Microsoft.ApplicationServer.Caching.AzureClientHelper.dll</HintPath>
</Reference>
<Reference Include="Microsoft.ApplicationServer.Caching.AzureCommon, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\windowsazure\Microsoft.ApplicationServer.Caching.AzureCommon.dll</HintPath>
</Reference>
<Reference Include="Microsoft.ApplicationServer.Caching.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\windowsazure\Microsoft.ApplicationServer.Caching.Client.dll</HintPath>
@ -65,47 +61,18 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\windowsazure\Microsoft.ApplicationServer.Caching.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Data.Edm, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\windowsazure\Microsoft.Data.Edm.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Data.OData, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\windowsazure\Microsoft.Data.OData.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.DistributedCache, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\windowsazure\Microsoft.Web.DistributedCache.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\windowsazure\Microsoft.WindowsAzure.Configuration.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Diagnostics, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\windowsazure\Microsoft.WindowsAzure.Diagnostics.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Diagnostics.StorageUtility, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\windowsazure\Microsoft.WindowsAzure.Diagnostics.StorageUtility.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.ServiceRuntime, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\windowsazure\Microsoft.WindowsAzure.ServiceRuntime.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Storage, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\windowsazure\Microsoft.WindowsAzure.Storage.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsFabric.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\windowsazure\Microsoft.WindowsFabric.Common.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsFabric.Data.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\windowsazure\Microsoft.WindowsFabric.Data.Common.dll</HintPath>
</Reference>
<Reference Include="NHibernate, Version=3.3.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\nhibernate\NHibernate.dll</HintPath>
@ -115,7 +82,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\aspnetmvc\System.Web.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Configuration" />
</ItemGroup>
<ItemGroup>
<Content Include="Web.config" />
@ -140,6 +106,7 @@
<Compile Include="Services\Caching\Database\AzureCacheProvider.cs" />
<Compile Include="Services\Caching\Database\Models\AzureCacheRecord.cs" />
<Compile Include="Services\Caching\Output\AzureOutputCacheStorageProvider.cs" />
<Compile Include="Services\Caching\Output\IAzureOutputCacheHolder.cs" />
<Compile Include="Services\Environment\Configuration\AzureBlobShellSettingsManager.cs" />
<Compile Include="Services\Environment\Configuration\PlatformConfiguration.cs" />
<Compile Include="Services\FileSystems\AzureFileSystem.cs" />

View File

@ -14,32 +14,37 @@ namespace Orchard.Azure.Services.Caching.Output {
[OrchardFeature(Constants.OutputCacheFeatureName)]
[OrchardSuppressDependency("Orchard.OutputCache.Services.DefaultCacheStorageProvider")]
public class AzureOutputCacheStorageProvider : Component, IOutputCacheStorageProvider {
private readonly DataCache _cache;
private readonly string _regionAlphaNumeric;
public AzureOutputCacheStorageProvider(ShellSettings shellSettings) {
public AzureOutputCacheStorageProvider(ShellSettings shellSettings, IAzureOutputCacheHolder cacheHolder) {
try {
_cacheConfig = CacheClientConfiguration.FromPlatformConfiguration(shellSettings.Name, Constants.OutputCacheSettingNamePrefix);
_cacheConfig.Validate();
}
catch (Exception ex) {
throw new Exception(String.Format("The {0} configuration settings are missing or invalid.", Constants.OutputCacheFeatureName), ex);
}
_cache = _cacheConfig.CreateCache();
_region = shellSettings.Name;
var region = shellSettings.Name;
// Azure Cache supports only alphanumeric strings for regions, but Orchard supports some
// non-alphanumeric characters in tenant names. Remove all non-alphanumering characters
// from the region, and append the hash code of the original string to mitigate the risk
// of two distinct original region strings yielding the same transformed region string.
_regionAlphaNumeric = new String(Array.FindAll(_region.ToCharArray(), Char.IsLetterOrDigit)) + _region.GetHashCode().ToString(CultureInfo.InvariantCulture);
_cache.CreateRegion(_regionAlphaNumeric);
}
_regionAlphaNumeric = new String(Array.FindAll(region.ToCharArray(), Char.IsLetterOrDigit)) + region.GetHashCode().ToString(CultureInfo.InvariantCulture);
private readonly CacheClientConfiguration _cacheConfig;
private readonly DataCache _cache;
private readonly string _region;
private readonly string _regionAlphaNumeric;
_cache = cacheHolder.TryGetDataCache(() => {
CacheClientConfiguration cacheConfig;
try {
cacheConfig = CacheClientConfiguration.FromPlatformConfiguration(shellSettings.Name, Constants.OutputCacheSettingNamePrefix);
cacheConfig.Validate();
}
catch (Exception ex) {
throw new Exception(String.Format("The {0} configuration settings are missing or invalid.", Constants.OutputCacheFeatureName), ex);
}
var cache = cacheConfig.CreateCache();
cache.CreateRegion(_regionAlphaNumeric);
return cache;
});
}
public void Set(string key, CacheItem cacheItem) {
Logger.Debug("Set() invoked with key='{0}' in region '{1}'.", key, _regionAlphaNumeric);

View File

@ -0,0 +1,23 @@
using System;
using Microsoft.ApplicationServer.Caching;
namespace Orchard.Azure.Services.Caching.Output {
public interface IAzureOutputCacheHolder : ISingletonDependency {
DataCache TryGetDataCache(Func<DataCache> builder);
}
public class AzureOutputCacheHolder : IAzureOutputCacheHolder {
private readonly object _synLock = new object();
private DataCache _dataCache;
public DataCache TryGetDataCache(Func<DataCache> builder) {
lock (_synLock) {
if (_dataCache != null) {
return _dataCache;
}
return _dataCache = builder();
}
}
}
}

View File

@ -13,8 +13,8 @@ namespace Orchard.Azure.Services.Environment.Configuration {
/// <param name="namePrefix">An optional prefix to prepend the setting name with.</param>
/// <returns>The value of the setting if found with or without tenant name prefix, otherwise null.</returns>
public static string GetSetting(string name, string tenant, string namePrefix = null) {
var tenantName = tenant + ":" + namePrefix + name;
var fallbackName = namePrefix + name;
var tenantName = tenant + ":" + (namePrefix ?? string.Empty) + name;
var fallbackName = (namePrefix ?? string.Empty) + name;
return CloudConfigurationManager.GetSetting(tenantName) ?? CloudConfigurationManager.GetSetting(fallbackName);
}
}

View File

@ -109,13 +109,7 @@ namespace Orchard.Azure.Services.FileSystems {
return path2;
}
var ch = path1[path1.Length - 1];
if (ch != '/') {
return (path1.TrimEnd('/') + '/' + path2.TrimStart('/'));
}
return (path1 + path2);
return (path1.TrimEnd('/') + '/' + path2.TrimStart('/'));
}
public IStorageFile GetFile(string path) {