mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Dynamic loading: monitor .cs files in addition to .csproj file
--HG-- branch : dev
This commit is contained in:
@@ -16,7 +16,7 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
private readonly IVirtualPathProvider _virtualPathProvider;
|
private readonly IVirtualPathProvider _virtualPathProvider;
|
||||||
private readonly IVirtualPathMonitor _virtualPathMonitor;
|
private readonly IVirtualPathMonitor _virtualPathMonitor;
|
||||||
private readonly IProjectFileParser _projectFileParser;
|
private readonly IProjectFileParser _projectFileParser;
|
||||||
private static readonly ReloadWorkaround _reloadWorkaround = new ReloadWorkaround();
|
private readonly ReloadWorkaround _reloadWorkaround = new ReloadWorkaround();
|
||||||
|
|
||||||
public DynamicExtensionLoader(
|
public DynamicExtensionLoader(
|
||||||
IBuildManager buildManager,
|
IBuildManager buildManager,
|
||||||
@@ -43,16 +43,20 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerable<string> GetWebFormVirtualDependencies(DependencyDescriptor dependency) {
|
public override IEnumerable<string> GetWebFormVirtualDependencies(DependencyDescriptor dependency) {
|
||||||
yield return dependency.VirtualPath;
|
// Return csproj and all .cs files
|
||||||
|
return GetDependencies(dependency.VirtualPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Monitor(ExtensionDescriptor descriptor, Action<IVolatileToken> monitor) {
|
public override void Monitor(ExtensionDescriptor descriptor, Action<IVolatileToken> monitor) {
|
||||||
// We need to monitor the path to the ".csproj" file.
|
// Monitor .csproj and all .cs files
|
||||||
string projectPath = GetProjectPath(descriptor);
|
string projectPath = GetProjectPath(descriptor);
|
||||||
if (projectPath != null) {
|
if (projectPath != null) {
|
||||||
Logger.Information("Monitoring virtual path \"{0}\"", projectPath);
|
foreach (var path in GetDependencies(projectPath)) {
|
||||||
monitor(_virtualPathMonitor.WhenPathChanges(projectPath));
|
Logger.Information("Monitoring virtual path \"{0}\"", path);
|
||||||
_reloadWorkaround.Monitor(_virtualPathMonitor.WhenPathChanges(projectPath));
|
|
||||||
|
monitor(_virtualPathMonitor.WhenPathChanges(path));
|
||||||
|
_reloadWorkaround.Monitor(_virtualPathMonitor.WhenPathChanges(path));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +64,7 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
// Since a dynamic assembly is not active anymore, we need to notify ASP.NET
|
// Since a dynamic assembly is not active anymore, we need to notify ASP.NET
|
||||||
// that a new site compilation is needed (since ascx files may be referencing
|
// that a new site compilation is needed (since ascx files may be referencing
|
||||||
// this now removed extension).
|
// this now removed extension).
|
||||||
Logger.Information("ExtensionRemoved: Module \"{0}\" has been removed, forcing site recompilation");
|
Logger.Information("ExtensionRemoved: Module \"{0}\" has been removed, forcing site recompilation", dependency.Name);
|
||||||
ctx.ResetSiteCompilation = true;
|
ctx.ResetSiteCompilation = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +72,7 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
// Since a dynamic assembly is not active anymore, we need to notify ASP.NET
|
// Since a dynamic assembly is not active anymore, we need to notify ASP.NET
|
||||||
// that a new site compilation is needed (since ascx files may be referencing
|
// that a new site compilation is needed (since ascx files may be referencing
|
||||||
// this now removed extension).
|
// this now removed extension).
|
||||||
Logger.Information("ExtensionDeactivated: Module \"{0}\" has been de-activated, forcing site recompilation");
|
Logger.Information("ExtensionDeactivated: Module \"{0}\" has been de-activated, forcing site recompilation", extension.Name);
|
||||||
ctx.ResetSiteCompilation = true;
|
ctx.ResetSiteCompilation = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +111,7 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
|
|
||||||
return new ExtensionProbeEntry {
|
return new ExtensionProbeEntry {
|
||||||
Descriptor = descriptor,
|
Descriptor = descriptor,
|
||||||
LastWriteTimeUtc = _virtualPathProvider.GetFileLastWriteTimeUtc(projectPath),
|
LastWriteTimeUtc = GetDependencies(projectPath).Max(f => _virtualPathProvider.GetFileLastWriteTimeUtc(f)),
|
||||||
Loader = this,
|
Loader = this,
|
||||||
VirtualPath = projectPath
|
VirtualPath = projectPath
|
||||||
};
|
};
|
||||||
@@ -130,6 +134,20 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IEnumerable<string> GetDependencies(string projectPath) {
|
||||||
|
return new[] {projectPath}.Concat(GetSourceFiles(projectPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<string> GetSourceFiles(string projectPath) {
|
||||||
|
var basePath = _virtualPathProvider.GetDirectoryName(projectPath);
|
||||||
|
|
||||||
|
using (var stream = _virtualPathProvider.OpenFile(projectPath)) {
|
||||||
|
var projectFile = _projectFileParser.Parse(stream);
|
||||||
|
|
||||||
|
return projectFile.SourceFilenames.Select(f => _virtualPathProvider.Combine(basePath, f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private string GetProjectPath(ExtensionDescriptor descriptor) {
|
private string GetProjectPath(ExtensionDescriptor descriptor) {
|
||||||
string projectPath = _virtualPathProvider.Combine(descriptor.Location, descriptor.Name,
|
string projectPath = _virtualPathProvider.Combine(descriptor.Location, descriptor.Name,
|
||||||
descriptor.Name + ".csproj");
|
descriptor.Name + ".csproj");
|
||||||
|
|||||||
Reference in New Issue
Block a user