Major refactor of macro.cs, fixing huge memory leak in caching of xsltExtensions. Work items: 30616, 30522
This commit is contained in:
@@ -63,7 +63,7 @@ namespace umbraco.editorControls.macrocontainer
|
||||
// with _macroSelectDropdown.Items.Add(new ListItem(GetMacroNameFromAlias(item), item));
|
||||
private string GetMacroNameFromAlias(string alias)
|
||||
{
|
||||
var macro = umbraco.macro.ReturnFromAlias(alias);
|
||||
var macro = umbraco.macro.GetMacro(alias);
|
||||
|
||||
return macro == null ? string.Empty : macro.Name;
|
||||
}
|
||||
|
||||
@@ -472,7 +472,7 @@ namespace umbraco.editorControls.tinyMCE3.webcontrol
|
||||
// Insert macro contents here...
|
||||
macro m;
|
||||
if (helper.FindAttribute(attributes, "macroID") != "")
|
||||
m = new macro(int.Parse(helper.FindAttribute(attributes, "macroID")));
|
||||
m = macro.GetMacro(int.Parse(helper.FindAttribute(attributes, "macroID")));
|
||||
else
|
||||
{
|
||||
// legacy: Check if the macroAlias is typed in lowercasing
|
||||
@@ -485,7 +485,7 @@ namespace umbraco.editorControls.tinyMCE3.webcontrol
|
||||
}
|
||||
|
||||
if (macroAlias != "")
|
||||
m = new macro(Macro.GetByAlias(macroAlias).Id);
|
||||
m = macro.GetMacro(macroAlias);
|
||||
else
|
||||
throw new ArgumentException("umbraco is unable to identify the macro. No id or macroalias was provided for the macro in the macro tag.", tag.Groups[1].Value);
|
||||
}
|
||||
|
||||
@@ -487,23 +487,40 @@ namespace umbraco.cms.businesslogic.macro
|
||||
/// </summary>
|
||||
/// <param name="Alias">The alias of the macro</param>
|
||||
/// <returns>If the macro with the given alias exists, it returns the macro, else null</returns>
|
||||
|
||||
public static Macro GetByAlias(string Alias)
|
||||
{
|
||||
return Cache.GetCacheItem(GetCacheKey(Alias), macroCacheSyncLock,
|
||||
|
||||
public static Macro GetByAlias(string alias)
|
||||
{
|
||||
return Cache.GetCacheItem(GetCacheKey(alias), macroCacheSyncLock,
|
||||
TimeSpan.FromMinutes(30),
|
||||
delegate
|
||||
{
|
||||
try
|
||||
{
|
||||
return new Macro(Alias);
|
||||
return new Macro(alias);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static Macro GetById(int id)
|
||||
{
|
||||
return Cache.GetCacheItem(GetCacheKey(string.Format("macro_via_id_{0}", id)), macroCacheSyncLock,
|
||||
TimeSpan.FromMinutes(30),
|
||||
delegate
|
||||
{
|
||||
try
|
||||
{
|
||||
return new Macro(id);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static MacroTypes FindMacroType(string xslt, string scriptFile, string scriptType, string scriptAssembly)
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace umbraco.cms.businesslogic.macro
|
||||
[Serializable]
|
||||
public class MacroModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Alias { get; set; }
|
||||
public string MacroControlIdentifier { get; set; }
|
||||
@@ -25,6 +26,9 @@ namespace umbraco.cms.businesslogic.macro
|
||||
public int CacheDuration { get; set; }
|
||||
public bool CacheByPage { get; set; }
|
||||
public bool CacheByMember { get; set; }
|
||||
|
||||
public bool RenderInEditor { get; set; }
|
||||
|
||||
public string CacheIdentifier { get; set; }
|
||||
|
||||
public List<MacroPropertyModel> Properties { get; set; }
|
||||
@@ -34,6 +38,32 @@ namespace umbraco.cms.businesslogic.macro
|
||||
Properties = new List<MacroPropertyModel>();
|
||||
}
|
||||
|
||||
public MacroModel(Macro m)
|
||||
{
|
||||
Id = m.Id;
|
||||
Name = m.Name;
|
||||
Alias = m.Alias;
|
||||
TypeAssembly = m.Assembly;
|
||||
TypeName = m.Type;
|
||||
Xslt = m.Xslt;
|
||||
ScriptName = m.ScriptingFile;
|
||||
CacheDuration = m.RefreshRate;
|
||||
CacheByPage = m.CacheByPage;
|
||||
CacheByMember = m.CachePersonalized;
|
||||
RenderInEditor = m.RenderContent;
|
||||
|
||||
Properties = new List<MacroPropertyModel>();
|
||||
|
||||
foreach (MacroProperty mp in m.Properties)
|
||||
{
|
||||
Properties.Add(
|
||||
new MacroPropertyModel(mp.Alias, string.Empty, mp.Type.Alias, mp.Type.BaseType));
|
||||
}
|
||||
|
||||
MacroType = Macro.FindMacroType(Xslt, ScriptName, TypeName, TypeAssembly);
|
||||
|
||||
}
|
||||
|
||||
public MacroModel(string name, string alias, string typeAssembly, string typeName, string xslt, string scriptName, int cacheDuration, bool cacheByPage, bool cacheByMember)
|
||||
{
|
||||
Name = name;
|
||||
@@ -57,7 +87,8 @@ namespace umbraco.cms.businesslogic.macro
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public string Value { get; set; }
|
||||
|
||||
public string Type { get; set; }
|
||||
public string CLRType { get; set; }
|
||||
public MacroPropertyModel()
|
||||
{
|
||||
|
||||
@@ -68,6 +99,14 @@ namespace umbraco.cms.businesslogic.macro
|
||||
Key = key;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public MacroPropertyModel(string key, string value, string type, string clrType)
|
||||
{
|
||||
Key = key;
|
||||
Value = value;
|
||||
Type = type;
|
||||
CLRType = clrType;
|
||||
}
|
||||
}
|
||||
|
||||
public enum MacroTypes
|
||||
|
||||
@@ -179,6 +179,14 @@ namespace umbraco.presentation
|
||||
}
|
||||
}
|
||||
|
||||
public virtual TraceContext Trace
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_HttpContext.Trace;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the request for the current context
|
||||
/// </summary>
|
||||
|
||||
@@ -97,5 +97,6 @@ namespace umbraco.presentation
|
||||
return IOHelper.ResolveUrl( SystemDirectories.Data );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -279,7 +279,7 @@ namespace umbraco
|
||||
if (macroID != String.Empty)
|
||||
tempMacro = getMacro(macroID);
|
||||
else
|
||||
tempMacro = macro.ReturnFromAlias(helper.FindAttribute(attributes, "macroalias"));
|
||||
tempMacro = macro.GetMacro(helper.FindAttribute(attributes, "macroalias"));
|
||||
|
||||
if (tempMacro != null)
|
||||
{
|
||||
@@ -460,7 +460,7 @@ namespace umbraco
|
||||
private macro getMacro(String macroID)
|
||||
{
|
||||
System.Web.HttpContext.Current.Trace.Write("umbracoTemplate", "Starting macro (" + macroID.ToString() + ")");
|
||||
return new macro(Convert.ToInt16(macroID));
|
||||
return macro.GetMacro(Convert.ToInt16(macroID));
|
||||
}
|
||||
|
||||
private String FindAttribute(Hashtable attributes, String key)
|
||||
|
||||
@@ -341,9 +341,7 @@
|
||||
<Compile Include="library.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="macro.cs">
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
</Compile>
|
||||
<Compile Include="macro.cs" />
|
||||
<Compile Include="page.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
|
||||
@@ -56,15 +56,8 @@ namespace umbraco
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
// Release cache
|
||||
System.Web.Caching.Cache macroCache = System.Web.HttpRuntime.Cache;
|
||||
if (macroCache["umbMacro" + ParentID.ToString()] != null)
|
||||
{
|
||||
macroCache.Remove("umbMacro" + ParentID.ToString());
|
||||
}
|
||||
|
||||
// Clear cache!
|
||||
macro.ClearAliasCache();
|
||||
macro.GetMacro(ParentID).removeFromCache();
|
||||
new cms.businesslogic.macro.Macro(ParentID).Delete();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ namespace umbraco.cms.presentation.developer
|
||||
new Guid("7B1E683C-5F34-43dd-803D-9699EA1E98CA"),
|
||||
macroID);
|
||||
else
|
||||
new macro(macroID).removeFromCache();
|
||||
macro.GetMacro(macroID).removeFromCache();
|
||||
|
||||
// Check for assemblyBrowser
|
||||
if (tempMacroType.IndexOf(".ascx") > 0)
|
||||
|
||||
@@ -436,7 +436,7 @@ namespace umbraco.presentation.developer.packages
|
||||
if (s != null && !String.IsNullOrEmpty(s.Name))
|
||||
{
|
||||
// remove from cache
|
||||
new runtimeMacro(s.Id).removeFromCache();
|
||||
runtimeMacro.GetMacro(s.Id).removeFromCache();
|
||||
s.Delete();
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace umbraco.presentation
|
||||
|
||||
|
||||
page p = new page(pageID, pageVersion);
|
||||
macro m = new macro(macroID);
|
||||
macro m = macro.GetMacro(macroID);
|
||||
|
||||
Control c = m.renderMacro(attributes, p.Elements, p.PageID);
|
||||
PlaceHolder1.Controls.Add(c);
|
||||
|
||||
@@ -182,7 +182,7 @@ namespace umbraco.presentation.tinymce3
|
||||
Hashtable attributes = new Hashtable();
|
||||
attributes.Add("macroAlias", m.Alias);
|
||||
|
||||
macro mRender = new macro(m.Id);
|
||||
macro mRender = macro.GetMacro(m.Id);
|
||||
foreach (Control c in _dataFields)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -146,22 +146,22 @@ namespace umbraco.presentation.templateControls
|
||||
|
||||
if ((!String.IsNullOrEmpty(Language) && Text != "") || !string.IsNullOrEmpty(FileLocation)) {
|
||||
var tempMacro = new macro();
|
||||
var model = tempMacro.ConvertToMacroModel(MacroAttributes);
|
||||
tempMacro.GenerateMacroModelPropertiesFromAttributes(MacroAttributes);
|
||||
if (string.IsNullOrEmpty(FileLocation)) {
|
||||
model.ScriptCode = Text;
|
||||
model.ScriptLanguage = Language;
|
||||
tempMacro.Model.ScriptCode = Text;
|
||||
tempMacro.Model.ScriptLanguage = Language;
|
||||
} else {
|
||||
model.ScriptName = FileLocation;
|
||||
tempMacro.Model.ScriptName = FileLocation;
|
||||
}
|
||||
model.MacroType = MacroTypes.Script;
|
||||
tempMacro.Model.MacroType = MacroTypes.Script;
|
||||
if (!String.IsNullOrEmpty(Attributes["Cache"])) {
|
||||
var cacheDuration = 0;
|
||||
if (int.TryParse(Attributes["Cache"], out cacheDuration))
|
||||
model.CacheDuration = cacheDuration;
|
||||
tempMacro.Model.CacheDuration = cacheDuration;
|
||||
else
|
||||
System.Web.HttpContext.Current.Trace.Warn("Template", "Cache attribute is in incorect format (should be an integer).");
|
||||
}
|
||||
var c = tempMacro.renderMacro(model, (Hashtable)Context.Items["pageElements"], pageId);
|
||||
var c = tempMacro.renderMacro((Hashtable)Context.Items["pageElements"], pageId);
|
||||
if (c != null)
|
||||
{
|
||||
Exceptions = tempMacro.Exceptions;
|
||||
@@ -172,7 +172,7 @@ namespace umbraco.presentation.templateControls
|
||||
System.Web.HttpContext.Current.Trace.Warn("Template", "Result of inline macro scripting is null");
|
||||
|
||||
} else {
|
||||
var tempMacro = macro.ReturnFromAlias(Alias);
|
||||
var tempMacro = macro.GetMacro(Alias);
|
||||
if (tempMacro != null) {
|
||||
try {
|
||||
var c = tempMacro.renderMacro(MacroAttributes, (Hashtable)Context.Items["pageElements"], pageId);
|
||||
|
||||
Reference in New Issue
Block a user