Exemple #1
0
        public Control loadMacroXSLT(uWebshopMacro macro, MacroModel model, Hashtable pageElements)
        {
            if (XsltFile.Trim() != string.Empty)
            {
                // Get main XML
                XmlDocument umbracoXML = content.Instance.XmlContent;

                // Create XML document for Macro
                var 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)
                {
                    return(new LiteralControl("<div style=\"border: 2px solid green; padding: 5px;\"><b>Debug from " + macro.Name + "</b><br/><p>" + HttpContext.Current.Server.HtmlEncode(macroXML.OuterXml) + "</p></div>"));
                }
                try
                {
                    XslCompiledTransform xsltFile = umbraco.macro.getXslt(XsltFile);

                    try
                    {
                        Control result = CreateControlsFromText(umbraco.macro.GetXsltTransformResult(macroXML, xsltFile));

                        TraceInfo("umbracoMacro", "After performing transformation");

                        return(result);
                    }
                    catch (Exception e)
                    {
                        Exceptions.Add(e);
                        // inner exception code by Daniel Lindstr?m from SBBS.se
                        Exception ie = e;
                        while (ie != null)
                        {
                            TraceWarn("umbracoMacro InnerException", ie.Message, ie);
                            ie = ie.InnerException;
                        }
                        return(new LiteralControl("Error parsing XSLT file: \\xslt\\" + XsltFile));
                    }
                }
                catch (Exception e)
                {
                    Exceptions.Add(e);
                    return(new LiteralControl("Error reading XSLT file: \\xslt\\" + XsltFile));
                }
            }
            TraceWarn("macro", "Xslt is empty");
            return(new LiteralControl(string.Empty));
        }
		public static Control GetMacroControl(string aliasOrPath, int documentId, params object[] properties)
		{
			//converting object[] into a single hash table merging common property names,
			//overwriting previously inserted values.

			//stupid macro propertiespropertyAliases are not case sensative !!!
			var attribs = new Hashtable();
			if (properties != null)
			{
				foreach (var prop in properties)
				{
					var dic = prop as IDictionary ?? prop.ToDictionary();

					foreach (var d in dic.Keys)
					{
						var key = d.ToString().ToLower();
						if (attribs.ContainsKey(key))
							attribs[key] = dic[d];
						else
							attribs.Add(key, dic[d]);
					}
				}
			}


			uWebshopMacro macro;
			
			//fit is starts with ~/ then we assume we are trying to render a file and not an aliased macro
			if (aliasOrPath.StartsWith("~/"))
			{
				//this code is adapted from the macro user control
				macro = new uWebshopMacro();
				macro.GenerateMacroModelPropertiesFromAttributes(attribs);
				macro.Model.ScriptName = aliasOrPath;
				macro.Model.MacroType = MacroTypes.Script;
			}
			else
			{
				macro = uWebshopMacro.GetMacro(aliasOrPath);
			}

			if (macro.Model.ScriptName == null)
			{
				macro = new uWebshopMacro();
				macro.GenerateMacroModelPropertiesFromAttributes(attribs);
				macro.Model.ScriptName = aliasOrPath;
				macro.Model.MacroType = MacroTypes.Script;
			}
			
			macro.UpdateMacroModel(attribs);
			
			var result = macro.RenderMacro(attribs, documentId);

			var exceptions = macro.Exceptions;

			if (exceptions.Any())
			{
				Log.Instance.LogError("GetMacroControl Error in Razor: " + aliasOrPath + " Exception: " + exceptions.First().StackTrace);
				throw new Exception(exceptions.First().StackTrace);
			}

			var keyValueDictionary = new Dictionary<string, string>();

			foreach (var key in HttpContext.Current.Request.Form.AllKeys)
			{
				if (key != null && !key.StartsWith("ctl00$") && !key.StartsWith("body_TabView") && !key.StartsWith("__EVENT") && !key.StartsWith("__VIEWSTATE") && !key.StartsWith("__ASYNCPOST"))
				{
					var value = HttpContext.Current.Request.Form[key];

					if (value != null) keyValueDictionary.Add(key, value);

					
				}
			}

			if (HttpContext.Current.Session != null)
			{
				HttpContext.Current.Session.Add("RazorFields", keyValueDictionary);
			}


			return result;
		}
		public Control loadMacroXSLT(uWebshopMacro macro, MacroModel model, Hashtable pageElements)
		{
			if (XsltFile.Trim() != string.Empty)
			{
				// Get main XML
				XmlDocument umbracoXML = content.Instance.XmlContent;

				// Create XML document for Macro
				var 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)
				{
					return new LiteralControl("<div style=\"border: 2px solid green; padding: 5px;\"><b>Debug from " + macro.Name + "</b><br/><p>" + HttpContext.Current.Server.HtmlEncode(macroXML.OuterXml) + "</p></div>");
				}
				try
				{
					XslCompiledTransform xsltFile = umbraco.macro.getXslt(XsltFile);

					try
					{
						Control result = CreateControlsFromText(umbraco.macro.GetXsltTransformResult(macroXML, xsltFile));

						TraceInfo("umbracoMacro", "After performing transformation");

						return result;
					}
					catch (Exception e)
					{
						Exceptions.Add(e);
						// inner exception code by Daniel Lindstr?m from SBBS.se
						Exception ie = e;
						while (ie != null)
						{
							TraceWarn("umbracoMacro InnerException", ie.Message, ie);
							ie = ie.InnerException;
						}
						return new LiteralControl("Error parsing XSLT file: \\xslt\\" + XsltFile);
					}
				}
				catch (Exception e)
				{
					Exceptions.Add(e);
					return new LiteralControl("Error reading XSLT file: \\xslt\\" + XsltFile);
				}
			}
			TraceWarn("macro", "Xslt is empty");
			return new LiteralControl(string.Empty);
		}
Exemple #4
0
        public static Control GetMacroControl(string aliasOrPath, int documentId, params object[] properties)
        {
            //converting object[] into a single hash table merging common property names,
            //overwriting previously inserted values.

            //stupid macro propertiespropertyAliases are not case sensative !!!
            var attribs = new Hashtable();

            if (properties != null)
            {
                foreach (var prop in properties)
                {
                    var dic = prop as IDictionary ?? prop.ToDictionary();

                    foreach (var d in dic.Keys)
                    {
                        var key = d.ToString().ToLower();
                        if (attribs.ContainsKey(key))
                        {
                            attribs[key] = dic[d];
                        }
                        else
                        {
                            attribs.Add(key, dic[d]);
                        }
                    }
                }
            }


            uWebshopMacro macro;

            //fit is starts with ~/ then we assume we are trying to render a file and not an aliased macro
            if (aliasOrPath.StartsWith("~/"))
            {
                //this code is adapted from the macro user control
                macro = new uWebshopMacro();
                macro.GenerateMacroModelPropertiesFromAttributes(attribs);
                macro.Model.ScriptName = aliasOrPath;
                macro.Model.MacroType  = MacroTypes.Script;
            }
            else
            {
                macro = uWebshopMacro.GetMacro(aliasOrPath);
            }

            if (macro.Model.ScriptName == null)
            {
                macro = new uWebshopMacro();
                macro.GenerateMacroModelPropertiesFromAttributes(attribs);
                macro.Model.ScriptName = aliasOrPath;
                macro.Model.MacroType  = MacroTypes.Script;
            }

            macro.UpdateMacroModel(attribs);

            var result = macro.RenderMacro(attribs, documentId);

            var exceptions = macro.Exceptions;

            if (exceptions.Any())
            {
                Log.Instance.LogError("GetMacroControl Error in Razor: " + aliasOrPath + " Exception: " + exceptions.First().StackTrace);
                throw new Exception(exceptions.First().StackTrace);
            }

            var keyValueDictionary = new Dictionary <string, string>();

            foreach (var key in HttpContext.Current.Request.Form.AllKeys)
            {
                if (key != null && !key.StartsWith("ctl00$") && !key.StartsWith("body_TabView") && !key.StartsWith("__EVENT") && !key.StartsWith("__VIEWSTATE") && !key.StartsWith("__ASYNCPOST"))
                {
                    var value = HttpContext.Current.Request.Form[key];

                    if (value != null)
                    {
                        keyValueDictionary.Add(key, value);
                    }
                }
            }

            if (HttpContext.Current.Session != null)
            {
                HttpContext.Current.Session.Add("RazorFields", keyValueDictionary);
            }


            return(result);
        }