/// <summary> Returns the XML string to save this panel to the template XML file </summary>
        /// <returns>String for template XML file</returns>
        public string To_Template_XML()
        {
            // Build the results for this panel, and each element in the page
            StringBuilder results = new StringBuilder();

            // Start this panel
            results.Append("\t\t\t<panel>\r\n");

            // Write each of the titles for this panel
            foreach (KeyValuePair <Template_Language, string> thisEntry in allPanelTitles)
            {
                // If this language is known, write it
                if (thisEntry.Key != Template_Language.Unknown)
                {
                    results.Append("\t\t\t\t<name language=\"" + Template_Language_Convertor.ToCode(thisEntry.Key) + "\">" + thisEntry.Value + "</name>\r\n");
                }
            }

            // Now, add the XML for the elements in this panel
            results.Append(elements.To_Template_XML("\t\t\t\t"));

            // End this page
            results.Append("\t\t\t</panel>\r\n");

            // Return the built XML string
            return(results.ToString());
        }
        private void process_inputs(XmlNodeReader nodeReader, Template thisTemplate)
        {
            // Keep track of the current pages and panels
            Template_Page  currentPage  = null;
            Template_Panel currentPanel = null;
            bool           inPanel      = false;

            // Read all the nodes
            while (nodeReader.Read())
            {
                // Get the node name, trimmed and to upper
                string nodeName = nodeReader.Name.Trim().ToUpper();

                // If this is the inputs or constant start tag, return
                if (((nodeReader.NodeType == XmlNodeType.EndElement) && (nodeName == "INPUTS")) ||
                    ((nodeReader.NodeType == XmlNodeType.Element) && (nodeReader.Name == "CONSTANTS")))
                {
                    return;
                }

                // If this is the beginning tag for an element, assign the next values accordingly
                if (nodeReader.NodeType == XmlNodeType.Element)
                {
                    // Does this start a new page?
                    if (nodeName == "PAGE")
                    {
                        // Set the inPanel flag to false
                        inPanel = false;

                        // Create the new page and add to this template
                        currentPage = new Template_Page();
                        thisTemplate.InputPages.Add(currentPage);
                    }

                    // Does this start a new panel?
                    if (nodeName == "PANEL")
                    {
                        // Set the inPanel flag to true
                        inPanel = true;

                        // Create the new panel and add to the current page
                        currentPanel = new Template_Panel();
                        if (currentPage != null)
                        {
                            currentPage.Panels.Add(currentPanel);
                        }
                    }

                    // Is this a name element?
                    if (nodeName == "NAME")
                    {
                        // Determine the language
                        Template_Language language;
                        if (nodeReader.HasAttributes)
                        {
                            nodeReader.MoveToFirstAttribute();
                            language = Template_Language_Convertor.ToEnum(nodeReader.Value);
                        }
                        else
                        {
                            language = DEFAULT_LANGUAGE;
                        }

                        // Get the text
                        string title = read_text_node(nodeReader);

                        // Set the name for either the page or panel
                        if (inPanel)
                        {
                            currentPanel.Set_Title(language, title);
                        }
                        else
                        {
                            if (currentPage != null)
                            {
                                currentPage.Set_Title(language, title);
                            }
                        }
                    }

                    // Is this a new element?
                    if ((nodeName == "ELEMENT") && (nodeReader.HasAttributes))
                    {
                        abstract_Element currentElement = process_element(nodeReader);
                        if ((currentElement != null) && (currentPanel != null))
                        {
                            currentPanel.Elements.Add(currentElement);
                        }
                    }
                }
            }
        }
        private void process_template_header(XmlNodeReader nodeReader, Template thisTemplate)
        {
            // Read all the nodes
            while (nodeReader.Read())
            {
                // Get the node name, trimmed and to upper
                string nodeName = nodeReader.Name.Trim().ToUpper();

                // If this is the inputs or constant start tag, return
                if ((nodeReader.NodeType == XmlNodeType.Element) &&
                    ((nodeName == "INPUTS") || (nodeName == "CONSTANTS")))
                {
                    return;
                }

                // If this is the beginning tag for an element, assign the next values accordingly
                if (nodeReader.NodeType == XmlNodeType.Element)
                {
                    // switch the rest based on the tag name
                    switch (nodeName)
                    {
                    case "NAME":

                        // Determine the language and then add this name
                        if (nodeReader.HasAttributes)
                        {
                            nodeReader.MoveToFirstAttribute();
                            thisTemplate.Set_Title(Template_Language_Convertor.ToEnum(nodeReader.Value), read_text_node(nodeReader));
                        }
                        else
                        {
                            thisTemplate.Set_Title(DEFAULT_LANGUAGE, read_text_node(nodeReader));
                        }
                        break;

                    case "NOTES":
                        thisTemplate.Notes = (thisTemplate.Notes + "  " + read_text_node(nodeReader)).Trim();
                        break;

                    case "DATECREATED":
                        DateTime tempDate;
                        if (DateTime.TryParse(read_text_node(nodeReader), out tempDate))
                        {
                            thisTemplate.DateCreated = tempDate;
                        }
                        break;

                    case "LASTMODIFIED":
                        DateTime tempDate2;
                        if (DateTime.TryParse(read_text_node(nodeReader), out tempDate2))
                        {
                            thisTemplate.LastModified = tempDate2;
                        }
                        break;

                    case "CREATOR":
                        thisTemplate.Creator = read_text_node(nodeReader);
                        break;
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary> Save this template scheme to the Template XML file </summary>
        /// <param name="FileName"> Name of Template XML file </param>
        /// <returns> TRUE if successful, otherwise FALSE </returns>
        public bool Save_Template_XML(string FileName)
        {
            try
            {
                StringBuilder resultBuilder = new StringBuilder();

                // Add header and the start main tag
                resultBuilder.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n");
                resultBuilder.Append("\r\n");
                resultBuilder.Append("<!-- Begin the XML for this input template -->\r\n");
                resultBuilder.Append("<input_template>\r\n");
                resultBuilder.Append("\r\n");

                // Add the administrative information about this template
                resultBuilder.Append("\t<!-- Define the information about this input template -->\r\n");

                // Write each of the titles for this page
                foreach (KeyValuePair <Template_Language, string> thisEntry in allTitles)
                {
                    // If this language is known, write it
                    if (thisEntry.Key != Template_Language.Unknown)
                    {
                        resultBuilder.Append("\t<name language=\"" + Template_Language_Convertor.ToCode(thisEntry.Key) + "\">" + thisEntry.Value + "</name>\r\n");
                    }
                }

                // Finish out the administrative section
                if (Notes.Length > 0)
                {
                    resultBuilder.Append("\t<notes>" + Notes + "</notes>\r\n");
                }
                resultBuilder.Append("\t<dateCreated>" + DateCreated.ToLongDateString() + "</dateCreated>\r\n");
                if (LastModified.CompareTo(DateCreated) > 0)
                {
                    resultBuilder.Append("\t<lastModified>" + LastModified.ToLongDateString() + "</lastModified>\r\n");
                }
                if (Creator.Length > 0)
                {
                    resultBuilder.Append("\t<creator>" + Creator + "</creator>\r\n");
                }
                resultBuilder.Append("\r\n");

                // Write the information which describes all the inputs
                resultBuilder.Append("\t<!-- This defines the inputs which are available for the user -->\r\n");
                resultBuilder.Append("\t<inputs>\r\n");
                resultBuilder.Append(inputs.To_Template_XML());
                resultBuilder.Append("\t</inputs>\r\n");
                resultBuilder.Append("\r\n");

                // Add all the constant information
                resultBuilder.Append("\t<!-- This defines the constants which can not be edited by the user -->\r\n");
                resultBuilder.Append("\t<constants>\r\n");
                resultBuilder.Append(constants.To_Template_XML("\t\t"));
                resultBuilder.Append("\t</constants>\r\n");
                resultBuilder.Append("\r\n");

                // Close the main tag
                resultBuilder.Append("</input_template>\r\n");
                resultBuilder.Append("<!-- End of input template XML -->\r\n");

                // Write this out to a file
                StreamWriter writer = new StreamWriter(FileName, false, Encoding.UTF8);
                writer.Write(resultBuilder.ToString());
                writer.Flush();
                writer.Close();

                // Return true
                return(true);
            }
            catch
            {
                return(false);
            }
        }