Work items: 29899
This commit is contained in:
@@ -40,7 +40,7 @@ namespace umbraco.MacroEngines
|
||||
try
|
||||
{
|
||||
string parsedResult;
|
||||
if (!GetResult("RazorValidation", code, currentPage, out parsedResult)) {
|
||||
if (!GetResult(null, code, currentPage, out parsedResult)) {
|
||||
errorMessage = parsedResult;
|
||||
return false;
|
||||
}
|
||||
@@ -68,11 +68,26 @@ namespace umbraco.MacroEngines
|
||||
: loadScript(IOHelper.MapPath(SystemDirectories.Python + "/" + macro.ScriptName));
|
||||
string parsedResult;
|
||||
GetResult(macro.CacheIdentifier, template, currentPage, out parsedResult);
|
||||
|
||||
// if it's a file we'll monitor changes to ensure that any updates to the file clears the cache
|
||||
if (String.IsNullOrEmpty(macro.ScriptCode)) {
|
||||
FileMonitor.Listen(SystemDirectories.Python + "/" + macro.ScriptName, action => RazorEngine.ClearRazorCompilationCache());
|
||||
}
|
||||
|
||||
return parsedResult;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// This clears all compiled razor scripts, thus ensures that changes made to files or scripts causes a recompilation
|
||||
/// </summary>
|
||||
public static void ClearRazorCompilationCache()
|
||||
{
|
||||
Razor.SetTemplateBaseType(typeof(HtmlTemplateBase<>));
|
||||
Razor.SetTemplateBaseType(typeof(UmbracoTemplateBase<>));
|
||||
}
|
||||
|
||||
private bool GetResult(string cacheIdentifier, string template, INode currentPage, out string result)
|
||||
{
|
||||
try
|
||||
|
||||
70
umbraco/businesslogic/IO/FileMonitor.cs
Normal file
70
umbraco/businesslogic/IO/FileMonitor.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Caching;
|
||||
using System.Web.Hosting;
|
||||
|
||||
namespace umbraco.IO
|
||||
{
|
||||
/// <summary>
|
||||
/// This class can be used to monitor file changes and update accordingly. This is copied
|
||||
/// from http://haacked.com/archive/2010/01/17/editable-routes.aspx and based on work in Dynamic Data
|
||||
/// </summary>
|
||||
public class FileMonitor
|
||||
{
|
||||
private FileMonitor(Action<string> changeCallback)
|
||||
: this(HostingEnvironment.VirtualPathProvider, changeCallback)
|
||||
{
|
||||
}
|
||||
|
||||
private FileMonitor(VirtualPathProvider vpp,
|
||||
Action<string> changeCallback)
|
||||
{
|
||||
_vpp = vpp;
|
||||
_changeCallback = changeCallback;
|
||||
}
|
||||
|
||||
VirtualPathProvider _vpp;
|
||||
Action<string> _changeCallback;
|
||||
|
||||
// When the file at the given path changes,
|
||||
// we'll call the supplied action.
|
||||
public static void Listen(string virtualPath, Action<string> action)
|
||||
{
|
||||
var notifier = new FileMonitor(action);
|
||||
notifier.ListenForChanges(virtualPath);
|
||||
}
|
||||
|
||||
void ListenForChanges(string virtualPath)
|
||||
{
|
||||
// Get a CacheDependency from the BuildProvider,
|
||||
// so that we know anytime something changes
|
||||
var virtualPathDependencies = new List<string>();
|
||||
virtualPathDependencies.Add(virtualPath);
|
||||
CacheDependency cacheDependency = _vpp.GetCacheDependency(
|
||||
virtualPath, virtualPathDependencies, DateTime.UtcNow);
|
||||
HttpRuntime.Cache.Insert(virtualPath /*key*/,
|
||||
virtualPath /*value*/,
|
||||
cacheDependency,
|
||||
Cache.NoAbsoluteExpiration,
|
||||
Cache.NoSlidingExpiration,
|
||||
CacheItemPriority.NotRemovable,
|
||||
new CacheItemRemovedCallback(OnConfigFileChanged));
|
||||
}
|
||||
|
||||
void OnConfigFileChanged(string key, object value,
|
||||
CacheItemRemovedReason reason)
|
||||
{
|
||||
// We only care about dependency changes
|
||||
if (reason != CacheItemRemovedReason.DependencyChanged)
|
||||
return;
|
||||
|
||||
_changeCallback(key);
|
||||
|
||||
// Need to listen for the next change
|
||||
ListenForChanges(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -158,6 +158,7 @@
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Interfaces\ILog.cs" />
|
||||
<Compile Include="IO\FileMonitor.cs" />
|
||||
<Compile Include="IO\IOHelper.cs" />
|
||||
<Compile Include="IO\SystemDirectories.cs" />
|
||||
<Compile Include="IO\SystemFiles.cs" />
|
||||
|
||||
Reference in New Issue
Block a user