Esempio n. 1
0
        private static void Main()
        {
            PortableSettingsProvider settingsProvider = new PortableSettingsProvider();

            BiblioUpTik.Properties.Settings.Default.Providers.Add((ProviderBase)settingsProvider);
            foreach (SettingsProperty property in BiblioUpTik.Properties.Settings.Default.Properties)
            {
                property.Provider = (SettingsProvider)settingsProvider;
            }
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run((Form) new BiblioUpTik.BiblioUpTik());
        }
        private string GetValue(SettingsProperty setting)
        {
            string str;

            try
            {
                str = PortableSettingsProvider.IsRoaming(setting) ? this.SettingsXML.SelectSingleNode("Settings/" + setting.Name).InnerText : this.SettingsXML.SelectSingleNode("Settings/" + Environment.MachineName + "/" + setting.Name).InnerText;
            }
            catch (Exception ex)
            {
                str = setting.DefaultValue != null?setting.DefaultValue.ToString() : "";
            }
            return(str);
        }
        private void SetValue(SettingsPropertyValue propVal)
        {
            XmlElement xmlElement1;

            try
            {
                xmlElement1 = !PortableSettingsProvider.IsRoaming(propVal.Property) ? (XmlElement)this.SettingsXML.SelectSingleNode("Settings/" + Environment.MachineName + "/" + propVal.Name) : (XmlElement)this.SettingsXML.SelectSingleNode("Settings/" + propVal.Name);
            }
            catch (Exception ex)
            {
                xmlElement1 = (XmlElement)null;
            }
            if (xmlElement1 != null)
            {
                xmlElement1.InnerText = propVal.SerializedValue.ToString();
            }
            else if (PortableSettingsProvider.IsRoaming(propVal.Property))
            {
                XmlElement element = this.SettingsXML.CreateElement(propVal.Name);
                element.InnerText = propVal.SerializedValue.ToString();
                this.SettingsXML.SelectSingleNode("Settings").AppendChild((XmlNode)element);
            }
            else
            {
                XmlElement xmlElement2;
                try
                {
                    xmlElement2 = (XmlElement)this.SettingsXML.SelectSingleNode("Settings/" + Environment.MachineName);
                }
                catch (Exception ex)
                {
                    xmlElement2 = this.SettingsXML.CreateElement(Environment.MachineName);
                    this.SettingsXML.SelectSingleNode("Settings").AppendChild((XmlNode)xmlElement2);
                }
                if (xmlElement2 == null)
                {
                    xmlElement2 = this.SettingsXML.CreateElement(Environment.MachineName);
                    this.SettingsXML.SelectSingleNode("Settings").AppendChild((XmlNode)xmlElement2);
                }
                XmlElement element = this.SettingsXML.CreateElement(propVal.Name);
                element.InnerText = propVal.SerializedValue.ToString();
                xmlElement2.AppendChild((XmlNode)element);
            }
        }