protected override Macros InitializeMacros() { return(MacrosFactory.CreateMacrosInstance(this)); }
public void ProcessTemplate(SharedBasePage page, Entry entry, string templateString, Control contentPlaceHolder, Macros macros) { int lastIndex = 0; MatchCollection matches = templateFinder.Matches(templateString); foreach (Match match in matches) { if (match.Index > lastIndex) { contentPlaceHolder.Controls.Add(new LiteralControl(templateString.Substring(lastIndex, match.Index - lastIndex))); } Group g = match.Groups["macro"]; Capture c = g.Captures[0]; Control ctrl = null; object targetMacroObj = macros; string captureValue = c.Value; //Check for a string like: <%foo("bar", "bar")|assemblyConfigName%> int assemblyNameIndex = captureValue.IndexOf(")|"); if (assemblyNameIndex != -1) //use the default Macros { //The QN minus the )| string macroAssemblyName = captureValue.Substring(assemblyNameIndex + 2); //The method, including the ) captureValue = captureValue.Substring(0, assemblyNameIndex + 1); try { targetMacroObj = MacrosFactory.CreateCustomMacrosInstance(page, entry, macroAssemblyName); } catch (Exception ex) { string ExToString = ex.ToString(); if (ex.InnerException != null) { ExToString += ex.InnerException.ToString(); } page.LoggingService.AddEvent(new EventDataItem(EventCodes.Error, String.Format("Error executing Macro: {0}", ExToString), string.Empty)); } } try { ctrl = InvokeMacro(targetMacroObj, captureValue) as Control; if (ctrl != null) { contentPlaceHolder.Controls.Add(ctrl); } else { page.LoggingService.AddEvent(new EventDataItem(EventCodes.Error, String.Format("Error executing Macro: {0} returned null.", captureValue), string.Empty)); } } catch (Exception ex) { string error = String.Format("Error executing macro: {0}. Make sure it you're calling it in your BlogTemplate with parentheses like 'myMacro()'. Macros with parameter lists and overloads must be called in this way. Exception: {1}", c.Value, ex.ToString()); page.LoggingService.AddEvent(new EventDataItem(EventCodes.Error, error, string.Empty)); } lastIndex = match.Index + match.Length; } if (lastIndex < templateString.Length) { contentPlaceHolder.Controls.Add(new LiteralControl(templateString.Substring(lastIndex, templateString.Length - lastIndex))); } }