Ejemplo n.º 1
0
        public SettingsExplorer(ApplicationSettingsBase settings)
            : base(new Guid("B760CC2A-F836-403E-9BD5-17807A387A8E"))
        {
            _settings = settings;

            Functions = ExplorerFunctions.GetContent | ExplorerFunctions.SetText;

            var type = _settings.GetType();
            Location = Far.Api.GetModuleManager(type).ModuleName + "\\" + type.Name;

            foreach (SettingsProperty property in _settings.Properties)
            {
                // skip not browsable
                var browsable = (BrowsableAttribute)property.Attributes[typeof(BrowsableAttribute)];
                if (browsable != null && !browsable.Browsable)
                    continue;

                // ensure the property value exists
                var dummy = _settings[property.Name];
                var value = _settings.PropertyValues[property.Name];

                var file = new SetFile();
                _files.Add(file);
                file.Data = value;
                file.Name = property.Name;
                file.Description = GetPropertyValueText(value);

                CompleteFileData(file, value);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SettingsHelper"/> class.
 /// </summary>
 /// <param name="settings">
 /// The settings.
 /// </param>
 /// <param name="goinstall">
 /// default setting parameter
 /// used for updating.
 /// </param>
 public SettingsHelper(ApplicationSettingsBase settings, string goinstall)
     : this()
 {
     this.settings = settings;
     this.goinstall = goinstall;
     this.Disposed = null;
 }
		private static void SetSharedPropertyValues(ApplicationSettingsBase settings, Dictionary<string, string> values)
		{
			foreach (SettingsProvider provider in settings.Providers)
			{
				ISharedApplicationSettingsProvider sharedSettingsProvider = GetSharedSettingsProvider(provider);
				if (sharedSettingsProvider == null)
					throw new NotSupportedException("Setting shared values is not supported.");

				var properties = GetPropertiesForProvider(settings, provider);
				SettingsPropertyValueCollection settingsValues = new SettingsPropertyValueCollection();

				foreach (var value in values)
				{
					SettingsProperty property = properties[value.Key];
					if (property == null)
						continue;

					settingsValues.Add(new SettingsPropertyValue(property) { SerializedValue = value.Value, IsDirty = true });
				}

				sharedSettingsProvider.SetSharedPropertyValues(settings.Context, settingsValues);
			}

			SaveIfDirty(settings);
			settings.Reload();
		}
Ejemplo n.º 4
0
 public SettingsManager(IApplicationState state, IPluginManager pluginManager, IApplicationConfig config, ApplicationSettingsBase settings)
 {
     _settings = settings;
     _state = state;
     _pluginManager = pluginManager;
     _config = config;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Zeigt ein Dialog an
 /// </summary>
 /// <param name="titel">Titel für den Dialog<</param>
 /// <param name="datacontext">DataContext für den Dialog</param>
 /// <param name="settings">ApplicationsSetting für Height and Width</param>
 /// <param name="pathHeigthSetting">Name für Height Setting</param>
 /// <param name="pathWidthSetting">Name für Width Setting</param>
 /// <param name="minHeigth">Minimum Height</param>
 /// <param name="minWidth">Minimum Width</param>
 /// <param name="maxHeigth">Maximum Height</param>
 /// <param name="maxWidth">Maximum Width</param>
 /// <param name="showInTaskbar"></param>
 /// <param name="icon"></param>
 /// <returns>true wenn DialogResult=true, ansonsten false</returns>
 public bool? ShowDialog(string titel, object datacontext,
     ApplicationSettingsBase settings, string pathHeigthSetting, string pathWidthSetting,
     double minHeigth, double minWidth, double maxHeigth = double.PositiveInfinity, double maxWidth = double.PositiveInfinity,
     bool showInTaskbar = false, ImageSource icon = null)
 {
     return DoShowDialog(titel, datacontext, settings, pathHeigthSetting, pathWidthSetting, minHeigth, minWidth,
         maxHeigth, maxWidth, showInTaskbar, icon);
 }
Ejemplo n.º 6
0
		/// <summary>
		/// Unregisters an instance of a settings class.
		/// </summary>
		public void UnregisterInstance(ApplicationSettingsBase settingsInstance)
		{
			lock (_syncLock)
			{
				if (_registeredSettingsInstances.Contains(settingsInstance))
					_registeredSettingsInstances.Remove(settingsInstance);
			}
		}
Ejemplo n.º 7
0
		/// <summary>
		/// Registers an instance of a settings class.
		/// </summary>
		public void RegisterInstance(ApplicationSettingsBase settingsInstance)
		{ 
			lock(_syncLock)
			{
				if (!_registeredSettingsInstances.Contains(settingsInstance))
					_registeredSettingsInstances.Add(settingsInstance);
			}
		}
Ejemplo n.º 8
0
Archivo: Login.cs Proyecto: Jamyn/Mist
 private static void MakePortable(ApplicationSettingsBase settings)
 {
     var portableSettingsProvider =
         new PortableSettingsProvider("Mist.settings");
     settings.Providers.Add(portableSettingsProvider);
     foreach (System.Configuration.SettingsProperty prop in settings.Properties)
         prop.Provider = portableSettingsProvider;
     settings.Reload();
 }
Ejemplo n.º 9
0
        static void RedirectSettings(ApplicationSettingsBase settings, SettingsProvider provider)
        {
            settings.Providers.Add(provider);
            foreach (SettingsProperty property in settings.Properties)
            {
                property.Provider = provider;
            }

            settings.Reload();
        }
Ejemplo n.º 10
0
 private static void MakePortable(ApplicationSettingsBase settings)
 {
     var portableSettingsProvider = new PortableSettingsProvider();
     settings.Providers.Add(portableSettingsProvider);
     foreach (SettingsProperty prop in settings.Properties)
     {
         prop.Provider = portableSettingsProvider;
     }
     settings.Reload();
 }
Ejemplo n.º 11
0
        public static bool TryGetValue <T>(this System.Configuration.ApplicationSettingsBase settings, string key, out T value)
        {
            if (settings.Properties[key] != null)
            {
                value = (T)settings[key];
                return(true);
            }

            value = default(T);
            return(false);
        }
        private static void SaveIfDirty(ApplicationSettingsBase settings)
        {
            foreach (SettingsPropertyValue property in settings.PropertyValues)
            {
            	if (!property.IsDirty)
					continue;
            	
				settings.Save();
            	return;
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Changes the settings provider so as to store settings in Helper.GetAppdataPath(), not some cryptic directory as is standard.
        /// </summary>
        /// <param name="settings"></param>
        public static void RewireSettingsProvider(ApplicationSettingsBase settings)
        {
            string SettingsFile = Path.Combine(Helper.GetAppdataPath(), "TikzEdt.settings");
            var portableSettingsProvider = new TESettingsProvider(SettingsFile);
            settings.Providers.Add(portableSettingsProvider);
            foreach (System.Configuration.SettingsProperty prop in settings.Properties)
                prop.Provider = portableSettingsProvider;

            if (File.Exists(SettingsFile))  // mono throws an exception if one reloads w/o file present for some unknown reason
                settings.Reload();
        }
        /// <summary>
        /// Returns an observable sequence of setting values that have changed.
        /// </summary>
        /// <param name="settings">The object that defines the settings to observe.</param>
        /// <returns>An observable sequence of setting values that have changed.</returns>
        public static IObservable <SettingsPropertyValue> SettingChanges(this ApplicationSettingsBase settings)
        {
            Contract.Requires(settings != null);
            Contract.Ensures(Contract.Result <IObservable <SettingsPropertyValue> >() != null);

            return(Observable.FromEventPattern <PropertyChangedEventHandler, PropertyChangedEventArgs>(
                       eh => eh.Invoke,
                       eh => settings.PropertyChanged += eh,
                       eh => settings.PropertyChanged -= eh)
                   .Select(e => settings.PropertyValues[e.EventArgs.PropertyName]));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SettingsKeyCodeReference"/> class.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="keySettingName">Name of the key setting.</param>
        /// <exception cref="ArgumentNullException"><see cref="keySettingName"/> is null or empty.</exception>
        SettingsKeyCodeReference(ApplicationSettingsBase settings, string keySettingName)
        {
            if (string.IsNullOrEmpty(keySettingName))
                throw new ArgumentNullException("keySettingName");

            _keySettingName = keySettingName;
            _settings = settings;

            settings.PropertyChanged += settings_PropertyChanged;

            UpdateValue();
        }
		private static SettingsPropertyCollection GetPropertiesForProvider(ApplicationSettingsBase settings, SettingsProvider provider)
        {
            SettingsPropertyCollection properties = new SettingsPropertyCollection();
            
            foreach (SettingsProperty property in settings.Properties)
            {
                if (property.Provider == provider)
                    properties.Add(property);
            }
            
            return properties;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Creates a <see cref="SettingsKeyCodeReference"/> instance.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="keySettingName">Name of the key setting.</param>
        /// <returns>The <see cref="SettingsKeyCodeReference"/> instance.</returns>
        public static SettingsKeyCodeReference Create(ApplicationSettingsBase settings, string keySettingName)
        {
            HashCache<string, SettingsKeyCodeReference> c;
            if (!_settingsCache.TryGetValue(settings, out c))
            {
                c = new HashCache<string, SettingsKeyCodeReference>(x => new SettingsKeyCodeReference(settings, x),
                    StringComparer.Ordinal);
                _settingsCache.Add(settings, c);
            }

            return c[keySettingName];
        }
Ejemplo n.º 18
0
        private static bool IsRoamingSetting(SettingsProperty setting)
        {
            bool flag  = !ApplicationSettingsBase.IsClickOnceDeployed(AppDomain.CurrentDomain);
            bool flag2 = false;

            if (flag)
            {
                SettingsManageabilityAttribute attribute = setting.Attributes[typeof(SettingsManageabilityAttribute)] as SettingsManageabilityAttribute;
                flag2 = (attribute != null) && (0 == 0);
            }
            return(flag2);
        }
        /// <summary>
        /// Returns an observable sequence of values that have changed for the settings with the specified <paramref name="names"/>.
        /// </summary>
        /// <param name="settings">The object that defines the settings to observe.</param>
        /// <param name="names">The names of one or more settings to be observed.</param>
        /// <returns>An observable sequence of values that have changed for the settings with the specified <paramref name="names"/>.</returns>
        public static IObservable <SettingsPropertyValue> SettingChanges(this ApplicationSettingsBase settings, params string[] names)
        {
            Contract.Requires(settings != null);
            Contract.Requires(names != null);
            Contract.Requires(names.Length > 0);
            Contract.Ensures(Contract.Result <IObservable <SettingsPropertyValue> >() != null);

            return(Observable.FromEventPattern <PropertyChangedEventHandler, PropertyChangedEventArgs>(
                       eh => eh.Invoke,
                       eh => settings.PropertyChanged += eh,
                       eh => settings.PropertyChanged -= eh)
                   .Where(e => names.Any(name => string.Equals(e.EventArgs.PropertyName, name, StringComparison.Ordinal)))
                   .Select(e => settings.PropertyValues[e.EventArgs.PropertyName]));
        }
Ejemplo n.º 20
0
        /// <devdoc>
        ///     Indicates whether a setting is roaming or not.
        /// </devdoc>
        private static bool IsRoamingSetting(SettingsProperty setting)
        {
            // Roaming is not supported in Clickonce deployed apps, since they don't have roaming config files.
            bool roamingSupported = !ApplicationSettingsBase.IsClickOnceDeployed(AppDomain.CurrentDomain);
            bool isRoaming        = false;

            if (roamingSupported)
            {
                SettingsManageabilityAttribute manageAttr = setting.Attributes[typeof(SettingsManageabilityAttribute)] as SettingsManageabilityAttribute;
                isRoaming = manageAttr != null && ((manageAttr.Manageability & SettingsManageability.Roaming) == SettingsManageability.Roaming);
            }

            return(isRoaming);
        }
Ejemplo n.º 21
0
        private bool? DoShowDialog(string titel, object datacontext,
            ApplicationSettingsBase settings, string pathHeigthSetting, string pathWidthSetting,
            double minHeigth, double minWidth, double maxHeigth = double.PositiveInfinity,
            double maxWidth = double.PositiveInfinity,
            bool showInTaskbar = false, ImageSource icon = null)
        {
            var win = new DialogWindow { Title = titel, DataContext = datacontext };

            win.Owner = Application.Current.MainWindow;
            win.ShowInTaskbar = showInTaskbar;
            win.MinHeight = minHeigth;
            win.MinWidth = minWidth;
            win.MaxHeight = maxHeigth;
            win.MaxWidth = maxWidth;

            if (icon != null)
            {
                win.Icon = icon;
            }
            else
            {
                var mainIcon = Application.Current.MainWindow.Icon;
                if (mainIcon != null)
                    win.Icon = mainIcon;
            }

            try
            {
                if (settings != null)
                {
                    win.SizeToContent = SizeToContent.Manual;

                    var height = settings[pathHeigthSetting];
                    var width = settings[pathWidthSetting];

                    BindingOperations.SetBinding(win, FrameworkElement.HeightProperty, new Binding(pathHeigthSetting) { Source = settings, Mode = BindingMode.TwoWay });
                    BindingOperations.SetBinding(win, FrameworkElement.WidthProperty, new Binding(pathWidthSetting) { Source = settings, Mode = BindingMode.TwoWay });

                    win.Height = (double)height;
                    win.Width = (double)width;
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
                win.SizeToContent = SizeToContent.WidthAndHeight;
            }

            return win.ShowDialog();
        }
        /// <summary>
        /// Call this to decide whether to show the dialog
        /// </summary>
        /// <param name="settings">enter your Settings.Default. Make sure you have a string property named DontShowThisAgain</param>
        /// <param name="key">A key to use for the list of things not-to-show. You're welcome to use a big long string (like a tip message itself); a hash will be used</param>
        /// <returns>true if you should show it</returns>
        public bool GetOKToShow(ApplicationSettingsBase settings, string key = null )
        {
            if (string.IsNullOrEmpty(key))
            {
                _key = FindForm().Name;
            }
            else
            {
                _key = key.GetHashCode().ToString();
            }
            _settings = settings;
            if (settings == null || DesignMode)
                return true;

            return !DialogsToHide.Contains(_key + ",");
        }
Ejemplo n.º 23
0
        public OptionsForm(ApplicationSettingsBase settings)
        {
            InitializeComponent();

            BoxBackColor = SystemColors.ControlLight;
            OptionsNoDescription = "Description.";

            _Panels.PanelAdded += new OptionsPanelEventHandler(_Panels_PanelAdded);

            ApplyBtn.Enabled = _ApplyAlwaysEnabled;

            _AppSettings = settings;
            _Settings = new SettingsPropertyCollection();
            _ChangedSettings = new Dictionary<String, Object>();

            _AppSettings.SettingChanging += new SettingChangingEventHandler(_AppSettings_SettingChanging);
        }
Ejemplo n.º 24
0
        static public void LoadFromDatabase(Assembly assembly, System.Configuration.ApplicationSettingsBase settings)
        {
            Assembly entry_assembly = Assembly.GetEntryAssembly();
            string   scope          = entry_assembly.GetName().Name;
            string   key            = KEY_PREFIX + assembly.GetName().Name;
            DbApi    di             = DbApi.Create();
            Dictionary <string, object> setting_names2value = Cliver.Bot.DbSettings.Get <Dictionary <string, object> >(di, scope, key);

            if (setting_names2value == null)
            {
                setting_names2value = new Dictionary <string, object>();
            }

            FieldInfo fi = settings.GetType().GetField("defaultInstance", BindingFlags.NonPublic | BindingFlags.Static);

            PropertyInfo[] pis          = fi.FieldType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            bool           new_property = false;

            foreach (PropertyInfo pi in pis)
            {
                string name = pi.DeclaringType.FullName + "." + pi.Name;
                object value;
                if (setting_names2value.TryGetValue(name, out value))
                {
                    if (!pi.CanWrite)
                    {
                        Log.Warning("Settings '" + name + "' is not writable.");
                        continue;
                    }
                    if (pi.PropertyType == typeof(int) && value is string)
                    {
                        value = int.Parse((string)value);
                    }
                    pi.SetValue(settings, value);
                }
                else
                {
                    new_property = true;
                    setting_names2value[name] = pi.GetValue(settings);
                }
            }
            if (new_property)
            {
                Cliver.Bot.DbSettings.Save(di, scope, key, setting_names2value);
            }
        }
		/// <summary>
		/// Registers an instance of a settings class.
		/// </summary>
		public void RegisterInstance(ApplicationSettingsBase settingsInstance)
		{
		    try
		    {
                //TODO (Phoenix5): #10730 - remove this when it's fixed.
                if (Application.GuiToolkitID == GuiToolkitID.Web)
                    return;
		    }
		    catch (Exception)
		    {
                //Just let it get added; this can only happen for a setting initialized before the application itself is initialized.
		    }

			lock(_syncLock)
			{
				if (!_registeredSettingsInstances.Contains(settingsInstance))
					_registeredSettingsInstances.Add(settingsInstance);
			}
		}
Ejemplo n.º 26
0
        public void SaveToConfig(System.Configuration.ApplicationSettingsBase settings)
        {
            //settings.MRPath0 = files[0];
            for (int q = 0; q < files.Count; q++)
            {
                string pName = "MRU" + myName + q.ToString();
                try
                {
                    //if (settings[pName] == null)
                    if (!DoesSettingExist(pName))
                    {
                        //SettingsProvider prov = Properties.Settings.Default.Providers.
                        SettingsProperty prop = new System.Configuration.SettingsProperty(pName);
                        prop.PropertyType = typeof(string);
                        prop.Attributes.Add(typeof(UserScopedSettingAttribute), new UserScopedSettingAttribute());
                        //prop.Provider = prov;
                        prop.SerializeAs = SettingsSerializeAs.Xml;
                        SettingsPropertyValue valu = new SettingsPropertyValue(prop);
                        settings.Properties.Add(prop);



                        //settings[pName] = files[q];
                        settings.Save();
                        settings.Reload();
                    }
                    settings[pName] = files[q];
                }
                catch (Exception e)
                {
                    if (IsWizard)
                    {
                        string msg = e.Message;
                        //System.Diagnostics.Debugger.Break();
                    }
                }
            }
            settings.Save();
        }
 public static ApplicationSettingsBase Synchronized(ApplicationSettingsBase wrapped)
 {
   return wrapped;
 }
Ejemplo n.º 28
0
        private void SaveProperties(ExeConfigurationFileMap exeMap, SettingsPropertyValueCollection collection, ConfigurationUserLevel level, SettingsContext context, bool checkUserLevel)
        {
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(exeMap, level);

            UserSettingsGroup userGroup = config.GetSectionGroup("userSettings") as UserSettingsGroup;
            bool isRoaming = (level == ConfigurationUserLevel.PerUserRoaming);

            if (userGroup == null)
            {
                userGroup = new UserSettingsGroup();
                config.SectionGroups.Add("userSettings", userGroup);
            }
            ApplicationSettingsBase asb       = context.CurrentSettings;
            string class_name                 = NormalizeInvalidXmlChars((asb != null ? asb.GetType() : typeof(ApplicationSettingsBase)).FullName);
            ClientSettingsSection userSection = null;
            ConfigurationSection  cnf         = userGroup.Sections.Get(class_name);

            userSection = cnf as ClientSettingsSection;
            if (userSection == null)
            {
                userSection = new ClientSettingsSection();
                userGroup.Sections.Add(class_name, userSection);
            }

            bool hasChanges = false;

            if (userSection == null)
            {
                return;
            }

            foreach (SettingsPropertyValue value in collection)
            {
                if (checkUserLevel && value.Property.Attributes.Contains(typeof(SettingsManageabilityAttribute)) != isRoaming)
                {
                    continue;
                }
                // The default impl does not save the ApplicationScopedSetting properties
                if (value.Property.Attributes.Contains(typeof(ApplicationScopedSettingAttribute)))
                {
                    continue;
                }

                hasChanges = true;
                SettingElement element = userSection.Settings.Get(value.Name);
                if (element == null)
                {
                    element = new SettingElement(value.Name, value.Property.SerializeAs);
                    userSection.Settings.Add(element);
                }
                if (element.Value.ValueXml == null)
                {
                    element.Value.ValueXml = new XmlDocument().CreateElement("value");
                }
                switch (value.Property.SerializeAs)
                {
                case SettingsSerializeAs.Xml:
                    element.Value.ValueXml.InnerXml = StripXmlHeader(value.SerializedValue as string);
                    break;

                case SettingsSerializeAs.String:
                    element.Value.ValueXml.InnerText = value.SerializedValue as string;
                    break;

                case SettingsSerializeAs.Binary:
                    element.Value.ValueXml.InnerText = value.SerializedValue != null?Convert.ToBase64String(value.SerializedValue as byte []) : string.Empty;

                    break;

                default:
                    throw new NotImplementedException();
                }
            }
            if (hasChanges)
            {
                config.Save(ConfigurationSaveMode.Minimal, true);
            }
        }
Ejemplo n.º 29
0
 /// <summary>
 /// Initializes a new <see cref="SettingsStore"/> instance.
 /// </summary>
 /// <param name="settings">The settings that are used to store the configuration data.</param>
 public SettingsStore(ApplicationSettingsBase settings)
     : this(settings, "Configuration")
 { }
Ejemplo n.º 30
0
        /// <summary>
        /// Load controller-specific settings and instantiate the controller
        /// </summary>
        /// <param name="settings">The application settings that stores the controller-specific config</param>
        /// <param name="controllerType">The type of the class of controller to instantiate</param>
        /// <returns>The instantiated controller</returns>
        public static RGBController LoadController(ApplicationSettingsBase settings, Type controllerType)
        {
            if (controllerType != null)
            {
                var controllerSettings = GetControllerSettings(settings, controllerType);

                // Try and instantiate the controller with the current config
                try
                {
                    var controller = (RGBController)Activator.CreateInstance(controllerType,
                        new object[] { controllerSettings }
                    );
                    controllerSettings.Controller = controller; // Back-reference
                    return controller;
                }
                catch (TargetInvocationException ex) { throw ex.InnerException; }

            }
            return null;
        }
Ejemplo n.º 31
0
        private void SaveProperties(ExeConfigurationFileMap exeMap, SettingsPropertyValueCollection collection, ConfigurationUserLevel level, SettingsContext context, bool checkUserLevel)
        {
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(exeMap, level);

            UserSettingsGroup userGroup = config.GetSectionGroup("userSettings") as UserSettingsGroup;
            bool isRoaming = (level == ConfigurationUserLevel.PerUserRoaming);

#if true // my reimplementation
            if (userGroup == null)
            {
                userGroup = new UserSettingsGroup();
                config.SectionGroups.Add("userSettings", userGroup);
                ApplicationSettingsBase asb = context.CurrentSettings;
                ClientSettingsSection   cs  = new ClientSettingsSection();
                string class_name           = NormalizeInvalidXmlChars((asb != null ? asb.GetType() : typeof(ApplicationSettingsBase)).FullName);
                userGroup.Sections.Add(class_name, cs);
            }

            bool hasChanges = false;

            foreach (ConfigurationSection section in userGroup.Sections)
            {
                ClientSettingsSection userSection = section as ClientSettingsSection;
                if (userSection == null)
                {
                    continue;
                }

                foreach (SettingsPropertyValue value in collection)
                {
                    if (checkUserLevel && value.Property.Attributes.Contains(typeof(SettingsManageabilityAttribute)) != isRoaming)
                    {
                        continue;
                    }
                    // The default impl does not save the ApplicationScopedSetting properties
                    if (value.Property.Attributes.Contains(typeof(ApplicationScopedSettingAttribute)))
                    {
                        continue;
                    }

                    hasChanges = true;
                    SettingElement element = userSection.Settings.Get(value.Name);
                    if (element == null)
                    {
                        element = new SettingElement(value.Name, value.Property.SerializeAs);
                        userSection.Settings.Add(element);
                    }
                    if (element.Value.ValueXml == null)
                    {
                        element.Value.ValueXml = new XmlDocument().CreateElement("value");
                    }
                    switch (value.Property.SerializeAs)
                    {
                    case SettingsSerializeAs.Xml:
                        element.Value.ValueXml.InnerXml = (value.SerializedValue as string) ?? string.Empty;
                        break;

                    case SettingsSerializeAs.String:
                        element.Value.ValueXml.InnerText = value.SerializedValue as string;
                        break;

                    case SettingsSerializeAs.Binary:
                        element.Value.ValueXml.InnerText = value.SerializedValue != null?Convert.ToBase64String(value.SerializedValue as byte []) : string.Empty;

                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }
            }
            if (hasChanges)
            {
                config.Save(ConfigurationSaveMode.Minimal, true);
            }
#else // original impl. - likely buggy to miss some properties to save
            foreach (ConfigurationSection configSection in userGroup.Sections)
            {
                ClientSettingsSection userSection = configSection as ClientSettingsSection;
                if (userSection != null)
                {
/*
 *                                      userSection.Settings.Clear();
 *
 *                                      foreach (SettingsPropertyValue propertyValue in collection)
 *                                      {
 *                                              if (propertyValue.IsDirty)
 *                                              {
 *                                                      SettingElement element = new SettingElement(propertyValue.Name, SettingsSerializeAs.String);
 *                                                      element.Value.ValueXml = new XmlDocument();
 *                                                      element.Value.ValueXml.InnerXml = (string)propertyValue.SerializedValue;
 *                                                      userSection.Settings.Add(element);
 *                                              }
 *                                      }
 */
                    foreach (SettingElement element in userSection.Settings)
                    {
                        if (collection [element.Name] != null)
                        {
                            if (collection [element.Name].Property.Attributes.Contains(typeof(SettingsManageabilityAttribute)) != isRoaming)
                            {
                                continue;
                            }

                            element.SerializeAs             = SettingsSerializeAs.String;
                            element.Value.ValueXml.InnerXml = (string)collection [element.Name].SerializedValue;                                ///Value = XmlElement
                        }
                    }
                }
            }
            config.Save(ConfigurationSaveMode.Minimal, true);
#endif
        }
Ejemplo n.º 32
0
 private UserSettingsUpgradeStep(ApplicationSettingsBase settings)
 {
     Platform.CheckForNullReference(settings, "settings");
     Settings = settings;
 }
 /// <summary>
 /// Start showing all dialogs again
 /// </summary>
 public void ResetDontShowMemory(ApplicationSettingsBase settings)
 {
     _settings = settings;
     DialogsToHide = "";
 }
Ejemplo n.º 34
0
 public static void SetValue <T>(this System.Configuration.ApplicationSettingsBase settings, string key, T value)
 {
     settings[key] = value;
     settings.Save();
 }
 public static ApplicationSettingsBase Synchronized(ApplicationSettingsBase wrapped)
 {
     return(wrapped);
 }
Ejemplo n.º 36
0
 public static bool ContainsKey(this System.Configuration.ApplicationSettingsBase settings, string key)
 {
     return(settings.Properties[key] != null);
 }
Ejemplo n.º 37
0
 /// <summary>
 /// Parses the data inside a file to be used later
 /// </summary>
 /// <param name="path">Input file, including the extension to detect the format</param>
 /// <param name="settings">Parameters</param>
 public PrimeProgramFile(string path, ApplicationSettingsBase settings) : this(path, new PrimeParameters(settings)) { }
Ejemplo n.º 38
0
 /// <summary>
 /// Initializes a new <see cref="SettingsStore"/> instance.
 /// </summary>
 /// <param name="settings">The settings that are used to store the configuration data.</param>
 /// <param name="propertyName">The name of the property which is used to store the settings.</param>
 public SettingsStore(ApplicationSettingsBase settings, string propertyName)
 {
     this.Settings = settings;
     this.PropertyName = propertyName;
 }
Ejemplo n.º 39
0
 // PortableSettingsProvider code obtained from http://stackoverflow.com/a/2579399 (Accessed 02-01-2014 @ 17:04).
 private static void MakeSettingsPortable(ApplicationSettingsBase settings)
 {
     var portableSettingsProvider = new PortableSettingsProvider(settings.GetType().Name + ".settings");
     settings.Providers.Add(portableSettingsProvider);
     foreach (SettingsProperty prop in settings.Properties)
         prop.Provider = portableSettingsProvider;
     settings.Reload();
 }
Ejemplo n.º 40
0
 public void Save(ApplicationSettingsBase applicationSettings)
 {
     IsSaved = true;
     fileStream.Seek(0, SeekOrigin.Begin);
     new BinaryFormatter().Serialize(fileStream, this);
 }
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection propertyCollection) {
            if (propertyCollection == null || propertyCollection.Count < 1)
                return new SettingsPropertyValueCollection();
            lock(_lock) {
                if (_SettingsBaseClass == null && context != null) {
                    Type oType = context["SettingsClassType"] as Type;
                    if (oType != null) {
                        _SettingsBaseClass = oType.InvokeMember("Default", BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Static,
                                                                null, null, null, CultureInfo.InvariantCulture) as ApplicationSettingsBase;
                    }
                }
                _PropertyValues = new SettingsPropertyValueCollection();
                _Properties = propertyCollection;

                StoreKnownTypes(propertyCollection);
                GetPropertyValuesCore();
                return _PropertyValues;
            }
        }
 /// <summary>
 /// This one uses the form's name as an id
 /// </summary>
 /// <param name="settings">Your Settings.Default</param>
 /// <param name="customID">Some string which can be used as a key into the don't-show index</param>
 public void CloseIfShouldNotShow(ApplicationSettingsBase settings, string customID = null)
 {
     if (!GetOKToShow(settings, customID))
         FindForm().Close();
 }