Exemplo n.º 1
0
        internal static void WriteInstance(XmlDocument xmlDoc, XmlElement pluginNode)
        {
            if (instance == null)
            {
                //This can occur if a logbook could not be loaded, then ST is closed
                instance = new Settings();
            }
            XmlElement user = xmlDoc.CreateElement("User");
            XmlAttribute username = xmlDoc.CreateAttribute("username");
            username.Value = instance.User.Username;
            user.Attributes.Append(username);
            XmlAttribute password = xmlDoc.CreateAttribute("password");
            password.Value = instance.User.Password;
            user.Attributes.Append(password);

            XmlNode existing = pluginNode.SelectSingleNode(user.Name);
            if (existing == null)
                pluginNode.AppendChild(user);
            else
                pluginNode.ReplaceChild(user, existing);

            XmlElement login = xmlDoc.CreateElement("Login");
            XmlAttribute loginId = xmlDoc.CreateAttribute("loginId");
            loginId.Value = instance.User.LoginId;
            login.Attributes.Append(loginId);
            XmlAttribute loginSecret = xmlDoc.CreateAttribute("loginSecret");
            loginSecret.Value = instance.User.LoginSecret;
            login.Attributes.Append(loginSecret);
            existing = pluginNode.SelectSingleNode(login.Name);
            if (existing == null)
                pluginNode.AppendChild(login);
            else
                pluginNode.ReplaceChild(login, existing);

            XmlElement ExportNameInComment = xmlDoc.CreateElement("ExportNameInComment");
            XmlAttribute export = xmlDoc.CreateAttribute("export");
            export.Value = instance.boExportNameInComment.ToString();
            ExportNameInComment.Attributes.Append(export);
            existing = pluginNode.SelectSingleNode(ExportNameInComment.Name);
            if (existing == null)
                pluginNode.AppendChild(ExportNameInComment);
            else
                pluginNode.ReplaceChild(ExportNameInComment, existing);

            XmlElement RoutePrivacyElement = xmlDoc.CreateElement("RoutePrivacy");
            RoutePrivacyElement.SetAttribute("RoutePrivacyIndex", instance.RoutePrivacyIndex.ToString());
            existing = pluginNode.SelectSingleNode(RoutePrivacyElement.Name);
            if (existing == null)
                pluginNode.AppendChild(RoutePrivacyElement);
            else
                pluginNode.ReplaceChild(RoutePrivacyElement, existing);

            // Save activity type mappings
            XmlElement mappings = xmlDoc.CreateElement("Mappings"); //Remains called only Mappings for compatibility reasons
            foreach (ActivityTypeMapping atm in instance.ActivityTypeMappings)
            {
                if (atm.Funbeat != 51) // 51 is default, only save mappings that differ
                {
                    XmlElement mapping = xmlDoc.CreateElement("Mapping");
                    XmlAttribute funbeat = xmlDoc.CreateAttribute("funbeat");
                    XmlAttribute st2 = xmlDoc.CreateAttribute("st2");
                    funbeat.Value = atm.Funbeat.ToString();
                    st2.Value = atm.SportTracks;
                    mapping.Attributes.Append(funbeat);
                    mapping.Attributes.Append(st2);

                    mappings.AppendChild(mapping);
                }
            }

            existing = pluginNode.SelectSingleNode(mappings.Name);
            if (existing == null)
                pluginNode.AppendChild(mappings);
            else
                pluginNode.ReplaceChild(mappings, existing);

            // Save equipment mappings
            XmlElement eqMappings = xmlDoc.CreateElement("EquipmentMappings");
            foreach (EquipmentTypeMapping etm in instance.EquipmentTypeMappings)
            {
                if (etm.Funbeat != "") // Only save mappings that are used
                {
                    XmlElement mapping = xmlDoc.CreateElement("Mapping");
                    XmlAttribute funbeat = xmlDoc.CreateAttribute("funbeat");
                    XmlAttribute st2 = xmlDoc.CreateAttribute("st2");
                    funbeat.Value = etm.Funbeat;
                    st2.Value = etm.SportTracks;
                    mapping.Attributes.Append(funbeat);
                    mapping.Attributes.Append(st2);

                    eqMappings.AppendChild(mapping);
                }
            }

            existing = pluginNode.SelectSingleNode(eqMappings.Name);
            if (existing == null)
                pluginNode.AppendChild(eqMappings);
            else
                pluginNode.ReplaceChild(eqMappings, existing);
        }
Exemplo n.º 2
0
        internal static void PopulateInstance(System.Xml.XmlElement pluginNode, XmlNamespaceManager nsmgr, XmlDocument xmlDoc)
        {
            instance = new Settings();

            foreach (XmlNode node in pluginNode.ChildNodes)
            {
                if (node.Name == "User")
                {
                    instance.User.Username = node.Attributes[0].Value; //Saved username only used to display to user on settings page
                    instance.User.HashedPassword = node.Attributes[1].Value; // Password only used to display to user on settings page
                }
                else if (node.Name == "Login")
                {
                    instance.User.LoginId = node.Attributes[0].Value;
                    instance.User.LoginSecret = node.Attributes[1].Value;
                }
                else if (node.Name == "ExportNameInComment")
                {
                    instance.boExportNameInComment = bool.Parse(node.Attributes[0].Value);
                }
                else if (node.Name == "Mappings")
                {
                    foreach (XmlNode mapping in node.ChildNodes)
                    {
                        ActivityTypeMapping atm = new ActivityTypeMapping();
                        atm.SportTracks = mapping.Attributes["st2"].Value;
                        atm.Funbeat = int.Parse(mapping.Attributes["funbeat"].Value);
                        instance.ActivityTypeMappings.Add(atm);
                    }
                }
                else if (node.Name == "EquipmentMappings")
                {
                    foreach (XmlNode mapping in node.ChildNodes)
                    {
                        EquipmentTypeMapping etm = new EquipmentTypeMapping();
                        etm.SportTracks = mapping.Attributes["st2"].Value;
                        etm.Funbeat = mapping.Attributes["funbeat"].Value;
                        instance.EquipmentTypeMappings.Add(etm);
                    }
                }
                else if (node.Name == "RoutePrivacy")
                {
                    int privacy;
                    if (int.TryParse(node.Attributes[0].Value, out privacy))
                        instance.RoutePrivacyIndex = privacy;
                }
            }
        }