Ejemplo n.º 1
0
		/// <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;
		}
Ejemplo n.º 2
0
        public ScriptingMacroResult loadMacroScript(MacroModel macro)
        {
            var retVal = new ScriptingMacroResult();
            string ret = String.Empty;
            IMacroEngine engine = null;
            if (!String.IsNullOrEmpty(macro.ScriptCode))
            {
                engine = MacroEngineFactory.GetByExtension(macro.ScriptLanguage);
                ret = engine.Execute(
                    macro,
                    Node.GetCurrent());
            }
            else
            {
                string path = IOHelper.MapPath(SystemDirectories.MacroScripts + "/" + macro.ScriptName);
                engine = MacroEngineFactory.GetByFilename(path);
                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;
        }
Ejemplo n.º 3
0
		///// <summary>
		///// Renders a Partial View Macro
		///// </summary>
		///// <param name="macro"></param>
		///// <param name="nodeId"></param>
		///// <returns></returns>
		//internal ScriptingMacroResult LoadPartialViewMacro(MacroModel macro, int nodeId)
		//{
		//	var retVal = new ScriptingMacroResult();
		//	TraceInfo("umbracoMacro", "Rendering Partial View Macro");

		//	var engine = MacroEngineFactory.GetEngine("Partial View Macro Engine");//PartialViewMacroEngine.EngineName);
		//	var ret = engine.Execute(macro, new Node(nodeId));

		//	// 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;
		//		}
		//	}
		//	TraceInfo("umbracoMacro", "Rendering Partial View Macro [done]");
		//	retVal.Result = ret;
		//	return retVal;
		//}

		public ScriptingMacroResult LoadMacroScript(MacroModel macro, int currentPageId)
		{
			Log.Instance.LogDebug("LoadMacroScript macro.Alias: " + macro.Alias);
			Log.Instance.LogDebug("LoadMacroScript macro.ScriptCode: " + macro.ScriptCode);
			Log.Instance.LogDebug("LoadMacroScript macro.ScriptName: " + macro.ScriptName);

			var retVal = new ScriptingMacroResult();
			TraceInfo("umbracoMacro", "Loading IMacroEngine script");
			string ret;
			IMacroEngine engine;
			if (!string.IsNullOrEmpty(macro.ScriptCode))
			{
				Log.Instance.LogDebug("LoadMacroScript engine.ScriptLanguage: " + macro.ScriptLanguage);
				
				engine = MacroEngineFactory.GetByExtension(macro.ScriptLanguage);

				Log.Instance.LogDebug("LoadMacroScript engine.Name: " + engine.Name);

				ret = engine.Execute(macro, new Node(currentPageId));
			}
			else
			{
				var path = macro.ScriptName;

				if (!macro.ScriptName.StartsWith("~"))
				{
					path = SystemDirectories.MacroScripts.TrimEnd('/') + "/" + macro.ScriptName.TrimStart('/');
				}
				
				Log.Instance.LogDebug("LoadMacroScript path: " + path);

				engine = MacroEngineFactory.GetByFilename(path);

				Log.Instance.LogDebug("LoadMacroScript engine.Name: " + engine.Name);

				ret = engine.Execute(macro, new Node(currentPageId));
			}

			// 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;
				}
			}
			TraceInfo("umbracoMacro", "Loading IMacroEngine script [done]");
			retVal.Result = ret;
			return retVal;
		}