Example #1
0
        /// <summary>
        /// Writes all preferences into XML config file stored in "path".
        /// Must be called explicitly in order to save values for the next session.
        /// Overwrites any existing config file with the values in this object.
        /// </summary>
        public void saveConfig()
        {
            XmlDocument  doc = new XmlDocument();
            XmlNode      Root, ApplicationNode, DataNode;
            XmlAttribute Attribute;

            Root = doc.CreateElement("AerionInputConfig");
            doc.AppendChild(Root);

            for (int i = 0; i < m_PreferencesName.Count; i++)
            {
                ApplicationNode = doc.CreateElement(m_PreferencesName[i]);
                Root.AppendChild(ApplicationNode);

                DataNode = doc.CreateElement("Translation");

                Attribute           = doc.CreateAttribute("XScaleFactor");
                Attribute.InnerText = m_XScaleFactor[i].ToString();
                DataNode.Attributes.Append(Attribute);

                Attribute           = doc.CreateAttribute("YScaleFactor");
                Attribute.InnerText = m_YScaleFactor[i].ToString();
                DataNode.Attributes.Append(Attribute);

                Attribute           = doc.CreateAttribute("ZScaleFactor");
                Attribute.InnerText = m_ZScaleFactor[i].ToString();
                DataNode.Attributes.Append(Attribute);

                Attribute           = doc.CreateAttribute("Threshold");
                Attribute.InnerText = m_TranslationThreshold[i].ToString();
                DataNode.Attributes.Append(Attribute);

                Attribute           = doc.CreateAttribute("Function");
                Attribute.InnerText = ((int)m_TranslationFunction[i]).ToString();
                DataNode.Attributes.Append(Attribute);

                ApplicationNode.AppendChild(DataNode);

                DataNode = doc.CreateElement("Rotation");

                Attribute           = doc.CreateAttribute("XScaleFactor");
                Attribute.InnerText = m_XRotScaleFactor[i].ToString();
                DataNode.Attributes.Append(Attribute);

                Attribute           = doc.CreateAttribute("YScaleFactor");
                Attribute.InnerText = m_YRotScaleFactor[i].ToString();
                DataNode.Attributes.Append(Attribute);

                Attribute           = doc.CreateAttribute("ZScaleFactor");
                Attribute.InnerText = m_ZRotScaleFactor[i].ToString();
                DataNode.Attributes.Append(Attribute);

                Attribute           = doc.CreateAttribute("Threshold");
                Attribute.InnerText = m_RotationThreshold[i].ToString();
                DataNode.Attributes.Append(Attribute);

                Attribute           = doc.CreateAttribute("Function");
                Attribute.InnerText = ((int)m_RotationFunction[i]).ToString();
                DataNode.Attributes.Append(Attribute);

                ApplicationNode.AppendChild(DataNode);
            }

            try
            {
                doc.Save(@path);
            }
            catch (Exception e)
            {
                Console.Out.WriteLine("Exception: {0}, {1}, {2}", e.GetType(), e.Message, e.StackTrace);
            }
        }