Esempio 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);
            }
        }
        public static void ImportSharedSettings(this ApplicationSettingsBase settings, string configurationFilename)
        {
            SystemConfiguration configuration = SystemConfigurationHelper.GetExeConfiguration(configurationFilename);
            var values = SystemConfigurationHelper.GetSettingsValues(configuration, settings.GetType());

            SetSharedPropertyValues(settings, values);
        }
Esempio n. 3
0
 static public string Txt(ApplicationSettingsBase appSettings, string settingName)
 {
     return(Txt(
                appSettings,
                _nilnul.cfg.on_._DllX.Cfg(appSettings.GetType().Assembly)
                , settingName
                ));
 }
Esempio n. 4
0
        public static ReactiveProperty <T> ToReactiveProperty <T>(this ApplicationSettingsBase settings, string propertyName)
        {
            var propertyInfo     = settings.GetType().GetProperty(propertyName);
            var reactiveProperty = new ReactiveProperty <T>((T)propertyInfo.GetValue(settings));

            settings.PropertyChanged += (s, e) => reactiveProperty.Value = (T)propertyInfo.GetValue(settings);
            reactiveProperty.Subscribe(t => propertyInfo.SetValue(settings, t));
            return(reactiveProperty);
        }
Esempio n. 5
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();
        }
Esempio n. 6
0
        /// <summary>
        /// Gets the default property value by property name.
        /// </summary>
        /// <typeparam name="T">Type to which the property must be cast to in the end.</typeparam>
        /// <param name="settings">The application settings.</param>
        /// <param name="propertyName">Name of the property we want to get the default value from.</param>
        /// <returns></returns>
        public static T GetPropertyDefaultValueByName <T>(this ApplicationSettingsBase settings, string propertyName)
        {
            var settingsProperty = settings.Properties[propertyName];
            var propertyInfo     = settings.GetType().GetProperties().FirstOrDefault(p => string.Equals(p.Name, propertyName, StringComparison.InvariantCulture));

            if (propertyInfo == null || settingsProperty == null)
            {
                return(default(T));
            }

            return((T)Convert.ChangeType(settingsProperty.DefaultValue, propertyInfo.PropertyType));
        }
Esempio n. 7
0
        public static void Export(ApplicationSettingsBase config, string path)
        {
            XDocument xml   = new XDocument(new XElement("DV_ReportAnalytics"));
            var       props = config.GetType().GetProperties(
                BindingFlags.DeclaredOnly |
                BindingFlags.Instance |
                BindingFlags.Public);

            foreach (var p in props)
            {
                xml.Root.Add(new XElement(p.Name, p.GetValue(config)));
            }
            xml.Save(path);
        }
        private void Form_Load(object sender, EventArgs e)
        {
            if (_appSettings == null)
            {
                return;
            }

            PropertyInfo settingProperty = _appSettings.GetType().GetProperty(_settingName);

            if (settingProperty == null)
            {
                return;
            }

            WindowSettings previousSettings = settingProperty.GetValue(_appSettings, null) as WindowSettings;

            if (previousSettings == null)
            {
                return;
            }

            previousSettings.Restore(this);
        }
Esempio n. 9
0
        public static void Import(ApplicationSettingsBase config, string path)
        {
            XDocument xml = XDocument.Load(path);

            try
            {
                // validate config before importing
                const string typeParam  = "ReportType";
                string       configType = (string)config.GetType().GetProperty(typeParam).GetValue(config);
                string       xmlType    = xml.Root.Element(typeParam).Value;
                if (!string.Equals(configType, xmlType))
                {
                    throw new Exception();
                }

                // starting importing
                var props = config.GetType().GetProperties(
                    BindingFlags.DeclaredOnly |
                    BindingFlags.Instance |
                    BindingFlags.Public);
                foreach (var p in props)
                {
                    if (p.Name == typeParam)
                    {
                        continue;
                    }
                    var pt = p.PropertyType;
                    p.SetValue(config, Convert.ChangeType(xml.Root.Element(p.Name).Value, pt));
                }
            }
            catch
            {
                string errormsg = "Invalid config!";
                Console.WriteLine(errormsg);
                ExceptionThrown?.Invoke(Default, new EventArgs <string>(errormsg));
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Resets the settings that correspond to the defined section to its default values.
        /// </summary>
        /// <param name="settings">The application defualt settings (extension method)</param>
        /// <param name="section">The section type</param>
        public static void ResetSectionToDefaultValues(this ApplicationSettingsBase settings, PropertyGroup.SettingsGroup section)
        {
            foreach (var propertyInfo in settings.GetType().GetProperties())
            {
                var att = propertyInfo.GetCustomAttributes(typeof(PropertyGroup), true).FirstOrDefault();
                if (att == null || ((PropertyGroup)att).Value != section)
                {
                    continue;
                }

                var settingsProperty = settings.Properties[propertyInfo.Name];
                if (settingsProperty == null)
                {
                    continue;
                }

                propertyInfo.SetValue(settings, Convert.ChangeType(settingsProperty.DefaultValue, propertyInfo.PropertyType), null);
            }
        }
Esempio n. 11
0
    public static bool Unprotect(this ApplicationSettingsBase settings)
    {
        var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
        var sec    = config.GetSectionGroup("userSettings")?.Sections[settings.GetType().FullName];

        if (sec != null)
        {
            try
            {
                if (sec.SectionInformation.IsProtected)
                {
                    sec.SectionInformation.UnprotectSection();
                    config.Save(ConfigurationSaveMode.Minimal);
                }

                return(true);
            }
            catch
            {
            }
        }

        return(false);
    }
Esempio n. 12
0
        public static void LoadFromServiceCore(ApplicationSettingsBase target)
        {
            try
            {
                Settings @default = Settings.Default;
                Type     type     = @default.GetType();
                Type     type2    = target.GetType();
                Dictionary <string, string> dictionary = new Dictionary <string, string>();
                foreach (PropertyInfo propertyInfo in type.GetProperties())
                {
                    object[] customAttributes = propertyInfo.GetCustomAttributes(typeof(SpecialSettingAttribute), false);
                    int      j = 0;
                    while (j < customAttributes.Length)
                    {
                        SpecialSettingAttribute specialSettingAttribute = (SpecialSettingAttribute)customAttributes[j];
                        if (specialSettingAttribute.SpecialSetting == SpecialSetting.ConnectionString)
                        {
                            string text = propertyInfo.GetValue(@default, null) as string;
                            if (text != null)
                            {
                                dictionary.Add(propertyInfo.Name, StringEncrypter.Decrypt(text, propertyInfo.Name, false));
                                @default[propertyInfo.Name] = dictionary[propertyInfo.Name];
                                break;
                            }
                            Log <ConnectionStringLoader> .Logger.FatalFormat("Fail to read {0} in ServiceCore", propertyInfo.Name);

                            break;
                        }
                        else
                        {
                            j++;
                        }
                    }
                }
                foreach (PropertyInfo propertyInfo2 in type2.GetProperties())
                {
                    bool     flag = false;
                    object[] customAttributes2 = propertyInfo2.GetCustomAttributes(typeof(SpecialSettingAttribute), false);
                    int      l = 0;
                    while (l < customAttributes2.Length)
                    {
                        SpecialSettingAttribute specialSettingAttribute2 = (SpecialSettingAttribute)customAttributes2[l];
                        if (specialSettingAttribute2.SpecialSetting == SpecialSetting.ConnectionString)
                        {
                            flag = true;
                            string text2 = dictionary.TryGetValue(propertyInfo2.Name);
                            if (text2 != null)
                            {
                                target[propertyInfo2.Name] = text2;
                                break;
                            }
                            Log <ConnectionStringLoader> .Logger.FatalFormat("No connectionstring defined in ServiceCore : {0}", propertyInfo2.Name);

                            break;
                        }
                        else
                        {
                            l++;
                        }
                    }
                    if (!flag && (propertyInfo2.GetCustomAttributes(typeof(ApplicationScopedSettingAttribute), false).FirstOrDefault <object>() != null || propertyInfo2.GetCustomAttributes(typeof(UserScopedSettingAttribute), false).FirstOrDefault <object>() != null))
                    {
                        Log <ConnectionStringLoader> .Logger.FatalFormat("Do NOT define Configuration Setting outside of ServiceCore : {0}", propertyInfo2.Name);
                    }
                }
            }
            catch (Exception ex)
            {
                Log <ConnectionStringLoader> .Logger.Fatal(string.Format("Exception occurred while loading ConnectionStrings : {0}", target), ex);
            }
        }