mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-07-31 21:15:28 +08:00
Enabled caching by default in Orchard.Azure.Web cloud service role.
Enabled session state cache provider by default in Orchard.Azure.Wew. Moved all string constants into Constants class. Got rid of unused implicit module feature of Orchard.Azure. Added missing settings banner. Split Orchard.StorageConnectionString role configuration setting up into two separate settings for Media and Settings respectively. Renamed startup task. Removed hard coded connection string and container name from AzureFileSystem, making it truly reusable.
This commit is contained in:
parent
5872371189
commit
ca34a462b6
@ -52,7 +52,7 @@
|
||||
<Folder Include="Profiles" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Orchard.Azure.WebContent\Bin\Startup\ConfigureIIS.cmd">
|
||||
<Content Include="Orchard.Azure.WebContent\Bin\Startup\SetIdleTimeout.cmd">
|
||||
<SubType>Content</SubType>
|
||||
</Content>
|
||||
<Content Include="Orchard.Azure.WebContent\diagnostics.wadcfg">
|
||||
|
@ -1,5 +0,0 @@
|
||||
REM Check if this task is running on the compute emulator, if not then sets the Idle Timeout to zero
|
||||
|
||||
IF "%ComputeEmulatorRunning%" == "false" (
|
||||
%windir%\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.processModel.idleTimeout:00:00:00
|
||||
)
|
@ -3,8 +3,13 @@
|
||||
<Role name="Orchard.Azure.Web">
|
||||
<Instances count="1" />
|
||||
<ConfigurationSettings>
|
||||
<Setting name="Orchard.StorageConnectionString" value="UseDevelopmentStorage=true" />
|
||||
<Setting name="Orchard.Media.StorageConnectionString" value="UseDevelopmentStorage=true" />
|
||||
<Setting name="Orchard.Settings.StorageConnectionString" value="UseDevelopmentStorage=true" />
|
||||
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
|
||||
<Setting name="Microsoft.WindowsAzure.Plugins.Caching.NamedCaches" value="{"caches":[{"name":"default","policy":{"eviction":{"type":0},"expiration":{"defaultTTL":10,"isExpirable":true,"type":1},"serverNotification":{"isEnabled":false}},"secondaries":0},{"name":"SessionStateCache","policy":{"eviction":{"type":0},"expiration":{"defaultTTL":10,"isExpirable":true,"type":1},"serverNotification":{"isEnabled":false}},"secondaries":0},{"name":"OutputCache","policy":{"eviction":{"type":0},"expiration":{"defaultTTL":10,"isExpirable":true,"type":1},"serverNotification":{"isEnabled":false}},"secondaries":0},{"name":"DatabaseCache","policy":{"eviction":{"type":0},"expiration":{"defaultTTL":10,"isExpirable":true,"type":1},"serverNotification":{"isEnabled":false}},"secondaries":0}]}" />
|
||||
<Setting name="Microsoft.WindowsAzure.Plugins.Caching.DiagnosticLevel" value="1" />
|
||||
<Setting name="Microsoft.WindowsAzure.Plugins.Caching.CacheSizePercentage" value="30" />
|
||||
<Setting name="Microsoft.WindowsAzure.Plugins.Caching.ConfigStoreConnectionString" value="UseDevelopmentStorage=true" />
|
||||
</ConfigurationSettings>
|
||||
</Role>
|
||||
</ServiceConfiguration>
|
@ -10,25 +10,28 @@
|
||||
</Sites>
|
||||
<Imports>
|
||||
<Import moduleName="Diagnostics" />
|
||||
<Import moduleName="Caching" />
|
||||
</Imports>
|
||||
<ConfigurationSettings>
|
||||
<Setting name="Orchard.StorageConnectionString" />
|
||||
<Setting name="Orchard.Settings.StorageConnectionString" />
|
||||
<Setting name="Orchard.Media.StorageConnectionString" />
|
||||
</ConfigurationSettings>
|
||||
<Endpoints>
|
||||
<InputEndpoint name="HttpIn" protocol="http" port="80" />
|
||||
</Endpoints>
|
||||
<Startup>
|
||||
<Task commandLine="Startup\ConfigureIIS.cmd" executionContext="elevated" taskType="simple">
|
||||
<Task commandLine="Startup\SetIdleTimeout.cmd" executionContext="elevated" taskType="simple">
|
||||
<Environment>
|
||||
<!-- Create the environment variable that informs the startup task whether it is running
|
||||
in the Compute Emulator or in the cloud. "%ComputeEmulatorRunning%"=="true" when
|
||||
running in the Compute Emulator, "%ComputeEmulatorRunning%"=="false" when running
|
||||
in the cloud. -->
|
||||
in the compute emulator or in the cloud. -->
|
||||
<Variable name="ComputeEmulatorRunning">
|
||||
<RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
|
||||
</Variable>
|
||||
</Environment>
|
||||
</Task>
|
||||
</Startup>
|
||||
<LocalResources>
|
||||
<LocalStorage name="DiagnosticStore" sizeInMB="20000" cleanOnRoleRecycle="false" />
|
||||
</LocalResources>
|
||||
</WebRole>
|
||||
</ServiceDefinition>
|
@ -36,11 +36,11 @@
|
||||
To use the in-role flavor of Windows Azure Caching, set {CacheHostIdentifier} to be the cache cluster role name.
|
||||
To use the Windows Azure Caching Service, set {CacheHostIdentifier} to be the endpoint of the cache cluster.
|
||||
-->
|
||||
<!--<dataCacheClients>
|
||||
<dataCacheClients>
|
||||
<dataCacheClient name="DefaultCacheClient" useLegacyProtocol="false" connectionPool="true" maxConnectionsToServer="20">
|
||||
<autoDiscover isEnabled="true" identifier="{CacheHostIdentifier}" />
|
||||
</dataCacheClient>
|
||||
</dataCacheClients>-->
|
||||
</dataCacheClients>
|
||||
|
||||
<system.diagnostics>
|
||||
<trace>
|
||||
@ -102,11 +102,11 @@
|
||||
</authentication>
|
||||
|
||||
<!-- Uncomment below to store session state in Windows Azure Cache (replace {CacheName} with name of your configured cache). -->
|
||||
<!--<sessionState mode="Custom" timeout="60" customProvider="CacheSessionStateProvider">
|
||||
<sessionState mode="Custom" timeout="60" customProvider="CacheSessionStateProvider">
|
||||
<providers>
|
||||
<add name="CacheSessionStateProvider" type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache" cacheName="{CacheName}" dataCacheClientName="DefaultCacheClient" applicationName="Orchard" />
|
||||
</providers>
|
||||
</sessionState>-->
|
||||
</sessionState>
|
||||
|
||||
<customErrors mode="RemoteOnly" />
|
||||
|
||||
|
27
src/Orchard.Web/Modules/Orchard.Azure/Constants.cs
Normal file
27
src/Orchard.Web/Modules/Orchard.Azure/Constants.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace Orchard.Azure {
|
||||
|
||||
public class Constants {
|
||||
public const string ShellSettingsStorageConnectionStringSettingName = "Orchard.Settings.StorageConnectionString";
|
||||
public const string ShellSettingsContainerName = "sites"; // Container names must be lower case.
|
||||
public const string ShellSettingsFileName = "Settings.txt";
|
||||
|
||||
public const string MediaStorageFeatureName = "Orchard.Azure";
|
||||
public const string MediaStorageStorageConnectionStringSettingName = "Orchard.Media.StorageConnectionString";
|
||||
public const string MediaStorageContainerName = "media"; // Container names must be lower case.
|
||||
|
||||
public const string OutputCacheFeatureName = "Orchard.Azure.OutputCache";
|
||||
public const string OutputCacheHostIdentifierSettingName = "Azure.OutputCache.HostIdentifier";
|
||||
public const string OutputCacheCacheNameSettingName = "Azure.OutputCache.CacheName";
|
||||
public const string OutputCacheIsSharedCachingSettingName = "Azure.OutputCache.IsSharedCaching";
|
||||
|
||||
public const string DatabaseCacheFeatureName = "Orchard.Azure.DatabaseCache";
|
||||
public const string DatabaseCacheHostIdentifierSettingName = "Azure.DatabaseCache.HostIdentifier";
|
||||
public const string DatabaseCacheCacheNameSettingName = "Azure.DatabaseCache.CacheName";
|
||||
public const string DatabaseCacheIsSharedCachingSettingName = "Azure.DatabaseCache.IsSharedCaching";
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
Name: Orchard.Azure
|
||||
Name: Azure
|
||||
AntiForgery: enabled
|
||||
Author: The Orchard Team
|
||||
Website: http://orchardproject.net
|
||||
@ -6,6 +6,10 @@ Version: 1.0
|
||||
OrchardVersion: 1.7
|
||||
Description: Provides a set of Orchard service implementations targeting Windows Azure services.
|
||||
Features:
|
||||
Orchard.Azure:
|
||||
Name: Windows Azure Media Storage
|
||||
Description: Activates an Orchard media storage provider that targets Windows Azure Blob Storage.
|
||||
Category: Hosting
|
||||
Orchard.Azure.OutputCache:
|
||||
Name: Windows Azure Output Cache
|
||||
Description: Activates an Orchard output cache provider that targets Windows Azure Cache.
|
||||
@ -15,7 +19,3 @@ Features:
|
||||
Name: Windows Azure Database Cache
|
||||
Description: Activates an NHibernate second-level cache provider that targets Windows Azure Cache.
|
||||
Category: Performance
|
||||
Orchard.Azure.MediaStorage:
|
||||
Name: Windows Azure Media Storage
|
||||
Description: Activates an Orchard media storage provider that targets Windows Azure Blob Storage.
|
||||
Category: Hosting
|
@ -102,6 +102,7 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Constants.cs" />
|
||||
<Compile Include="Services\Caching\Database\AzureCacheClient.cs" />
|
||||
<Compile Include="Services\Caching\Database\AzureCacheConfiguration.cs" />
|
||||
<Compile Include="Services\Caching\Database\AzureCacheProvider.cs" />
|
||||
@ -112,6 +113,7 @@
|
||||
<Compile Include="Services\FileSystems\CloudBlobContainerExtensions.cs" />
|
||||
<Compile Include="Services\FileSystems\Media\AzureBlobStorageProvider.cs" />
|
||||
<Compile Include="Services\Logging\AzureDiagnosticsAppender.cs" />
|
||||
<Compile Include="Services\MissingSettingsBanner.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<PropertyGroup>
|
||||
|
@ -7,7 +7,7 @@ using Orchard.Logging;
|
||||
|
||||
namespace Orchard.Azure.Services.Caching.Database {
|
||||
|
||||
[OrchardFeature("Orchard.Azure.DatabaseCache")]
|
||||
[OrchardFeature(Constants.DatabaseCacheFeatureName)]
|
||||
[OrchardSuppressDependency("Orchard.Data.DefaultDatabaseCacheConfiguration")]
|
||||
public class AzureCacheConfiguration : Component, IDatabaseCacheConfiguration {
|
||||
|
||||
@ -18,8 +18,8 @@ namespace Orchard.Azure.Services.Caching.Database {
|
||||
: base() {
|
||||
_shellSettings = shellSettings;
|
||||
|
||||
CacheHostIdentifier = shellSettings["Azure.DatabaseCache.HostIdentifier"];
|
||||
CacheName = shellSettings["Azure.DatabaseCache.CacheName"];
|
||||
CacheHostIdentifier = shellSettings[Constants.DatabaseCacheHostIdentifierSettingName];
|
||||
CacheName = shellSettings[Constants.DatabaseCacheCacheNameSettingName];
|
||||
}
|
||||
|
||||
private readonly ShellSettings _shellSettings;
|
||||
|
@ -10,15 +10,15 @@ using System.Web;
|
||||
|
||||
namespace Orchard.Azure.Services.Caching.Output {
|
||||
|
||||
[OrchardFeature("Orchard.Azure.OutputCache")]
|
||||
[OrchardFeature(Constants.OutputCacheFeatureName)]
|
||||
[OrchardSuppressDependency("Orchard.OutputCache.Services.DefaultCacheStorageProvider")]
|
||||
public class AzureOutputCacheStorageProvider : Component, IOutputCacheStorageProvider {
|
||||
|
||||
public AzureOutputCacheStorageProvider(ShellSettings shellSettings)
|
||||
: base() {
|
||||
|
||||
var cacheHostIdentifier = shellSettings["Azure.OutputCache.HostIdentifier"];
|
||||
var cacheName = shellSettings["Azure.OutputCache.CacheName"];
|
||||
var cacheHostIdentifier = shellSettings[Constants.OutputCacheHostIdentifierSettingName];
|
||||
var cacheName = shellSettings[Constants.OutputCacheCacheNameSettingName];
|
||||
|
||||
var dataCacheFactoryConfiguration = new DataCacheFactoryConfiguration() {
|
||||
AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(true, cacheHostIdentifier),
|
||||
@ -33,7 +33,7 @@ namespace Orchard.Azure.Services.Caching.Output {
|
||||
else
|
||||
_cache = dataCacheFactory.GetDefaultCache();
|
||||
|
||||
_usingSharedCaching = Boolean.Parse(shellSettings["Azure.OutputCache.IsSharedCaching"]);
|
||||
_usingSharedCaching = Boolean.Parse(shellSettings[Constants.OutputCacheIsSharedCachingSettingName]);
|
||||
|
||||
if (!_usingSharedCaching)
|
||||
{
|
||||
|
@ -12,22 +12,13 @@ namespace Orchard.Azure.Services.Environment.Configuration {
|
||||
|
||||
public class AzureBlobShellSettingsManager : Component, IShellSettingsManager {
|
||||
|
||||
public const string ConnectionStringSettingName = "Orchard.StorageConnectionString";
|
||||
public const string ContainerName = "sites"; // Container names must be lower cased.
|
||||
public const string SettingsFilename = "Settings.txt";
|
||||
public const char Separator = ':';
|
||||
public const string EmptyValue = "null";
|
||||
|
||||
protected const string EmptyValueString = "null";
|
||||
protected readonly IShellSettingsManagerEventHandler Events;
|
||||
protected readonly AzureFileSystem FileSystem;
|
||||
|
||||
public AzureBlobShellSettingsManager(IShellSettingsManagerEventHandler events, IMimeTypeProvider mimeTypeProvider)
|
||||
: this(CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting(ConnectionStringSettingName)), events, mimeTypeProvider) {
|
||||
}
|
||||
|
||||
public AzureBlobShellSettingsManager(CloudStorageAccount storageAccount, IShellSettingsManagerEventHandler events, IMimeTypeProvider mimeTypeProvider) {
|
||||
public AzureBlobShellSettingsManager(IShellSettingsManagerEventHandler events, IMimeTypeProvider mimeTypeProvider) {
|
||||
Events = events;
|
||||
FileSystem = new AzureFileSystem(ContainerName, String.Empty, true, mimeTypeProvider);
|
||||
FileSystem = new AzureFileSystem(CloudConfigurationManager.GetSetting(Constants.ShellSettingsStorageConnectionStringSettingName), Constants.ShellSettingsContainerName, String.Empty, true, mimeTypeProvider);
|
||||
}
|
||||
|
||||
public virtual IEnumerable<ShellSettings> LoadSettings() {
|
||||
@ -37,11 +28,8 @@ namespace Orchard.Azure.Services.Environment.Configuration {
|
||||
|
||||
public virtual void SaveSettings(ShellSettings settings) {
|
||||
var content = ShellSettingsSerializer.ComposeSettings(settings);
|
||||
var filePath = FileSystem.Combine(settings.Name, SettingsFilename);
|
||||
|
||||
var file = FileSystem.FileExists(filePath)
|
||||
? FileSystem.GetFile(filePath)
|
||||
: FileSystem.CreateFile(filePath);
|
||||
var filePath = FileSystem.Combine(settings.Name, Constants.ShellSettingsFileName);
|
||||
var file = FileSystem.FileExists(filePath) ? FileSystem.GetFile(filePath) : FileSystem.CreateFile(filePath);
|
||||
|
||||
using (var stream = file.OpenWrite()) {
|
||||
using (var writer = new StreamWriter(stream)) {
|
||||
@ -55,7 +43,7 @@ namespace Orchard.Azure.Services.Environment.Configuration {
|
||||
private IEnumerable<ShellSettings> LoadSettingsInternal() {
|
||||
foreach (var folder in FileSystem.ListFolders(null)) {
|
||||
foreach (var file in FileSystem.ListFiles(folder.GetPath())) {
|
||||
if (!String.Equals(file.GetName(), SettingsFilename))
|
||||
if (!String.Equals(file.GetName(), Constants.ShellSettingsFileName))
|
||||
continue;
|
||||
using (var stream = file.OpenRead()) {
|
||||
using (var reader = new StreamReader(stream))
|
||||
|
@ -48,11 +48,7 @@ namespace Orchard.Azure.Services.Environment.Configuration {
|
||||
private const string _prefix = "Orchard";
|
||||
|
||||
public AzureConfigShellSettingsManager(IShellSettingsManagerEventHandler events, IMimeTypeProvider mimeTypeProvider)
|
||||
: this(CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting(ConnectionStringSettingName)), events, mimeTypeProvider) {
|
||||
}
|
||||
|
||||
public AzureConfigShellSettingsManager(CloudStorageAccount storageAccount, IShellSettingsManagerEventHandler events, IMimeTypeProvider mimeTypeProvider)
|
||||
: base(storageAccount, events, mimeTypeProvider) {
|
||||
: base(events, mimeTypeProvider) {
|
||||
if (RoleEnvironment.IsAvailable) {
|
||||
RoleEnvironment.Changing += RoleEnvironment_Changing;
|
||||
RoleEnvironment.Changed += RoleEnvironment_Changed;
|
||||
@ -97,7 +93,7 @@ namespace Orchard.Azure.Services.Environment.Configuration {
|
||||
}
|
||||
|
||||
private string ParseValue(string value) {
|
||||
if (value == EmptyValue || String.IsNullOrWhiteSpace(value))
|
||||
if (value == EmptyValueString || String.IsNullOrWhiteSpace(value))
|
||||
return null;
|
||||
return value;
|
||||
}
|
||||
|
@ -23,6 +23,11 @@ namespace Orchard.Azure.Services.FileSystems {
|
||||
private CloudBlobClient _blobClient;
|
||||
private CloudBlobContainer _container;
|
||||
|
||||
public string StorageConnectionString {
|
||||
get;
|
||||
protected set;
|
||||
}
|
||||
|
||||
public string ContainerName {
|
||||
get;
|
||||
protected set;
|
||||
@ -42,9 +47,10 @@ namespace Orchard.Azure.Services.FileSystems {
|
||||
}
|
||||
}
|
||||
|
||||
public AzureFileSystem(string containerName, string root, bool isPrivate, IMimeTypeProvider mimeTypeProvider) {
|
||||
public AzureFileSystem(string storageConnectionString, string containerName, string root, bool isPrivate, IMimeTypeProvider mimeTypeProvider) {
|
||||
_isPrivate = isPrivate;
|
||||
_mimeTypeProvider = mimeTypeProvider;
|
||||
StorageConnectionString = storageConnectionString;
|
||||
ContainerName = containerName;
|
||||
_root = String.IsNullOrEmpty(root) ? "" : root + "/";
|
||||
}
|
||||
@ -54,7 +60,7 @@ namespace Orchard.Azure.Services.FileSystems {
|
||||
return;
|
||||
}
|
||||
|
||||
_storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("Orchard.StorageConnectionString"));
|
||||
_storageAccount = CloudStorageAccount.Parse(StorageConnectionString);
|
||||
_absoluteRoot = Combine(Combine(_storageAccount.BlobEndpoint.AbsoluteUri, ContainerName), _root);
|
||||
|
||||
_blobClient = _storageAccount.CreateCloudBlobClient();
|
||||
|
@ -2,14 +2,15 @@
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.FileSystems.Media;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Microsoft.WindowsAzure;
|
||||
|
||||
namespace Orchard.Azure.Services.FileSystems.Media {
|
||||
|
||||
[OrchardFeature("Orchard.Azure.MediaStorage")]
|
||||
[OrchardFeature(Constants.MediaStorageFeatureName)]
|
||||
[OrchardSuppressDependency("Orchard.FileSystems.Media.FileSystemStorageProvider")]
|
||||
public class AzureBlobStorageProvider : AzureFileSystem, IStorageProvider {
|
||||
|
||||
public AzureBlobStorageProvider(ShellSettings shellSettings, IMimeTypeProvider mimeTypeProvider) : base("media", shellSettings.Name, false, mimeTypeProvider)
|
||||
public AzureBlobStorageProvider(ShellSettings shellSettings, IMimeTypeProvider mimeTypeProvider) : base(CloudConfigurationManager.GetSetting(Constants.MediaStorageStorageConnectionStringSettingName), Constants.MediaStorageContainerName, shellSettings.Name, false, mimeTypeProvider)
|
||||
{ }
|
||||
|
||||
public bool TrySaveStream(string path, Stream inputStream) {
|
||||
|
@ -11,17 +11,17 @@ namespace Orchard.Azure.Services.Logging {
|
||||
/// </summary>
|
||||
public class AzureDiagnosticsAppender : AppenderSkeleton {
|
||||
|
||||
private const string _wadStorageAccountConnectionStringSettingName = "Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString";
|
||||
//private const string _wadStorageAccountConnectionStringSettingName = "Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString";
|
||||
|
||||
public AzureDiagnosticsAppender() {
|
||||
var defaultDiagnostics = DiagnosticMonitor.GetDefaultInitialConfiguration();
|
||||
var period = TimeSpan.FromMinutes(1d);
|
||||
//var defaultDiagnostics = DiagnosticMonitor.GetDefaultInitialConfiguration();
|
||||
//var period = TimeSpan.FromMinutes(1d);
|
||||
|
||||
defaultDiagnostics.Directories.ScheduledTransferPeriod = period;
|
||||
defaultDiagnostics.Logs.ScheduledTransferPeriod = period;
|
||||
defaultDiagnostics.WindowsEventLog.ScheduledTransferPeriod = period;
|
||||
//defaultDiagnostics.Directories.ScheduledTransferPeriod = period;
|
||||
//defaultDiagnostics.Logs.ScheduledTransferPeriod = period;
|
||||
//defaultDiagnostics.WindowsEventLog.ScheduledTransferPeriod = period;
|
||||
|
||||
DiagnosticMonitor.Start(_wadStorageAccountConnectionStringSettingName, defaultDiagnostics);
|
||||
//DiagnosticMonitor.Start(_wadStorageAccountConnectionStringSettingName, defaultDiagnostics);
|
||||
}
|
||||
|
||||
protected override void Append(LoggingEvent loggingEvent) {
|
||||
|
@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.Localization;
|
||||
using Orchard.UI.Admin.Notification;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Microsoft.WindowsAzure;
|
||||
using Microsoft.WindowsAzure.Storage;
|
||||
|
||||
namespace Orchard.Azure.Services {
|
||||
|
||||
public class MissingSettingsBanner : INotificationProvider {
|
||||
|
||||
public MissingSettingsBanner(IFeatureManager featureManager, ShellSettings shellSettings) {
|
||||
_featureManager = featureManager;
|
||||
_shellSettings = shellSettings;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
private IFeatureManager _featureManager;
|
||||
private ShellSettings _shellSettings;
|
||||
|
||||
public Localizer T {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public IEnumerable<NotifyEntry> GetNotifications() {
|
||||
var enabledFeatureNamesQuery =
|
||||
from feature in _featureManager.GetEnabledFeatures()
|
||||
select feature.Id;
|
||||
|
||||
if (enabledFeatureNamesQuery.Contains(Constants.MediaStorageFeatureName)) {
|
||||
CloudStorageAccount storageAccount = null;
|
||||
var storageConnectionString = CloudConfigurationManager.GetSetting(Constants.MediaStorageStorageConnectionStringSettingName);
|
||||
var isValid = CloudStorageAccount.TryParse(storageConnectionString, out storageAccount);
|
||||
if (!isValid)
|
||||
yield return new NotifyEntry {
|
||||
Message = T("A valid storage account connection string must be configured in the role configuration setting '{0}'.", Constants.MediaStorageStorageConnectionStringSettingName),
|
||||
Type = NotifyType.Warning
|
||||
};
|
||||
}
|
||||
|
||||
if (enabledFeatureNamesQuery.Contains(Constants.OutputCacheFeatureName)) {
|
||||
// Create default configuration to local role-based cache when feature is enabled.
|
||||
if (!_shellSettings.Keys.Contains(Constants.OutputCacheHostIdentifierSettingName))
|
||||
_shellSettings[Constants.OutputCacheHostIdentifierSettingName] = "Orchard.Azure.Web";
|
||||
if (!_shellSettings.Keys.Contains(Constants.OutputCacheCacheNameSettingName))
|
||||
_shellSettings[Constants.OutputCacheCacheNameSettingName] = "OutputCache";
|
||||
if (!_shellSettings.Keys.Contains(Constants.OutputCacheIsSharedCachingSettingName))
|
||||
_shellSettings[Constants.OutputCacheIsSharedCachingSettingName] = "false";
|
||||
|
||||
if (String.IsNullOrWhiteSpace(_shellSettings[Constants.OutputCacheHostIdentifierSettingName]))
|
||||
yield return new NotifyEntry {
|
||||
Message = T("A cache cluster host identifier must be configured in the shell setting '{0}'.", Constants.OutputCacheHostIdentifierSettingName),
|
||||
Type = NotifyType.Warning
|
||||
};
|
||||
if (String.IsNullOrWhiteSpace(_shellSettings[Constants.OutputCacheCacheNameSettingName]))
|
||||
yield return new NotifyEntry {
|
||||
Message = T("A cache name must be configured in the shell setting '{0}'.", Constants.OutputCacheCacheNameSettingName),
|
||||
Type = NotifyType.Warning
|
||||
};
|
||||
bool result;
|
||||
if (!Boolean.TryParse(_shellSettings[Constants.OutputCacheIsSharedCachingSettingName], out result))
|
||||
yield return new NotifyEntry {
|
||||
Message = T("A valid boolean value must be configured in the shell setting '{0}'.", Constants.OutputCacheIsSharedCachingSettingName),
|
||||
Type = NotifyType.Warning
|
||||
};
|
||||
}
|
||||
|
||||
if (enabledFeatureNamesQuery.Contains(Constants.DatabaseCacheFeatureName)) {
|
||||
// Create default configuration to local role-based cache when feature is enabled.
|
||||
if (!_shellSettings.Keys.Contains(Constants.DatabaseCacheHostIdentifierSettingName))
|
||||
_shellSettings[Constants.DatabaseCacheHostIdentifierSettingName] = "Orchard.Azure.Web";
|
||||
if (!_shellSettings.Keys.Contains(Constants.DatabaseCacheCacheNameSettingName))
|
||||
_shellSettings[Constants.DatabaseCacheCacheNameSettingName] = "DatabaseCache";
|
||||
if (!_shellSettings.Keys.Contains(Constants.DatabaseCacheIsSharedCachingSettingName))
|
||||
_shellSettings[Constants.DatabaseCacheIsSharedCachingSettingName] = "false";
|
||||
|
||||
if (String.IsNullOrWhiteSpace(_shellSettings[Constants.DatabaseCacheHostIdentifierSettingName]))
|
||||
yield return new NotifyEntry {
|
||||
Message = T("A cache cluster host identifier must be configured in the shell setting '{0}'.", Constants.DatabaseCacheHostIdentifierSettingName),
|
||||
Type = NotifyType.Warning
|
||||
};
|
||||
if (String.IsNullOrWhiteSpace(_shellSettings[Constants.DatabaseCacheCacheNameSettingName]))
|
||||
yield return new NotifyEntry {
|
||||
Message = T("A cache name must be configured in the shell setting '{0}'.", Constants.DatabaseCacheCacheNameSettingName),
|
||||
Type = NotifyType.Warning
|
||||
};
|
||||
bool result;
|
||||
if (!Boolean.TryParse(_shellSettings[Constants.DatabaseCacheIsSharedCachingSettingName], out result))
|
||||
yield return new NotifyEntry {
|
||||
Message = T("A valid boolean value must be configured in the shell setting '{0}'.", Constants.DatabaseCacheIsSharedCachingSettingName),
|
||||
Type = NotifyType.Warning
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user