Adding configurable sections in HostComponents.config

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2013-05-09 16:57:45 -07:00
parent 0438074842
commit 886295312f
20 changed files with 194 additions and 31 deletions

View File

@@ -272,10 +272,6 @@
<XmlDelete XmlFileName="$(StageFolder)\Config\log4net.config" <XmlDelete XmlFileName="$(StageFolder)\Config\log4net.config"
XPath="/log4net/root/appender-ref[@ref='debug-file']" /> XPath="/log4net/root/appender-ref[@ref='debug-file']" />
<!-- disable dynamic compilation loader -->
<Move SourceFiles="$(StageFolder)\Config\Sample.HostComponents.config"
DestinationFiles="$(StageFolder)\Config\HostComponents.config"/>
<XmlUpdate XmlFileName="$(StageFolder)\Config\HostComponents.config" <XmlUpdate XmlFileName="$(StageFolder)\Config\HostComponents.config"
XPath="/HostComponents/Components/Component[@Type='Orchard.Environment.Extensions.Loaders.DynamicExtensionLoader']/Properties/Property/@Value" XPath="/HostComponents/Components/Component[@Type='Orchard.Environment.Extensions.Loaders.DynamicExtensionLoader']/Properties/Property/@Value"
Value="true" /> Value="true" />

View File

@@ -8,6 +8,7 @@
<autofac defaultAssembly="Orchard.Framework"> <autofac defaultAssembly="Orchard.Framework">
<components> <components>
<!--
<component instance-scope="single-instance" <component instance-scope="single-instance"
type="Orchard.Environment.Configuration.AzureBlobTenantManager" type="Orchard.Environment.Configuration.AzureBlobTenantManager"
service="Orchard.Environment.Configuration.IShellSettingsManager"> service="Orchard.Environment.Configuration.IShellSettingsManager">
@@ -17,6 +18,7 @@
<parameter name="container" value="mycontainer"/> <parameter name="container" value="mycontainer"/>
</parameters> </parameters>
</component> </component>
-->
</components> </components>
</autofac> </autofac>

View File

@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8" ?>
<HostComponents>
<Components>
<!-- Set Value="true" to disable new extensions monitoring -->
<Component Type="Orchard.Environment.Extensions.ExtensionMonitoringCoordinator">
<Properties>
<Property Name="Disabled" Value="false"/>
</Properties>
</Component>
<!-- Set Value="true" to disable Placement files monitoring (Placement.info) -->
<Component Type="Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy.PlacementFileParser">
<Properties>
<Property Name="DisableMonitoring" Value="false"/>
</Properties>
</Component>
<!-- Set Value="true" to disable template views monitoring (Views\*.cshtml) -->
<Component Type="Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy.ShapeTemplateBindingStrategy">
<Properties>
<Property Name="DisableMonitoring" Value="false"/>
</Properties>
</Component>
<!-- Set Value="true" to disable extension folders monitoring (new files in modules and themes) -->
<Component Type="Orchard.Environment.Extensions.Folders.ExtensionHarvester">
<Properties>
<Property Name="DisableMonitoring" Value="false"/>
</Properties>
</Component>
<!-- Set Value="true" to disable project files monitoring (/Modules/**/*.csproj) -->
<Component Type="Orchard.Environment.Extensions.Compilers.DefaultProjectFileParser">
<Properties>
<Property Name="DisableMonitoring" Value="false"/>
</Properties>
</Component>
<!-- Set Value="true" to disable source files monitoring -->
<Component Type="Orchard.Environment.Extensions.Loaders.DynamicExtensionLoader">
<Properties>
<Property Name="DisableMonitoring" Value="false"/>
</Properties>
</Component>
<!-- Set Value="true" to completely disable the Dynamic Extension Loader -->
<Component Type="Orchard.Environment.Extensions.Loaders.DynamicExtensionLoader">
<Properties>
<Property Name="Disabled" Value="false"/>
</Properties>
</Component>
<!-- Set Value="true" to disable pre-compiled files monitoring (~/Modules/**/bin/*.dll) -->
<Component Type="Orchard.Environment.Extensions.Loaders.PrecompiledExtensionLoader">
<Properties>
<Property Name="DisableMonitoring" Value="false"/>
</Properties>
</Component>
<!-- Set Value="true" to disable the dependencies folder monitoring -->
<Component Type="Orchard.FileSystems.Dependencies.DefaultDependenciesFolder">
<Properties>
<Property Name="DisableMonitoring" Value="false"/>
</Properties>
</Component>
<!-- Set Value="true" to disable compiled dependencides files monitoring -->
<Component Type="Orchard.FileSystems.Dependencies.DefaultExtensionDependenciesManager">
<Properties>
<Property Name="DisableMonitoring" Value="false"/>
</Properties>
</Component>
<!-- Set Value="true" to disable localization files monitoring (*.po) -->
<Component Type="Orchard.Localization.Services.DefaultLocalizedStringManager">
<Properties>
<Property Name="DisableMonitoring" Value="false"/>
</Properties>
</Component>
<!-- Set Value="true" to disable parallel cache resolution -->
<Component Type="Orchard.Caching.DefaultParallelCacheContext">
<Properties>
<Property Name="Disabled" Value="false"/>
</Properties>
</Component>
</Components>
</HostComponents>

View File

@@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<HostComponents>
<Components>
<Component Type="Orchard.Environment.Extensions.ExtensionMonitoringCoordinator">
<Properties>
<Property Name="Disabled" Value="true"/>
</Properties>
</Component>
</Components>
</HostComponents>

View File

@@ -131,7 +131,7 @@
<Content Include="Config\log4net.config"> <Content Include="Config\log4net.config">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Content> </Content>
<Content Include="Config\Sample.HostComponents.config"> <Content Include="Config\HostComponents.config">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Content> </Content>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
@@ -162,7 +162,7 @@
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Config\Sample.Host.config" /> <Content Include="Config\Host.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="App_Data\" /> <Folder Include="App_Data\" />
@@ -232,7 +232,6 @@
<XmlDelete XmlFileName="$(PackageTmp)\Config\log4net.config" XPath="/log4net/logger[@name='Orchard']" /> <XmlDelete XmlFileName="$(PackageTmp)\Config\log4net.config" XPath="/log4net/logger[@name='Orchard']" />
<XmlDelete XmlFileName="$(PackageTmp)\Config\log4net.config" XPath="/log4net/root/appender-ref[@ref='debug-file']" /> <XmlDelete XmlFileName="$(PackageTmp)\Config\log4net.config" XPath="/log4net/root/appender-ref[@ref='debug-file']" />
<!-- disable dynamic compilation loader --> <!-- disable dynamic compilation loader -->
<Copy SourceFiles="$(PackageTmp)\Config\Sample.HostComponents.config" DestinationFiles="$(PackageTmp)\Config\HostComponents.config" />
<XmlUpdate XmlFileName="$(PackageTmp)\Config\HostComponents.config" XPath="/HostComponents/Components/Component[@Type='Orchard.Environment.Extensions.Loaders.DynamicExtensionLoader']/Properties/Property/@Value" Value="true" /> <XmlUpdate XmlFileName="$(PackageTmp)\Config\HostComponents.config" XPath="/HostComponents/Components/Component[@Type='Orchard.Environment.Extensions.Loaders.DynamicExtensionLoader']/Properties/Property/@Value" Value="true" />
</Target> </Target>
<Target Name="AfterBuild" DependsOnTargets="AfterBuildCompiler"> <Target Name="AfterBuild" DependsOnTargets="AfterBuildCompiler">

View File

@@ -123,7 +123,7 @@
--> -->
<system.webServer> <system.webServer>
<validation validateIntegratedModeConfiguration="false"/> <validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"> <modules runAllManagedModulesForAllRequests="false">
<remove name="WarmupHttpModule"/> <remove name="WarmupHttpModule"/>
<add name="WarmupHttpModule" type="Orchard.WarmupStarter.WarmupHttpModule, Orchard.WarmupStarter, Version=1.0.20, Culture=neutral"/> <add name="WarmupHttpModule" type="Orchard.WarmupStarter.WarmupHttpModule, Orchard.WarmupStarter, Version=1.0.20, Culture=neutral"/>
</modules> </modules>

View File

@@ -3,6 +3,7 @@ using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
using Orchard.Caching; using Orchard.Caching;
using Orchard.FileSystems.WebSite; using Orchard.FileSystems.WebSite;
using Orchard.Logging;
namespace Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy { namespace Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy {
@@ -21,11 +22,20 @@ namespace Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy {
public PlacementFileParser(ICacheManager cacheManager, IWebSiteFolder webSiteFolder) { public PlacementFileParser(ICacheManager cacheManager, IWebSiteFolder webSiteFolder) {
_cacheManager = cacheManager; _cacheManager = cacheManager;
_webSiteFolder = webSiteFolder; _webSiteFolder = webSiteFolder;
Logger = NullLogger.Instance;
} }
public ILogger Logger { get; set; }
public bool DisableMonitoring { get; set; }
public PlacementFile Parse(string virtualPath) { public PlacementFile Parse(string virtualPath) {
return _cacheManager.Get(virtualPath, context => { return _cacheManager.Get(virtualPath, context => {
if (!DisableMonitoring) {
Logger.Debug("Monitoring virtual path \"{0}\"", virtualPath);
context.Monitor(_webSiteFolder.WhenPathChanges(virtualPath)); context.Monitor(_webSiteFolder.WhenPathChanges(virtualPath));
}
var placementText = _webSiteFolder.ReadFile(virtualPath); var placementText = _webSiteFolder.ReadFile(virtualPath);
return ParseImplementation(virtualPath, placementText); return ParseImplementation(virtualPath, placementText);
}); });

View File

@@ -49,6 +49,7 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
} }
public ILogger Logger { get; set; } public ILogger Logger { get; set; }
public bool DisableMonitoring { get; set; }
private static IEnumerable<ExtensionDescriptor> Once(IEnumerable<FeatureDescriptor> featureDescriptors) { private static IEnumerable<ExtensionDescriptor> Once(IEnumerable<FeatureDescriptor> featureDescriptors) {
var once = new ConcurrentDictionary<string, object>(); var once = new ConcurrentDictionary<string, object>();
@@ -73,7 +74,11 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
if (!_virtualPathProvider.DirectoryExists(virtualPath)) if (!_virtualPathProvider.DirectoryExists(virtualPath))
return new List<string>(); return new List<string>();
if (!DisableMonitoring) {
Logger.Debug("Monitoring virtual path \"{0}\"", virtualPath);
ctx.Monitor(_virtualPathMonitor.WhenPathChanges(virtualPath)); ctx.Monitor(_virtualPathMonitor.WhenPathChanges(virtualPath));
}
return _virtualPathProvider.ListFiles(virtualPath).Select(Path.GetFileName).ToReadOnlyCollection(); return _virtualPathProvider.ListFiles(virtualPath).Select(Path.GetFileName).ToReadOnlyCollection();
}); });
return new { harvesterInfo.harvester, basePath, subPath, virtualPath, fileNames }; return new { harvesterInfo.harvester, basePath, subPath, virtualPath, fileNames };

View File

@@ -5,6 +5,7 @@ using System.Xml;
using System.Xml.Linq; using System.Xml.Linq;
using Orchard.Caching; using Orchard.Caching;
using Orchard.FileSystems.WebSite; using Orchard.FileSystems.WebSite;
using Orchard.Logging;
namespace Orchard.Environment.Extensions.Compilers { namespace Orchard.Environment.Extensions.Compilers {
public class DefaultProjectFileParser : IProjectFileParser { public class DefaultProjectFileParser : IProjectFileParser {
@@ -14,12 +15,21 @@ namespace Orchard.Environment.Extensions.Compilers {
public DefaultProjectFileParser(IWebSiteFolder webSiteFolder, ICacheManager cacheManager) { public DefaultProjectFileParser(IWebSiteFolder webSiteFolder, ICacheManager cacheManager) {
_webSiteFolder = webSiteFolder; _webSiteFolder = webSiteFolder;
_cacheManager = cacheManager; _cacheManager = cacheManager;
Logger = NullLogger.Instance;
} }
ILogger Logger { get; set; }
public bool DisableMonitoring { get; set; }
public ProjectFileDescriptor Parse(string virtualPath) { public ProjectFileDescriptor Parse(string virtualPath) {
return _cacheManager.Get(virtualPath, return _cacheManager.Get(virtualPath,
ctx => { ctx => {
if (!DisableMonitoring) {
Logger.Debug("Monitoring virtual path \"{0}\"", virtualPath);
ctx.Monitor(_webSiteFolder.WhenPathChanges(virtualPath)); ctx.Monitor(_webSiteFolder.WhenPathChanges(virtualPath));
}
string content = _webSiteFolder.ReadFile(virtualPath); string content = _webSiteFolder.ReadFile(virtualPath);
using (var reader = new StringReader(content)) { using (var reader = new StringReader(content)) {
return Parse(reader); return Parse(reader);

View File

@@ -43,7 +43,9 @@ namespace Orchard.Environment.Extensions {
public void MonitorExtensionsWork(Action<IVolatileToken> monitor) { public void MonitorExtensionsWork(Action<IVolatileToken> monitor) {
Logger.Information("Start monitoring extension files..."); Logger.Information("Start monitoring extension files...");
// Monitor add/remove of any module/theme // Monitor add/remove of any module/theme
Logger.Debug("Monitoring virtual path \"{0}\"", "~/Modules");
monitor(_virtualPathMonitor.WhenPathChanges("~/Modules")); monitor(_virtualPathMonitor.WhenPathChanges("~/Modules"));
Logger.Debug("Monitoring virtual path \"{0}\"", "~/Themes");
monitor(_virtualPathMonitor.WhenPathChanges("~/Themes")); monitor(_virtualPathMonitor.WhenPathChanges("~/Themes"));
// Give loaders a chance to monitor any additional changes // Give loaders a chance to monitor any additional changes

View File

@@ -44,6 +44,7 @@ namespace Orchard.Environment.Extensions.Folders {
public Localizer T { get; set; } public Localizer T { get; set; }
public ILogger Logger { get; set; } public ILogger Logger { get; set; }
public bool DisableMonitoring { get; set; }
public IEnumerable<ExtensionDescriptor> HarvestExtensions(IEnumerable<string> paths, string extensionType, string manifestName, bool manifestIsOptional) { public IEnumerable<ExtensionDescriptor> HarvestExtensions(IEnumerable<string> paths, string extensionType, string manifestName, bool manifestIsOptional) {
return paths return paths
@@ -55,7 +56,11 @@ namespace Orchard.Environment.Extensions.Folders {
string key = string.Format("{0}-{1}-{2}", path, manifestName, extensionType); string key = string.Format("{0}-{1}-{2}", path, manifestName, extensionType);
return _cacheManager.Get(key, ctx => { return _cacheManager.Get(key, ctx => {
if (!DisableMonitoring) {
Logger.Debug("Monitoring virtual path \"{0}\"", path);
ctx.Monitor(_webSiteFolder.WhenPathChanges(path)); ctx.Monitor(_webSiteFolder.WhenPathChanges(path));
}
return AvailableExtensionsInFolder(path, extensionType, manifestName, manifestIsOptional).ToReadOnlyCollection(); return AvailableExtensionsInFolder(path, extensionType, manifestName, manifestIsOptional).ToReadOnlyCollection();
}); });
} }
@@ -127,7 +132,11 @@ namespace Orchard.Environment.Extensions.Folders {
private ExtensionDescriptor GetExtensionDescriptor(string locationPath, string extensionId, string extensionType, string manifestPath, bool manifestIsOptional) { private ExtensionDescriptor GetExtensionDescriptor(string locationPath, string extensionId, string extensionType, string manifestPath, bool manifestIsOptional) {
return _cacheManager.Get(manifestPath, context => { return _cacheManager.Get(manifestPath, context => {
if (!DisableMonitoring) {
Logger.Debug("Monitoring virtual path \"{0}\"", manifestPath);
context.Monitor(_webSiteFolder.WhenPathChanges(manifestPath)); context.Monitor(_webSiteFolder.WhenPathChanges(manifestPath));
}
var manifestText = _webSiteFolder.ReadFile(manifestPath); var manifestText = _webSiteFolder.ReadFile(manifestPath);
if (manifestText == null) { if (manifestText == null) {
if (manifestIsOptional) { if (manifestIsOptional) {

View File

@@ -47,6 +47,7 @@ namespace Orchard.Environment.Extensions.Loaders {
public ILogger Logger { get; set; } public ILogger Logger { get; set; }
public bool Disabled { get; set; } public bool Disabled { get; set; }
public bool DisableMonitoring { get; set; }
public override int Order { get { return 100; } } public override int Order { get { return 100; } }
@@ -63,6 +64,9 @@ namespace Orchard.Environment.Extensions.Loaders {
if (Disabled) if (Disabled)
return; return;
if (DisableMonitoring)
return;
// Monitor .csproj and all .cs files // Monitor .csproj and all .cs files
string projectPath = GetProjectPath(descriptor); string projectPath = GetProjectPath(descriptor);
if (projectPath != null) { if (projectPath != null) {

View File

@@ -37,6 +37,7 @@ namespace Orchard.Environment.Extensions.Loaders {
public ILogger Logger { get; set; } public ILogger Logger { get; set; }
public bool Disabled { get; set; } public bool Disabled { get; set; }
public bool DisableMonitoring { get; set; }
public override int Order { get { return 30; } } public override int Order { get { return 30; } }
@@ -125,6 +126,9 @@ namespace Orchard.Environment.Extensions.Loaders {
if (Disabled) if (Disabled)
return; return;
if (DisableMonitoring)
return;
// If the assembly exists, monitor it // If the assembly exists, monitor it
string assemblyPath = GetAssemblyPath(descriptor); string assemblyPath = GetAssemblyPath(descriptor);
if (assemblyPath != null) { if (assemblyPath != null) {

View File

@@ -29,6 +29,7 @@ namespace Orchard.Environment {
if (!_appDataFolder.FileExists(fileName)) if (!_appDataFolder.FileExists(fileName))
TouchFile(); TouchFile();
Logger.Debug("Monitoring virtual path \"{0}\"", fileName);
monitor(_appDataFolder.WhenPathChanges(fileName)); monitor(_appDataFolder.WhenPathChanges(fileName));
} }

View File

@@ -99,7 +99,8 @@ namespace Orchard.FileSystems.AppData {
} }
public IVolatileToken WhenPathChanges(string path) { public IVolatileToken WhenPathChanges(string path) {
return _virtualPathMonitor.WhenPathChanges(GetVirtualPath(path)); var virtualPath = GetVirtualPath(path);
return _virtualPathMonitor.WhenPathChanges(virtualPath);
} }
public string GetVirtualPath(string path) { public string GetVirtualPath(string path) {

View File

@@ -23,6 +23,7 @@ namespace Orchard.FileSystems.Dependencies {
} }
public Localizer T { get; set; } public Localizer T { get; set; }
public bool DisableMonitoring { get; set; }
private string PersistencePath { private string PersistencePath {
get { return _appDataFolder.Combine(BasePath, FileName); } get { return _appDataFolder.Combine(BasePath, FileName); }
@@ -36,7 +37,10 @@ namespace Orchard.FileSystems.Dependencies {
return _cacheManager.Get(PersistencePath, return _cacheManager.Get(PersistencePath,
ctx => { ctx => {
_appDataFolder.CreateDirectory(BasePath); _appDataFolder.CreateDirectory(BasePath);
if (!DisableMonitoring) {
ctx.Monitor(_appDataFolder.WhenPathChanges(ctx.Key)); ctx.Monitor(_appDataFolder.WhenPathChanges(ctx.Key));
}
_writeThroughToken.IsCurrent = true; _writeThroughToken.IsCurrent = true;
ctx.Monitor(_writeThroughToken); ctx.Monitor(_writeThroughToken);

View File

@@ -28,6 +28,7 @@ namespace Orchard.FileSystems.Dependencies {
} }
public ILogger Logger { get; set; } public ILogger Logger { get; set; }
public bool DisableMonitoring { get; set; }
private string PersistencePath { private string PersistencePath {
get { return _appDataFolder.Combine(BasePath, FileName); } get { return _appDataFolder.Combine(BasePath, FileName); }
@@ -65,7 +66,10 @@ namespace Orchard.FileSystems.Dependencies {
public IEnumerable<ActivatedExtensionDescriptor> LoadDescriptors() { public IEnumerable<ActivatedExtensionDescriptor> LoadDescriptors() {
return _cacheManager.Get(PersistencePath, ctx => { return _cacheManager.Get(PersistencePath, ctx => {
_appDataFolder.CreateDirectory(BasePath); _appDataFolder.CreateDirectory(BasePath);
if (!DisableMonitoring) {
ctx.Monitor(_appDataFolder.WhenPathChanges(ctx.Key)); ctx.Monitor(_appDataFolder.WhenPathChanges(ctx.Key));
}
_writeThroughToken.IsCurrent = true; _writeThroughToken.IsCurrent = true;
ctx.Monitor(_writeThroughToken); ctx.Monitor(_writeThroughToken);

View File

@@ -86,6 +86,8 @@ namespace Orchard.FileSystems.VirtualPath {
new[] { virtualPath }, new[] { virtualPath },
_clock.UtcNow); _clock.UtcNow);
Logger.Debug("Monitoring virtual path \"{0}\"", virtualPath);
HostingEnvironment.Cache.Add( HostingEnvironment.Cache.Add(
key, key,
virtualPath, virtualPath,
@@ -98,6 +100,8 @@ namespace Orchard.FileSystems.VirtualPath {
public void Signal(string key, object value, CacheItemRemovedReason reason) { public void Signal(string key, object value, CacheItemRemovedReason reason) {
var virtualPath = Convert.ToString(value); var virtualPath = Convert.ToString(value);
Logger.Debug("Virtual path changed '{0}'", virtualPath);
var token = DetachToken(virtualPath); var token = DetachToken(virtualPath);
if (token != null) if (token != null)
token.IsCurrent = false; token.IsCurrent = false;

View File

@@ -4,6 +4,7 @@ using System.Linq;
using System.Web.Hosting; using System.Web.Hosting;
using Orchard.Caching; using Orchard.Caching;
using Orchard.FileSystems.VirtualPath; using Orchard.FileSystems.VirtualPath;
using Orchard.Logging;
namespace Orchard.FileSystems.WebSite { namespace Orchard.FileSystems.WebSite {
public class WebSiteFolder : IWebSiteFolder { public class WebSiteFolder : IWebSiteFolder {
@@ -13,8 +14,12 @@ namespace Orchard.FileSystems.WebSite {
public WebSiteFolder(IVirtualPathMonitor virtualPathMonitor, IVirtualPathProvider virtualPathProvider) { public WebSiteFolder(IVirtualPathMonitor virtualPathMonitor, IVirtualPathProvider virtualPathProvider) {
_virtualPathMonitor = virtualPathMonitor; _virtualPathMonitor = virtualPathMonitor;
_virtualPathProvider = virtualPathProvider; _virtualPathProvider = virtualPathProvider;
Logger = NullLogger.Instance;
} }
public ILogger Logger { get; set; }
public IEnumerable<string> ListDirectories(string virtualPath) { public IEnumerable<string> ListDirectories(string virtualPath) {
if (!_virtualPathProvider.DirectoryExists(virtualPath)) { if (!_virtualPathProvider.DirectoryExists(virtualPath)) {
return Enumerable.Empty<string>(); return Enumerable.Empty<string>();

View File

@@ -8,6 +8,7 @@ using Orchard.Environment.Configuration;
using Orchard.Environment.Extensions; using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models; using Orchard.Environment.Extensions.Models;
using Orchard.FileSystems.WebSite; using Orchard.FileSystems.WebSite;
using Orchard.Logging;
namespace Orchard.Localization.Services { namespace Orchard.Localization.Services {
public class DefaultLocalizedStringManager : ILocalizedStringManager { public class DefaultLocalizedStringManager : ILocalizedStringManager {
@@ -33,8 +34,13 @@ namespace Orchard.Localization.Services {
_cacheManager = cacheManager; _cacheManager = cacheManager;
_shellSettings = shellSettings; _shellSettings = shellSettings;
_signals = signals; _signals = signals;
Logger = NullLogger.Instance;
} }
ILogger Logger { get; set; }
public bool DisableMonitoring { get; set; }
// This will translate a string into a string in the target cultureName. // This will translate a string into a string in the target cultureName.
// The scope portion is optional, it amounts to the location of the file containing // The scope portion is optional, it amounts to the location of the file containing
// the string in case it lives in a view, or the namespace name if the string lives in a binary. // the string in case it lives in a view, or the namespace name if the string lives in a binary.
@@ -109,8 +115,11 @@ namespace Orchard.Localization.Services {
string text = _webSiteFolder.ReadFile(corePath); string text = _webSiteFolder.ReadFile(corePath);
if (text != null) { if (text != null) {
ParseLocalizationStream(text, translations, false); ParseLocalizationStream(text, translations, false);
if (!DisableMonitoring) {
Logger.Debug("Monitoring virtual path \"{0}\"", corePath);
context.Monitor(_webSiteFolder.WhenPathChanges(corePath)); context.Monitor(_webSiteFolder.WhenPathChanges(corePath));
} }
}
foreach (var module in _extensionManager.AvailableExtensions()) { foreach (var module in _extensionManager.AvailableExtensions()) {
if (DefaultExtensionTypes.IsModule(module.ExtensionType)) { if (DefaultExtensionTypes.IsModule(module.ExtensionType)) {
@@ -118,10 +127,14 @@ namespace Orchard.Localization.Services {
text = _webSiteFolder.ReadFile(modulePath); text = _webSiteFolder.ReadFile(modulePath);
if (text != null) { if (text != null) {
ParseLocalizationStream(text, translations, true); ParseLocalizationStream(text, translations, true);
if (!DisableMonitoring) {
Logger.Debug("Monitoring virtual path \"{0}\"", modulePath);
context.Monitor(_webSiteFolder.WhenPathChanges(modulePath)); context.Monitor(_webSiteFolder.WhenPathChanges(modulePath));
} }
} }
} }
}
foreach (var theme in _extensionManager.AvailableExtensions()) { foreach (var theme in _extensionManager.AvailableExtensions()) {
if (DefaultExtensionTypes.IsTheme(theme.ExtensionType)) { if (DefaultExtensionTypes.IsTheme(theme.ExtensionType)) {
@@ -129,24 +142,34 @@ namespace Orchard.Localization.Services {
text = _webSiteFolder.ReadFile(themePath); text = _webSiteFolder.ReadFile(themePath);
if (text != null) { if (text != null) {
ParseLocalizationStream(text, translations, true); ParseLocalizationStream(text, translations, true);
if (!DisableMonitoring) {
Logger.Debug("Monitoring virtual path \"{0}\"", themePath);
context.Monitor(_webSiteFolder.WhenPathChanges(themePath)); context.Monitor(_webSiteFolder.WhenPathChanges(themePath));
} }
} }
} }
}
string rootPath = string.Format(RootLocalizationFilePathFormat, culture); string rootPath = string.Format(RootLocalizationFilePathFormat, culture);
text = _webSiteFolder.ReadFile(rootPath); text = _webSiteFolder.ReadFile(rootPath);
if (text != null) { if (text != null) {
ParseLocalizationStream(text, translations, true); ParseLocalizationStream(text, translations, true);
if (!DisableMonitoring) {
Logger.Debug("Monitoring virtual path \"{0}\"", rootPath);
context.Monitor(_webSiteFolder.WhenPathChanges(rootPath)); context.Monitor(_webSiteFolder.WhenPathChanges(rootPath));
} }
}
string tenantPath = string.Format(TenantLocalizationFilePathFormat, _shellSettings.Name, culture); string tenantPath = string.Format(TenantLocalizationFilePathFormat, _shellSettings.Name, culture);
text = _webSiteFolder.ReadFile(tenantPath); text = _webSiteFolder.ReadFile(tenantPath);
if (text != null) { if (text != null) {
ParseLocalizationStream(text, translations, true); ParseLocalizationStream(text, translations, true);
if (!DisableMonitoring) {
Logger.Debug("Monitoring virtual path \"{0}\"", tenantPath);
context.Monitor(_webSiteFolder.WhenPathChanges(tenantPath)); context.Monitor(_webSiteFolder.WhenPathChanges(tenantPath));
} }
}
return translations; return translations;
} }