@@ -1241,7 +1149,7 @@ namespace umbraco
if (!File.Exists(IOHelper.MapPath(userControlPath)))
return new LiteralControl(string.Format("UserControl {0} does not exist.", fileName));
- var oControl = (UserControl)new UserControl().LoadControl(userControlPath);
+ var oControl = (UserControl) new UserControl().LoadControl(userControlPath);
int slashIndex = fileName.LastIndexOf("/") + 1;
if (slashIndex < 0)
@@ -1264,80 +1172,13 @@ namespace umbraco
}
AddCurrentNodeToControl(oControl, type);
-
- foreach (string propertyAlias in properties.Keys)
- {
- PropertyInfo prop = type.GetProperty(propertyAlias);
- if (prop == null)
- {
- TraceWarn(loadUserControlKey, "Unable to retrieve type from propertyAlias: " + propertyAlias);
- continue;
- }
-
- MacroPropertyModel propModel = model.Properties.Find(m => m.Key == propertyAlias.ToLower());
- // zb-00037 #29875 : values have already been parsed + no need to parse ""
- object propValue = propModel != null && prop != null ? propModel.Value : null;
-
- if (propValue == null)
- continue;
-
- // Special case for types of webControls.unit
- try
- {
- if (prop.PropertyType == typeof(Unit))
- propValue = Unit.Parse(propValue.ToString());
- else
- {
- try
- {
- object o = propertyDefinitions[propertyAlias];
- if (o == null)
- continue;
- var st = (TypeCode)Enum.Parse(typeof(TypeCode), o.ToString(), true);
-
- // Special case for booleans
- if (prop.PropertyType == typeof(bool))
- {
- bool parseResult;
- if (
- Boolean.TryParse(
- propValue.ToString().Replace("1", "true").Replace("0", "false"),
- out parseResult))
- propValue = parseResult;
- else
- propValue = false;
- }
- else
- propValue = Convert.ChangeType(propValue, st);
-
- Trace.Write("macro.loadControlProperties",
- string.Format("Property added '{0}' with value '{1}'", propertyAlias,
- propValue));
- }
- catch (Exception PropException)
- {
- HttpContext.Current.Trace.Warn("macro.loadControlProperties",
- string.Format(
- "Error adding property '{0}' with value '{1}'",
- propertyAlias, propValue), PropException);
- }
- }
-
- prop.SetValue(oControl, Convert.ChangeType(propValue, prop.PropertyType), null);
- }
- catch (Exception propException)
- {
- HttpContext.Current.Trace.Warn("macro.loadControlProperties",
- string.Format(
- "Error adding property '{0}' with value '{1}', maybe it doesn't exists or maybe casing is wrong!",
- propertyAlias, propValue), propException);
- }
- }
+ updateControlProperties(type, oControl, model);
return oControl;
}
catch (Exception e)
{
- HttpContext.Current.Trace.Warn("macro", string.Format("Error creating usercontrol ({0})", fileName), e);
+ UmbracoContext.Current.Trace.Warn("macro", string.Format("Error creating usercontrol ({0})", fileName),
+ e);
return new LiteralControl(
string.Format(
"Error creating control ({0}).
Maybe file doesn't exists or the usercontrol has a cache directive, which is not allowed! See the tracestack for more information!
",
@@ -1347,13 +1188,15 @@ namespace umbraco
private static void AddCurrentNodeToControl(Control control, Type type)
{
- var currentNodeProperty = type.GetProperty("CurrentNode");
- if (currentNodeProperty != null && currentNodeProperty.CanWrite && currentNodeProperty.PropertyType.IsAssignableFrom(typeof(Node)))
+ PropertyInfo currentNodeProperty = type.GetProperty("CurrentNode");
+ if (currentNodeProperty != null && currentNodeProperty.CanWrite &&
+ currentNodeProperty.PropertyType.IsAssignableFrom(typeof (Node)))
{
currentNodeProperty.SetValue(control, Node.GetCurrent(), null);
}
currentNodeProperty = type.GetProperty("currentNode");
- if (currentNodeProperty != null && currentNodeProperty.CanWrite && currentNodeProperty.PropertyType.IsAssignableFrom(typeof(Node)))
+ if (currentNodeProperty != null && currentNodeProperty.CanWrite &&
+ currentNodeProperty.PropertyType.IsAssignableFrom(typeof (Node)))
{
currentNodeProperty.SetValue(control, Node.GetCurrent(), null);
}
@@ -1362,30 +1205,13 @@ namespace umbraco
private void TraceInfo(string category, string message)
{
if (HttpContext.Current != null)
- HttpContext.Current.Trace.Write(category, message);
+ UmbracoContext.Current.Trace.Write(category, message);
}
private void TraceWarn(string category, string message)
{
if (HttpContext.Current != null)
- HttpContext.Current.Trace.Warn(category, message);
- }
-
- ///
- /// For debug purposes only - should be deleted or made private
- ///
- /// The type of object (control) to show properties from
- public void macroProperties(Type type)
- {
- PropertyInfo[] myProperties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
- HttpContext.Current.Response.Write("" + type.Name + "
");
- foreach (PropertyInfo propertyItem in myProperties)
- {
- // if (propertyItem.CanWrite)
- HttpContext.Current.Response.Write(propertyItem.Name + " (" + propertyItem.PropertyType +
- ")
");
- }
- HttpContext.Current.Response.Write("
");
+ UmbracoContext.Current.Trace.Warn(category, message);
}
public static string renderMacroStartTag(Hashtable attributes, int pageId, Guid versionId)
@@ -1430,7 +1256,7 @@ namespace umbraco
public static string GetRenderedMacro(int MacroId, page umbPage, Hashtable attributes, int pageId)
{
- var m = new macro(MacroId);
+ macro m = GetMacro(MacroId);
Control c = m.renderMacro(attributes, umbPage.Elements, pageId);
TextWriter writer = new StringWriter();
var ht = new HtmlTextWriter(writer);
@@ -1452,7 +1278,7 @@ namespace umbraco
string tempAlias = (attributes["macroalias"] != null)
? attributes["macroalias"].ToString()
: attributes["macroAlias"].ToString();
- macro currentMacro = ReturnFromAlias(tempAlias);
+ macro currentMacro = GetMacro(tempAlias);
if (!currentMacro.DontRenderInEditor)
{
string querystring = "umbPageId=" + PageID + "&umbVersionId=" + PageVersion;
@@ -1463,9 +1289,12 @@ namespace umbraco
// Create a new 'HttpWebRequest' Object to the mentioned URL.
string retVal = string.Empty;
string protocol = GlobalSettings.UseSSL ? "https" : "http";
- string url = string.Format("{0}://{1}:{2}{3}/macroResultWrapper.aspx?{4}", protocol, HttpContext.Current.Request.ServerVariables["SERVER_NAME"], HttpContext.Current.Request.ServerVariables["SERVER_PORT"], IOHelper.ResolveUrl(SystemDirectories.Umbraco), querystring);
+ string url = string.Format("{0}://{1}:{2}{3}/macroResultWrapper.aspx?{4}", protocol,
+ HttpContext.Current.Request.ServerVariables["SERVER_NAME"],
+ HttpContext.Current.Request.ServerVariables["SERVER_PORT"],
+ IOHelper.ResolveUrl(SystemDirectories.Umbraco), querystring);
- var myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
+ var myHttpWebRequest = (HttpWebRequest) WebRequest.Create(url);
// allows for validation of SSL conversations (to bypass SSL errors in debug mode!)
ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
@@ -1482,7 +1311,7 @@ namespace umbraco
HttpWebResponse myHttpWebResponse = null;
try
{
- myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
+ myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();
if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
{
Stream streamResponse = myHttpWebResponse.GetResponseStream();
@@ -1531,15 +1360,16 @@ namespace umbraco
private static string showNoMacroContent(macro currentMacro)
{
- return "" + currentMacro.Name + "
No macro content available for WYSIWYG editing";
+ return "" + currentMacro.Name +
+ "
No macro content available for WYSIWYG editing";
}
private static bool ValidateRemoteCertificate(
-object sender,
- X509Certificate certificate,
- X509Chain chain,
- SslPolicyErrors policyErrors
-)
+ object sender,
+ X509Certificate certificate,
+ X509Chain chain,
+ SslPolicyErrors policyErrors
+ )
{
if (GlobalSettings.DebugMode)
{
@@ -1574,29 +1404,9 @@ object sender,
xslt = xslt.Replace("{1}", namespaceList.ToString());
return xslt;
}
-
- #region Macro Init refactor
-
- // add some caching object here
-
- public macro GetMacro(string Alias)
- {
-
- // load it via API
- Macro m = Macro.GetByAlias(Alias);
-
- return convertAPIMacroToLegacyRuntimeFormat(m);
- }
-
- private macro convertAPIMacroToLegacyRuntimeFormat(Macro m)
- {
- throw new NotImplementedException("not implemented");
- }
-
- #endregion
-
}
+
public class MacroCacheContent
{
private readonly Control _control;
@@ -1643,7 +1453,6 @@ object sender,
public void RefreshAll()
{
- macro.ClearAliasCache();
}
public void Refresh(Guid Id)
@@ -1653,12 +1462,12 @@ object sender,
void ICacheRefresher.Refresh(int Id)
{
- new macro(Id).removeFromCache();
+ macro.GetMacro(Id).removeFromCache();
}
void ICacheRefresher.Remove(int Id)
{
- new macro(Id).removeFromCache();
+ macro.GetMacro(Id).removeFromCache();
}
#endregion
@@ -1694,18 +1503,17 @@ object sender,
public class DLRMacroResult
{
- public Control Control { get; set; }
- public Exception ResultException { get; set; }
-
public DLRMacroResult()
{
-
}
public DLRMacroResult(Control control, Exception resultException)
{
- this.Control = control;
- this.ResultException = resultException;
+ Control = control;
+ ResultException = resultException;
}
+
+ public Control Control { get; set; }
+ public Exception ResultException { get; set; }
}
}
\ No newline at end of file
diff --git a/umbraco/presentation/template.cs b/umbraco/presentation/template.cs
index 43fd7ffb10..0c29825669 100644
--- a/umbraco/presentation/template.cs
+++ b/umbraco/presentation/template.cs
@@ -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)
diff --git a/umbraco/presentation/umbraco.presentation.csproj b/umbraco/presentation/umbraco.presentation.csproj
index d3d2a59a04..724e44321e 100644
--- a/umbraco/presentation/umbraco.presentation.csproj
+++ b/umbraco/presentation/umbraco.presentation.csproj
@@ -341,9 +341,7 @@
Code
-
- ASPXCodeBehind
-
+
Code
diff --git a/umbraco/presentation/umbraco/create/macroTasks.cs b/umbraco/presentation/umbraco/create/macroTasks.cs
index 17e1fcc197..f5786b42cd 100644
--- a/umbraco/presentation/umbraco/create/macroTasks.cs
+++ b/umbraco/presentation/umbraco/create/macroTasks.cs
@@ -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;
}
diff --git a/umbraco/presentation/umbraco/developer/Macros/editMacro.aspx.cs b/umbraco/presentation/umbraco/developer/Macros/editMacro.aspx.cs
index 41e3bd9f50..11bc90ff4d 100644
--- a/umbraco/presentation/umbraco/developer/Macros/editMacro.aspx.cs
+++ b/umbraco/presentation/umbraco/developer/Macros/editMacro.aspx.cs
@@ -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)
diff --git a/umbraco/presentation/umbraco/developer/Packages/installedPackage.aspx.cs b/umbraco/presentation/umbraco/developer/Packages/installedPackage.aspx.cs
index e47dddc093..9b782673c3 100644
--- a/umbraco/presentation/umbraco/developer/Packages/installedPackage.aspx.cs
+++ b/umbraco/presentation/umbraco/developer/Packages/installedPackage.aspx.cs
@@ -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();
}
diff --git a/umbraco/presentation/umbraco/macroResultWrapper.aspx.cs b/umbraco/presentation/umbraco/macroResultWrapper.aspx.cs
index 46ed47a6ea..4c9d13fb3b 100644
--- a/umbraco/presentation/umbraco/macroResultWrapper.aspx.cs
+++ b/umbraco/presentation/umbraco/macroResultWrapper.aspx.cs
@@ -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);
diff --git a/umbraco/presentation/umbraco/plugins/tinymce3/insertMacro.aspx.cs b/umbraco/presentation/umbraco/plugins/tinymce3/insertMacro.aspx.cs
index 85a6d33368..7d7fefc4d9 100644
--- a/umbraco/presentation/umbraco/plugins/tinymce3/insertMacro.aspx.cs
+++ b/umbraco/presentation/umbraco/plugins/tinymce3/insertMacro.aspx.cs
@@ -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
diff --git a/umbraco/presentation/umbraco/templateControls/Macro.cs b/umbraco/presentation/umbraco/templateControls/Macro.cs
index 584a91dc93..c3e24292b8 100644
--- a/umbraco/presentation/umbraco/templateControls/Macro.cs
+++ b/umbraco/presentation/umbraco/templateControls/Macro.cs
@@ -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);