本文整理汇总了C#中umbraco.cms.businesslogic.macro.MacroModel类的典型用法代码示例。如果您正苦于以下问题:C# MacroModel类的具体用法?C# MacroModel怎么用?C# MacroModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MacroModel类属于umbraco.cms.businesslogic.macro命名空间,在下文中一共展示了MacroModel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Macro_Is_File_Based
public void Macro_Is_File_Based(string macroType, bool expectedResult)
{
var mType = Enum<MacroTypes>.Parse(macroType);
var model = new MacroModel("Test", "test", "", "", "", "", 0, false, false);
model.MacroType = mType; //force the type
Assert.AreEqual(expectedResult, macro.MacroIsFileBased(model));
}
开发者ID:ChrisNikkel,项目名称:Umbraco-CMS,代码行数:7,代码来源:MacroTests.cs
示例2: Execute
public virtual string Execute(MacroModel macro, INode currentPage) {
var fileEnding = macro.ScriptName.Substring(macro.ScriptName.LastIndexOf('.')).Trim('.');
var mse = MacroScriptEngine.LoadEngineByFileExtension(fileEnding);
var vars = new SortedDictionary<string, object> {
{"currentPage", new DynamicNode(currentPage)}
};
foreach (var prop in macro.Properties) {
vars.Add(prop.Key, prop.Value);
}
mse.ScriptVariables = vars;
return mse.ExecuteFile(IOHelper.MapPath(SystemDirectories.MacroScripts + "/" + macro.ScriptName));
}
开发者ID:elrute,项目名称:Triphulcas,代码行数:12,代码来源:DLRScriptingEngine.cs
示例3: SetUserControlProperty
public void SetUserControlProperty(string val, string macroPropName, Type convertTo)
{
var ctrl = new UserControlTest();
var macroModel = new MacroModel("test", "test", "", "~/usercontrols/menu.ascx", "", "", 0, false, false);
macroModel.Properties.Add(new MacroPropertyModel(macroPropName, val));
macro.UpdateControlProperties(ctrl, macroModel);
var ctrlType = ctrl.GetType();
var prop = ctrlType.GetProperty(macroPropName);
var converted = val.TryConvertTo(convertTo);
Assert.IsTrue(converted.Success);
Assert.NotNull(prop);
Assert.AreEqual(converted.Result, prop.GetValue(ctrl));
}
开发者ID:phaniarveti,项目名称:Experiments,代码行数:16,代码来源:MacroTests.cs
示例4: Render
public static string Render(string razorScript = "", string macroScriptFileName = "", int nodeId = 0, IDictionary<string, string> macroParameters = null)
{
var macroEngine = new RazorMacroEngine();
var macro = new MacroModel();
macro.ScriptCode = razorScript;
macro.ScriptLanguage = "cshtml";
macro.ScriptName = macroScriptFileName;
var node = new umbraco.NodeFactory.Node(nodeId);
if(macroParameters != null) {
foreach(var param in macroParameters) {
macro.Properties.Add(new MacroPropertyModel(param.Key, param.Value));
}
}
return macroEngine.Execute(macro, new umbraco.NodeFactory.Node(nodeId));
}
开发者ID:williamchang,项目名称:umbraco-labs,代码行数:18,代码来源:RenderRazor.cs
示例5: InjectContext
public static void InjectContext(WebPage razorWebPage, MacroModel macro, INode currentPage) {
var context = HttpContext.Current;
var contextWrapper = new HttpContextWrapper(context);
//inject http context - for request response
HttpContext.Current.Trace.Write("umbracoMacro", string.Format("Loading Macro Script Context (file: {0})", macro.Name));
razorWebPage.Context = contextWrapper;
HttpContext.Current.Trace.Write("umbracoMacro", string.Format("Done Loading Macro Script Context (file: {0})", macro.Name));
//Inject Macro Model And Parameters
if (razorWebPage is IMacroContext) {
HttpContext.Current.Trace.Write("umbracoMacro", string.Format("Boxing Macro Script MacroContext (file: {0})", macro.Name));
var razorMacro = (IMacroContext)razorWebPage;
HttpContext.Current.Trace.Write("umbracoMacro", string.Format("Done Boxing Macro Script MacroContext (file: {0})", macro.Name));
HttpContext.Current.Trace.Write("umbracoMacro", string.Format("Loading Macro Script Model (file: {0})", macro.Name));
razorMacro.SetMembers(macro, currentPage);
HttpContext.Current.Trace.Write("umbracoMacro", string.Format("Done Loading Macro Script Model (file: {0})", macro.Name));
}
}
开发者ID:phaniarveti,项目名称:Experiments,代码行数:20,代码来源:RazorMacroEngine.cs
示例6: Execute
public string Execute(MacroModel macro, INode currentPage)
{
var fileLocation = string.Empty;
if (!string.IsNullOrEmpty(macro.ScriptName))
{
fileLocation = macro.ScriptName;
}
else if (!string.IsNullOrEmpty(macro.ScriptCode))
{
var code = macro.ScriptCode.Trim();
var md5 = library.md5(code);
var filename = string.Concat("inline-", md5, ".php");
fileLocation = this.CreateTemporaryFile(code, filename, true);
}
if (string.IsNullOrEmpty(fileLocation))
{
return string.Empty;
}
var builder = new StringBuilder();
using (var writer = new StringWriter(builder))
{
var contents = File.ReadAllText(IOHelper.MapPath(fileLocation));
var context = ScriptContext.CurrentContext;
context.Output = writer;
Operators.SetVariable(context, null, "model", PhpSafeType(currentPage));
PhpEval(context, Parse(contents));
}
return builder.ToString();
}
开发者ID:leekelleher,项目名称:umbraco-php-macro-engine,代码行数:38,代码来源:PhpMacroEngine.cs
示例7: CacheMacroAsString
/// <summary>
/// Determine if macro can be cached as string
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
/// <remarks>
/// Scripts and XSLT can be generated as strings, but not controls as page events wouldn't be hit (such as Page_Load, etc)
/// </remarks>
internal static bool CacheMacroAsString(MacroModel model)
{
switch (model.MacroType)
{
case MacroTypes.XSLT:
case MacroTypes.Python:
case MacroTypes.Script:
case MacroTypes.PartialView:
return true;
case MacroTypes.UserControl:
case MacroTypes.CustomControl:
case MacroTypes.Unknown:
default:
return false;
}
}
开发者ID:CarlSargunar,项目名称:Umbraco-CMS,代码行数:24,代码来源:macro.cs
示例8: GetMacroFile
internal static string GetMacroFile(MacroModel model)
{
switch (model.MacroType)
{
case MacroTypes.XSLT:
return string.Concat("~/xslt/", model.Xslt);
case MacroTypes.Python:
case MacroTypes.Script:
return string.Concat("~/macroScripts/", model.ScriptName);
case MacroTypes.PartialView:
return model.ScriptName; //partial views are saved with the full virtual path
case MacroTypes.UserControl:
return model.TypeName; //user controls saved with the full virtual path
case MacroTypes.CustomControl:
case MacroTypes.Unknown:
default:
return "/" + model.TypeName;
}
}
开发者ID:CarlSargunar,项目名称:Umbraco-CMS,代码行数:19,代码来源:macro.cs
示例9: MacroIsFileBased
internal static bool MacroIsFileBased(MacroModel model)
{
return model.MacroType != MacroTypes.CustomControl && model.MacroType != MacroTypes.Unknown;
}
开发者ID:CarlSargunar,项目名称:Umbraco-CMS,代码行数:4,代码来源:macro.cs
示例10: ExecuteRazor
public string ExecuteRazor(MacroModel macro, INode currentPage) {
var context = HttpContext.Current;
var contextWrapper = new HttpContextWrapper(context);
string fileLocation = null;
if (!string.IsNullOrEmpty(macro.ScriptName)) {
//Razor Is Already Contained In A File
if (macro.ScriptName.StartsWith("~"))
fileLocation = macro.ScriptName;
else
fileLocation = SystemDirectories.MacroScripts + "/" + macro.ScriptName;
} else if (!string.IsNullOrEmpty(macro.ScriptCode) && !string.IsNullOrEmpty(macro.ScriptLanguage)) {
//Inline Razor Syntax
fileLocation = CreateInlineRazorFile(macro.ScriptCode, macro.ScriptLanguage);
}
if (string.IsNullOrEmpty(fileLocation))
return String.Empty; //No File Location
var razorWebPage = CompileAndInstantiate(fileLocation);
HttpContext.Current.Trace.Write("umbracoMacro", string.Format("Loading Macro Script Context (file: {0})", macro.Name));
InjectContext(razorWebPage, macro, currentPage);
HttpContext.Current.Trace.Write("umbracoMacro", string.Format("Done Loading Macro Script Context (file: {0})", macro.Name));
//Output Razor To String
var output = new StringWriter();
HttpContext.Current.Trace.Write("umbracoMacro", string.Format("Executing Macro Script (file: {0})", macro.Name));
razorWebPage.ExecutePageHierarchy(new WebPageContext(contextWrapper, razorWebPage, null), output);
HttpContext.Current.Trace.Write("umbracoMacro", string.Format("Done Executing Macro Script (file: {0})", macro.Name));
return output.ToString();
}
开发者ID:phaniarveti,项目名称:Experiments,代码行数:32,代码来源:RazorMacroEngine.cs
示例11: MacroNeedsToBeClearedFromCache
/// <summary>
/// check that the file has not recently changed
/// </summary>
/// <param name="model"></param>
/// <param name="dateAddedKey"></param>
/// <param name="macroFile"></param>
/// <returns></returns>
/// <remarks>
/// The only reason this is necessary is because a developer might update a file associated with the
/// macro, we need to ensure if that is the case that the cache not be used and it is refreshed.
/// </remarks>
internal static bool MacroNeedsToBeClearedFromCache(MacroModel model, string dateAddedKey, FileInfo macroFile)
{
if (MacroIsFileBased(model))
{
var cacheResult = ApplicationContext.Current.ApplicationCache.GetCacheItem<DateTime?>(dateAddedKey);
if (cacheResult != null)
{
var dateMacroAdded = cacheResult;
if (macroFile.LastWriteTime.CompareTo(dateMacroAdded) == 1)
{
TraceInfo("renderMacro", string.Format("Macro needs to be removed from cache due to file change '{0}'.", model.CacheIdentifier));
return true;
}
}
}
return false;
}
开发者ID:CarlSargunar,项目名称:Umbraco-CMS,代码行数:31,代码来源:macro.cs
示例12: PartialViewMacroController
public PartialViewMacroController(UmbracoContext umbracoContext, MacroModel macro, INode currentPage)
{
_umbracoContext = umbracoContext;
_macro = macro;
_currentPage = currentPage;
}
开发者ID:CarlSargunar,项目名称:Umbraco-CMS,代码行数:6,代码来源:PartialViewMacroController.cs
示例13: Get_Macro_File
public void Get_Macro_File(string xslt, string scriptFile, string scriptType, string scriptAssembly, string expectedResult)
{
var model = new MacroModel("Test", "test", scriptAssembly, scriptType, xslt, scriptFile, 0, false, false);
var file = macro.GetMacroFile(model);
Assert.AreEqual(expectedResult, file);
}
开发者ID:ChrisNikkel,项目名称:Umbraco-CMS,代码行数:6,代码来源:MacroTests.cs
示例14: loadControl
/// <summary>
/// Loads a custom or webcontrol using reflection into the macro object
/// </summary>
/// <param name="fileName">The assembly to load from</param>
/// <param name="controlName">Name of the control</param>
/// <returns></returns>
public Control loadControl(string fileName, string controlName, MacroModel model, Hashtable pageElements)
{
Type type;
Assembly asm;
try
{
string currentAss = IOHelper.MapPath(string.Format("{0}/{1}.dll", SystemDirectories.Bin, fileName));
if (!File.Exists(currentAss))
return new LiteralControl("Unable to load user control because is does not exist: " + fileName);
asm = Assembly.LoadFrom(currentAss);
TraceInfo("umbracoMacro", "Assembly file " + currentAss + " LOADED!!");
}
catch
{
throw new ArgumentException(string.Format("ASSEMBLY NOT LOADED PATH: {0} NOT FOUND!!",
IOHelper.MapPath(SystemDirectories.Bin + "/" + fileName +
".dll")));
}
TraceInfo("umbracoMacro", string.Format("Assembly Loaded from ({0}.dll)", fileName));
type = asm.GetType(controlName);
if (type == null)
return new LiteralControl(string.Format("Unable to get type {0} from assembly {1}",
controlName, asm.FullName));
var control = Activator.CreateInstance(type) as Control;
if (control == null)
return new LiteralControl(string.Format("Unable to create control {0} from assembly {1}",
controlName, asm.FullName));
AddCurrentNodeToControl(control, type);
// Properties
UpdateControlProperties(type, control, model);
return control;
}
开发者ID:CarlSargunar,项目名称:Umbraco-CMS,代码行数:44,代码来源:macro.cs
示例15: Can_Cache_As_String
public void Can_Cache_As_String(string macroType, bool expectedResult)
{
var mType = Enum<MacroTypes>.Parse(macroType);
var model = new MacroModel("Test", "test", "", "", "", "", 0, false, false);
model.MacroType = mType; //force the type
Assert.AreEqual(expectedResult, macro.CacheMacroAsString(model));
}
开发者ID:ChrisNikkel,项目名称:Umbraco-CMS,代码行数:7,代码来源:MacroTests.cs
示例16: macro
public macro(string alias)
{
Macro m = Macro.GetByAlias(alias);
Model = new MacroModel(m);
}
开发者ID:CarlSargunar,项目名称:Umbraco-CMS,代码行数:5,代码来源:macro.cs
示例17: loadMacroDLR
public DLRMacroResult loadMacroDLR(MacroModel macro)
{
var retVal = new DLRMacroResult();
var ret = new LiteralControl();
IMacroEngine engine = null;
if (!String.IsNullOrEmpty(macro.ScriptCode))
{
engine = MacroEngineFactory.GetByExtension(macro.ScriptLanguage);
ret.Text = engine.Execute(
macro,
Node.GetCurrent());
}
else
{
string path = IOHelper.MapPath(SystemDirectories.MacroScripts + "/" + macro.ScriptName);
engine = MacroEngineFactory.GetByFilename(path);
ret.Text = engine.Execute(macro, Node.GetCurrent());
}
// if the macro engine supports success reporting and executing failed, then return an empty control so it's not cached
if (engine is IMacroEngineResultStatus)
{
var result = engine as IMacroEngineResultStatus;
if (!result.Success)
{
retVal.ResultException = result.ResultException;
}
}
retVal.Control = ret;
return retVal;
}
开发者ID:CarlSargunar,项目名称:Umbraco-CMS,代码行数:31,代码来源:macro.cs
示例18: LoadPartialViewMacro
/// <summary>
/// Renders a Partial View Macro
/// </summary>
/// <param name="macro"></param>
/// <returns></returns>
internal ScriptingMacroResult LoadPartialViewMacro(MacroModel macro)
{
var retVal = new ScriptingMacroResult();
IMacroEngine engine = null;
engine = MacroEngineFactory.GetEngine(PartialViewMacroEngine.EngineName);
var ret = engine.Execute(macro, Node.GetCurrent());
// if the macro engine supports success reporting and executing failed, then return an empty control so it's not cached
if (engine is IMacroEngineResultStatus)
{
var result = engine as IMacroEngineResultStatus;
if (!result.Success)
{
retVal.ResultException = result.ResultException;
}
}
retVal.Result = ret;
return retVal;
}
开发者ID:CarlSargunar,项目名称:Umbraco-CMS,代码行数:25,代码来源:macro.cs
示例19: LoadMacroXslt
// gets the control for the macro, using GetXsltTransform methods for execution
// will pick XmlDocument or Navigator mode depending on the capabilities of the published caches
internal Control LoadMacroXslt(macro macro, MacroModel model, Hashtable pageElements, bool throwError)
{
if (XsltFile.Trim() == string.Empty)
{
TraceWarn("macro", "Xslt is empty");
return new LiteralControl(string.Empty);
}
using (DisposableTimer.DebugDuration<macro>("Executing XSLT: " + XsltFile))
{
XmlDocument macroXml = null;
// get master xml document
var cache = UmbracoContext.Current.ContentCache.InnerCache as Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedContentCache;
if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported.");
XmlDocument umbracoXml = cache.GetXml(UmbracoContext.Current, UmbracoContext.Current.InPreviewMode);
macroXml = new XmlDocument();
macroXml.LoadXml("<macro/>");
foreach (var prop in macro.Model.Properties)
{
AddMacroXmlNode(umbracoXml, macroXml, prop.Key, prop.Type, prop.Value);
}
if (HttpContext.Current.Request.QueryString["umbDebug"] != null && GlobalSettings.DebugMode)
{
var outerXml = macroXml.OuterXml;
return
new LiteralControl("<div style=\"border: 2px solid green; padding: 5px;\"><b>Debug from " +
macro.Name +
"</b><br/><p>" + HttpContext.Current.Server.HtmlEncode(outerXml) +
"</p></div>");
}
try
{
var xsltFile = getXslt(XsltFile);
using (DisposableTimer.DebugDuration<macro>("Performing transformation"))
{
try
{
var transformed = GetXsltTransformResult(macroXml, xsltFile);
var result = CreateControlsFromText(transformed);
return result;
}
catch (Exception e)
{
Exceptions.Add(e);
LogHelper.WarnWithException<macro>("Error parsing XSLT file", e);
var macroErrorEventArgs = new MacroErrorEventArgs { Name = Model.Name, Alias = Model.Alias, ItemKey = Model.Xslt, Exception = e, Behaviour = UmbracoSettings.MacroErrorBehaviour };
var macroControl = GetControlForErrorBehavior("Error parsing XSLT file: \\xslt\\" + XsltFile, macroErrorEventArgs);
//if it is null, then we are supposed to throw the (original) exception
// see: http://issues.umbraco.org/issue/U4-497 at the end
if (macroControl == null && throwError)
{
throw;
}
return macroControl;
}
}
}
catch (Exception e)
{
Exceptions.Add(e);
LogHelper.WarnWithException<macro>("Error loading XSLT " + Model.Xslt, true, e);
// Invoke any error handlers for this macro
var macroErrorEventArgs = new MacroErrorEventArgs { Name = Model.Name, Alias = Model.Alias, ItemKey = Model.Xslt, Exception = e, Behaviour = UmbracoSettings.MacroErrorBehaviour };
var macroControl = GetControlForErrorBehavior("Error reading XSLT file: \\xslt\\" + XsltFile, macroErrorEventArgs);
//if it is null, then we are supposed to throw the (original) exception
// see: http://issues.umbraco.org/issue/U4-497 at the end
if (macroControl == null && throwError)
{
throw;
}
return macroControl;
}
}
}
开发者ID:CarlSargunar,项目名称:Umbraco-CMS,代码行数:83,代码来源:macro.cs
示例20: loadUserControl
/// <summary>
/// Loads an usercontrol using reflection into the macro object
/// </summary>
/// <param name="fileName">Filename of the usercontrol - ie. ~wulff.ascx</param>
/// <param name="attributes">The attributes.</param>
/// <param name="pageElements">The page elements.</param>
/// <returns></returns>
public Control loadUserControl(string fileName, MacroModel model, Hashtable pageElements)
{
Debug.Assert(!string.IsNullOrEmpty(fileName), "fileName cannot be empty");
Debug.Assert(model.Properties != null, "attributes cannot be null");
Debug.Assert(pageElements != null, "pageElements cannot be null");
try
{
string userControlPath = @"~/" + fileName;
if (!File.Exists(IOHelper.MapPath(userControlPath)))
return new LiteralControl(string.Format("UserControl {0} does not exist.", fileName));
var oControl = (UserControl)new UserControl().LoadControl(userControlPath);
int slashIndex = fileName.LastIndexOf("/") + 1;
if (slashIndex < 0)
slashIndex = 0;
if (!String.IsNullOrEmpty(model.MacroControlIdentifier))
oControl.ID = model.MacroControlIdentifier;
else
oControl.ID =
string.Format("{0}_{1}", fileName.Substring(slashIndex, fileName.IndexOf(".ascx") - slashIndex),
StateHelper.GetContextValue<int>(macrosAddedKey));
TraceInfo(loadUserControlKey, string.Format("Usercontrol added with id '{0}'", oControl.ID));
Type type = oControl.GetType();
if (type == null)
{
TraceWarn(loadUserControlKey, "Unable to retrieve control type: " + fileName);
return oControl;
}
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);
}
}
//.........这里部分代码省略.........
开发者ID:jracabado,项目名称:justEdit-,代码行数:101,代码来源:macro.cs
注:本文中的umbraco.cms.businesslogic.macro.MacroModel类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论