Beispiel #1
0
        public static Macro Import(XmlNode n)
        {
            Macro  m     = null;
            string alias = xmlHelper.GetNodeValue(n.SelectSingleNode("alias"));

            try
            {
                //check to see if the macro alreay exists in the system
                //it's better if it does and we keep using it, alias *should* be unique remember
                m = new Macro(alias);
                Macro.GetByAlias(alias);
            }
            catch (IndexOutOfRangeException)
            {
                m = MakeNew(xmlHelper.GetNodeValue(n.SelectSingleNode("name")));
            }

            try
            {
                m.Alias       = alias;
                m.Assembly    = xmlHelper.GetNodeValue(n.SelectSingleNode("scriptAssembly"));
                m.Type        = xmlHelper.GetNodeValue(n.SelectSingleNode("scriptType"));
                m.Xslt        = xmlHelper.GetNodeValue(n.SelectSingleNode("xslt"));
                m.RefreshRate = int.Parse(xmlHelper.GetNodeValue(n.SelectSingleNode("refreshRate")));

                // we need to validate if the usercontrol is missing the tilde prefix requirement introduced in v6
                if (String.IsNullOrEmpty(m.Assembly) && !String.IsNullOrEmpty(m.Type) && !m.Type.StartsWith("~"))
                {
                    m.Type = "~/" + m.Type;
                }

                if (n.SelectSingleNode("scriptingFile") != null)
                {
                    m.ScriptingFile = xmlHelper.GetNodeValue(n.SelectSingleNode("scriptingFile"));
                }

                try
                {
                    m.UseInEditor = bool.Parse(xmlHelper.GetNodeValue(n.SelectSingleNode("useInEditor")));
                }
                catch (Exception macroExp)
                {
                    LogHelper.Error <Macro>("Error creating macro property", macroExp);
                }

                // macro properties
                foreach (XmlNode mp in n.SelectNodes("properties/property"))
                {
                    try
                    {
                        string propertyAlias = mp.Attributes.GetNamedItem("alias").Value;
                        var    property      = m.Properties.SingleOrDefault(p => p.Alias == propertyAlias);
                        if (property != null)
                        {
                            property.Public = bool.Parse(mp.Attributes.GetNamedItem("show").Value);
                            property.Name   = mp.Attributes.GetNamedItem("name").Value;
                            property.Type   = new MacroPropertyType(mp.Attributes.GetNamedItem("propertyType").Value);

                            property.Save();
                        }
                        else
                        {
                            MacroProperty.MakeNew(
                                m,
                                bool.Parse(mp.Attributes.GetNamedItem("show").Value),
                                propertyAlias,
                                mp.Attributes.GetNamedItem("name").Value,
                                new MacroPropertyType(mp.Attributes.GetNamedItem("propertyType").Value)
                                );
                        }
                    }
                    catch (Exception macroPropertyExp)
                    {
                        LogHelper.Error <Macro>("Error creating macro property", macroPropertyExp);
                    }
                }

                m.Save();
            }
            catch { return(null); }

            return(m);
        }
Beispiel #2
0
        public static Macro Import(XmlNode n)
        {
            Macro  m     = null;
            string alias = xmlHelper.GetNodeValue(n.SelectSingleNode("alias"));

            try
            {
                //check to see if the macro alreay exists in the system
                //it's better if it does and we keep using it, alias *should* be unique remember
                m = new Macro(alias);
                Macro.GetByAlias(alias);
            }
            catch (IndexOutOfRangeException)
            {
                m = MakeNew(xmlHelper.GetNodeValue(n.SelectSingleNode("name")));
            }

            try
            {
                m.Alias       = alias;
                m.Assembly    = xmlHelper.GetNodeValue(n.SelectSingleNode("scriptAssembly"));
                m.Type        = xmlHelper.GetNodeValue(n.SelectSingleNode("scriptType"));
                m.Xslt        = xmlHelper.GetNodeValue(n.SelectSingleNode("xslt"));
                m.RefreshRate = int.Parse(xmlHelper.GetNodeValue(n.SelectSingleNode("refreshRate")));

                if (n.SelectSingleNode("scriptingFile") != null)
                {
                    m.ScriptingFile = xmlHelper.GetNodeValue(n.SelectSingleNode("scriptingFile"));
                }

                try
                {
                    m.UseInEditor = bool.Parse(xmlHelper.GetNodeValue(n.SelectSingleNode("useInEditor")));
                }
                catch (Exception macroExp)
                {
                    BusinessLogic.Log.Add(BusinessLogic.LogTypes.Error, BusinessLogic.User.GetUser(0), -1, "Error creating macro property: " + macroExp.ToString());
                }

                // macro properties
                foreach (XmlNode mp in n.SelectNodes("properties/property"))
                {
                    try
                    {
                        string propertyAlias = mp.Attributes.GetNamedItem("alias").Value;
                        var    property      = m.Properties.SingleOrDefault(p => p.Alias == propertyAlias);
                        if (property != null)
                        {
                            property.Public = bool.Parse(mp.Attributes.GetNamedItem("show").Value);
                            property.Name   = mp.Attributes.GetNamedItem("name").Value;
                            property.Type   = new MacroPropertyType(mp.Attributes.GetNamedItem("propertyType").Value);

                            property.Save();
                        }
                        else
                        {
                            MacroProperty.MakeNew(
                                m,
                                bool.Parse(mp.Attributes.GetNamedItem("show").Value),
                                propertyAlias,
                                mp.Attributes.GetNamedItem("name").Value,
                                new MacroPropertyType(mp.Attributes.GetNamedItem("propertyType").Value)
                                );
                        }
                    }
                    catch (Exception macroPropertyExp)
                    {
                        BusinessLogic.Log.Add(BusinessLogic.LogTypes.Error, BusinessLogic.User.GetUser(0), -1, "Error creating macro property: " + macroPropertyExp.ToString());
                    }
                }

                m.Save();
            }
            catch { return(null); }

            return(m);
        }