Exemple #1
0
        /// <summary>
        /// Write the parameter set
        /// </summary>
        /// <param name="subSet">The parameter subset</param>
        /// <param name="strings">List of strings</param>
        /// <param name="elem">XML element name</param>
        /// <param name="indent">The XML indentation</param>
        private void WriteParamSet(ParameterSet subSet, List <string> strings, string elem, int indent)
        {
            string lineStr;
            int    idx;

            if (!subSet.NodeIsRoot())
            {
                strings.Add(string.Empty);
            }

            lineStr = new string(' ', indent) + "<" + elem + " name=\"" + subSet.EnglishName + "\"";
            if (subSet.NodeIsRoot())
            {
                lineStr += " version=\"" + subSet.Version + "\">";
            }
            else
            {
                if (subSet.LocaleCount() > 0)
                {
                    lineStr += " locales=\"" + subSet.GetLocale(0);
                    for (idx = 1; idx <= subSet.LocaleCount() - 1; idx++)
                    {
                        lineStr += ";" + subSet.GetLocale(idx);
                    }
                    lineStr += "\"";
                }
                lineStr += ">";
            }
            strings.Add(lineStr);

            if (subSet.TranslationCount() > 0)
            {
                for (idx = 0; idx <= subSet.TranslationCount() - 1; idx++)
                {
                    lineStr = new string(' ', indent + 2) + "<translate lang=\"" +
                              subSet.GetTranslation(idx).Lang + "\">" +
                              EscapeText(subSet.GetTranslation(idx).Text) + "</translate>";
                    strings.Add(lineStr);
                }
            }

            for (idx = 0; idx <= subSet.DefinitionCount() - 1; idx++)
            {
                this.WriteParameters(subSet, subSet.GetDefinition(idx), strings, indent + 2);
            }
            for (idx = 0; idx <= subSet.ChildCount() - 1; idx++)
            {
                this.WriteParamSet(subSet.GetChild(idx), strings, "set", indent + 2);
            }

            lineStr = new string(' ', indent) + "</" + elem + ">";
            if (!subSet.NodeIsRoot() && (subSet.ChildCount() > 0))
            {
                lineStr += "<!-- " + subSet.EnglishName + " -->";
            }

            strings.Add(lineStr);
        }
Exemple #2
0
        /// <summary>
        /// Parses a &lt;parameters&gt; or &lt;set&gt; element in an XML parameter document
        /// </summary>
        /// <param name="Parser"></param>
        /// <param name="aNode"></param>
        /// <param name="Params"></param>
        /// <param name="bModify"></param>
        private void readParamNode(XMLParser Parser, XmlNode aNode, ref ParameterSet Params, bool bModify)
        {
            XmlNode      childNode;
            ParameterSet newParams;
            string       sTag,
                         sValues,
                         sChildName,
                         sLang,
                         sDummy;

            try
            {
                Params.sName        = Parser.getAttrValue(aNode, "name");                 // Name and version information. The
                Params.sEnglishName = Params.sName;
                if (Params.NodeIsRoot())                                                  //   version is passed to child sets
                {
                    Params.sVersion = Parser.getAttrValue(aNode, "version");              //   during creation
                }
                childNode = Parser.firstElementChild(aNode, "translate");                 // See if tbere's a translation of the name matching our current language setting
                while (childNode != null)
                {
                    sLang  = Parser.getAttrValue(childNode, "lang");
                    sDummy = Parser.getText(childNode);
                    Params.addTranslation(sLang, sDummy);
                    childNode = Parser.nextElementSibling(childNode, "translate");
                }

                if (!bModify)                                                           // If we are not modifying an existing
                {
                    while (Params.ChildCount() > 0)                                     //   parameter set, then clear any old
                    {
                        Params.DeleteChild(Params.ChildCount() - 1);                    //   child parameter sets
                    }
                }
                sValues = Parser.getAttrValue(aNode, "locales").Trim();                     // Populate the locale list
                Params.SetLocaleText(sValues);

                childNode = Parser.firstElementChild(aNode, "par");                       // Parse the <par> elements
                while (childNode != null)
                {
                    sTag    = Parser.getAttrValue(childNode, "name");
                    sValues = Parser.getText(childNode);
                    readParamValues(ref Params, sTag, sValues, bModify);
                    childNode = Parser.nextElementSibling(childNode, "par");
                }
                Params.deriveParams();

                childNode = Parser.firstElementChild(aNode, "set");                       // Create child parameter sets from the
                while (childNode != null)                                                 //   <set> elements
                {
                    if (!bModify)
                    {
                        newParams = Params.AddChild();
                    }
                    else
                    {                                                                      // If we are modifying an existing
                        sChildName = Parser.getAttrValue(childNode, "name");               //  parameter set, then locate the child
                        newParams  = Params.GetChild(sChildName);                          //   set that we are about to parse
                        if (newParams == null)
                        {
                            newParams = Params.AddChild();
                        }
                    }
                    readParamNode(Parser, childNode, ref newParams, bModify);
                    childNode = Parser.nextElementSibling(childNode, "set");
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="subSet"></param>
        /// <param name="Strings"></param>
        /// <param name="sElem"></param>
        /// <param name="iIndent"></param>
        private void writeParamSet(ParameterSet subSet,
                                   List <string> Strings,
                                   string sElem,
                                   int iIndent)
        {
            string sLine;
            int    Idx;

            if (!subSet.NodeIsRoot())
            {
                Strings.Add("");
            }

            sLine = new string(' ', iIndent) + "<" + sElem + " name=\"" + subSet.sEnglishName + "\"";
            if (subSet.NodeIsRoot())
            {
                sLine += " version=\"" + subSet.sVersion + "\">";
            }
            else
            {
                if (subSet.iLocaleCount() > 0)
                {
                    sLine += " locales=\"" + subSet.getLocale(0);
                    for (Idx = 1; Idx <= subSet.iLocaleCount() - 1; Idx++)
                    {
                        sLine += ";" + subSet.getLocale(Idx);
                    }
                    sLine += "\"";
                }
                sLine += ">";
            }
            Strings.Add(sLine);

            if (subSet.iTranslationCount() > 0)
            {
                for (Idx = 0; Idx <= subSet.iTranslationCount() - 1; Idx++)
                {
                    sLine = new string(' ', iIndent + 2) + "<translate lang=\"" +
                            subSet.getTranslation(Idx).sLang + "\">" +
                            TTypedValue.escapeText(subSet.getTranslation(Idx).sText) + "</translate>";
                    Strings.Add(sLine);
                }
            }

            for (Idx = 0; Idx <= subSet.DefinitionCount() - 1; Idx++)
            {
                writeParameters(subSet, subSet.GetDefinition(Idx), Strings, iIndent + 2);
            }
            for (Idx = 0; Idx <= subSet.ChildCount() - 1; Idx++)
            {
                writeParamSet(subSet.GetChild(Idx), Strings, "set", iIndent + 2);
            }

            sLine = new string(' ', iIndent) + "</" + sElem + ">";
            if (!subSet.NodeIsRoot() && (subSet.ChildCount() > 0))
            {
                sLine += "<!-- " + subSet.sEnglishName + " -->";
            }

            Strings.Add(sLine);
        }
Exemple #4
0
        /// <summary>
        /// Parses a &lt;parameters&gt; or &lt;set&gt; element in an XML parameter document
        /// </summary>
        /// <param name="parser">The XML parser</param>
        /// <param name="xmlNode">The XML node</param>
        /// <param name="parameters">The parameter set</param>
        /// <param name="modify">Do modify</param>
        private void ReadParamNode(XMLParser parser, XmlNode xmlNode, ref ParameterSet parameters, bool modify)
        {
            XmlNode      childNode;
            ParameterSet newParams;
            string       tag,
                         values,
                         childName,
                         lang,
                         dummy;

            try
            {
                parameters.Name        = parser.GetAttrValue(xmlNode, "name");              // Name and version information. The version is passed to child sets during creation
                parameters.EnglishName = parameters.Name;
                if (parameters.NodeIsRoot())
                {
                    parameters.Version = parser.GetAttrValue(xmlNode, "version");
                }

                childNode = parser.FirstElementChild(xmlNode, "translate");                 // See if tbere's a translation of the name matching our current language setting
                while (childNode != null)
                {
                    lang  = parser.GetAttrValue(childNode, "lang");
                    dummy = parser.GetText(childNode);
                    parameters.AddTranslation(lang, dummy);
                    childNode = parser.NextElementSibling(childNode, "translate");
                }

                if (!modify)
                {
                    // If we are not modifying an existing parameter set, then clear any old child parameter sets
                    while (parameters.ChildCount() > 0)
                    {
                        parameters.DeleteChild(parameters.ChildCount() - 1);
                    }
                }

                values = parser.GetAttrValue(xmlNode, "locales").Trim();                   // Populate the locale list
                parameters.SetLocaleText(values);

                childNode = parser.FirstElementChild(xmlNode, "par");                       // Parse the <par> elements
                while (childNode != null)
                {
                    tag    = parser.GetAttrValue(childNode, "name");
                    values = parser.GetText(childNode);
                    this.ReadParamValues(ref parameters, tag, values, modify);
                    childNode = parser.NextElementSibling(childNode, "par");
                }
                parameters.DeriveParams();

                childNode = parser.FirstElementChild(xmlNode, "set");                       // Create child parameter sets from the <set> elements
                while (childNode != null)
                {
                    if (!modify)
                    {
                        newParams = parameters.AddChild();
                    }
                    else
                    {
                        // If we are modifying an existing parameter set, then locate the child set that we are about to parse
                        childName = parser.GetAttrValue(childNode, "name");
                        newParams = parameters.GetChild(childName);
                        if (newParams == null)
                        {
                            newParams = parameters.AddChild();
                        }
                    }
                    this.ReadParamNode(parser, childNode, ref newParams, modify);
                    childNode = parser.NextElementSibling(childNode, "set");
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }