/// <summary> /// Creates a new PrimeParameters object /// </summary> /// <param name="settings">Use this settings as base</param> public PrimeParameters(ApplicationSettingsBase settings) : this() { foreach (SettingsPropertyValue s in settings.PropertyValues) { _properties.Add(s.Name, s.PropertyValue); } }
private static void Main() { // Set Current Directory to EXE Path string currentDir = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); if (!String.IsNullOrWhiteSpace(currentDir)) { Environment.CurrentDirectory = currentDir; } // Get Settings from File if (File.Exists(SettingsManager.SettingsPath + SettingsManager.SettingsFile)) { // Load Settings ApplicationSettingsBase settings = Settings.Default; SettingsManager.Load(ref settings); } else { // Create Default Settings SettingsManager.Save(Settings.Default); } // Run Program AutoKMS autoKMS = new AutoKMS(); autoKMS.RunAutoKMS(); }
/// <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> /// <returns>true wenn DialogResult=true, ansonsten false</returns> public bool?ShowDialog(string titel, object datacontext, ApplicationSettingsBase settings, string pathHeigthSetting, string pathWidthSetting, double minHeigth = 0, double minWidth = 0, double maxHeigth = double.PositiveInfinity, double maxWidth = double.PositiveInfinity) { var win = new DialogWindow { Title = titel, DataContext = datacontext }; win.MinHeight = minHeigth; win.MinWidth = minWidth; win.MaxHeight = maxHeigth; win.MaxWidth = maxWidth; 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 { win.SizeToContent = SizeToContent.WidthAndHeight; } return(win.ShowDialog()); }
public RichDelegateCommand(String shortDescription, String longDescription, KeyGesture keyGesture, VisualBrush icon, Action executeMethod, Func <bool> canExecuteMethod, ApplicationSettingsBase settingContainer, string settingName) : base(executeMethod, canExecuteMethod, false) { KeyGestureSettingContainer = settingContainer; KeyGestureSettingName = settingName; KeyGesture = keyGesture ?? RefreshKeyGestureSetting(); ShortDescription = (String.IsNullOrEmpty(shortDescription) ? "" : shortDescription); LongDescription = (String.IsNullOrEmpty(longDescription) ? "" : longDescription); m_VisualBrush = icon; if (HasIcon) { // TODO: fetching the magnification level from the app resources breaks encapsulation ! var scale = (Double)Application.Current.Resources["MagnificationLevel"]; IconProvider = new ScalableGreyableImageProvider(m_VisualBrush, scale); //m_IconProviders.Add(IconProvider); } }
private static void Main() { // Set Current Directory to EXE Path string currentDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); if (!String.IsNullOrWhiteSpace(currentDir)) { Environment.CurrentDirectory = currentDir; } // Get Settings from File if (File.Exists(SettingsManager.SettingsPath + SettingsManager.SettingsFile)) { // Load Settings ApplicationSettingsBase settings = Settings.Default; SettingsManager.Load(ref settings); } else { // Create Default Settings SettingsManager.Save(Settings.Default); } // Start KMS Server //KMSServer.Start(null, new KMSServerSettings { GenerateRandomKMSPID = true }); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new GUI()); }
public static void EnsureMaintainUserSettings(this ApplicationSettingsBase settings, string keyName) { if (settings == null) { return; } var keyValue = settings[keyName]; var defaultValue = settings.Properties[keyName]?.DefaultValue; if (keyValue != defaultValue) { return; } foreach (SettingsProperty prop in settings.Properties) { if (!prop.Attributes.ContainsKey(typeof(UserScopedSettingAttribute))) { continue; } var result = settings.GetPreviousVersion(prop.Name); settings[prop.Name] = result; } settings.Save(); }
public static void CopyTo(this ApplicationSettingsBase settings, ApplicationSettingsBase to_set) { //var vals=to_set.PropertyValues.Cast<SettingsPropertyValue>(); var vals = settings.PropertyValues.Cast <SettingsPropertyValue>(); vals.Generate(x => to_set[x.Name] = settings[x.Name]); }
/// <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; }
public static void LoadProperty(object parent, ApplicationSettingsBase settings, PropertyInfo p) { if (!AddProperty(settings, p.Name, p.PropertyType)) { p.SetValue(parent, settings[p.Name]); } }
public static void Add <T>(this ApplicationSettingsBase settings, string propertyName, T val) { if (settings.Properties[propertyName] != null) { return; } var p = new SettingsProperty(propertyName) { PropertyType = typeof(T), Provider = settings.Providers["LocalFileSettingsProvider"], SerializeAs = SettingsSerializeAs.String }; p.Attributes.Add(typeof(UserScopedSettingAttribute), new UserScopedSettingAttribute()); settings.Properties.Add(p); settings.Reload(); //finally set value with new value if none was loaded from userConfig.xml var item = settings[propertyName]; if (item == null) { settings[propertyName] = val; settings.Save(); } }
public static void Initialize(ContainerBuilder builder, ApplicationSettingsBase appSettings) { builder.RegisterType <TimerProvider>().As <ITimerProvider>().SingleInstance(); builder.Register(c => c.Resolve <ITimerProvider>().GetTimer()); builder.RegisterType <TamagochiSerializer>().As <ISerializer>(); builder.RegisterType <GameContextProvider>().As <IGameContextProvider>().SingleInstance(); builder.Register(c => { var timer = c.Resolve <AbstractTamagochiTimer>(); var petFactory = c.Resolve <AbstractPetFactory>(); return(new GameFactory(petFactory, timer)); }).As <AbstractGameFactory>().SingleInstance(); builder.Register(c => { var provider = c.Resolve <IGameContextProvider>(); var serializer = c.Resolve <ISerializer>(); var settings = c.Resolve <ISettings>(); return(provider.GetGameContext(serializer, settings)); }).SingleInstance(); builder.RegisterType <PetFactory>().As <AbstractPetFactory>().SingleInstance(); builder.RegisterType <TamagochiSettingsProvider>().As <ISettingsProvider>().SingleInstance(); builder.Register(c => c.Resolve <ISettingsProvider>().GetSettings(appSettings)).SingleInstance(); }
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 SetSharedPropertyValue(this ApplicationSettingsBase settings, string propertyName, object value) { SettingsProperty property = settings.Properties[propertyName]; if (property == null) { throw new ArgumentException(String.Format("The specified property does not exist: {0}", propertyName), "propertyName"); } ISharedApplicationSettingsProvider sharedSettingsProvider = GetSharedSettingsProvider(property.Provider); if (sharedSettingsProvider == null) { throw new NotSupportedException("Setting shared values is not supported."); } SettingsPropertyValue settingsValue = new SettingsPropertyValue(property) { PropertyValue = value }; sharedSettingsProvider.SetSharedPropertyValues(settings.Context, new SettingsPropertyValueCollection { settingsValue }); SaveIfDirty(settings); //Need to call Reload because changes to shared settings aren't automatically realized by the .NET settings framework. settings.Reload(); }
public static void DoUpgrade(ApplicationSettingsBase settings) { try { // attempt to read the upgrade flag if ((bool)settings[UpgradeFlag] == true) { // upgrade the settings to the latest version settings.Upgrade(); // clear the upgrade flag settings[UpgradeFlag] = false; settings.Save(); } else { // the settings are up to date } } catch (SettingsPropertyNotFoundException ex) { // notify the developer that the upgrade // flag should be added to the settings file throw ex; } }
protected SettingsHelper(ApplicationSettingsBase userSettings, LogHelper logHelper) { _configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); _canSaveAppSettings = CanSaveConfiguration(_configuration); _logHelper = logHelper; _userSettings = userSettings; }
private string AddNew(string key, string value) { ApplicationSettingsBase settings = Properties.Settings.Default; var p = new SettingsProperty(key) { PropertyType = typeof(string), Provider = settings.Providers["LocalFileSettingsProvider"], SerializeAs = SettingsSerializeAs.Xml }; p.Attributes.Add(typeof(UserScopedSettingAttribute), new UserScopedSettingAttribute()); settings.Properties.Add(p); settings.Reload(); //finally set value with new value if none was loaded from userConfig.xml var item = settings[key]; if (item == null) { settings[key] = value; settings.Save(); return(value); } else { return(item.ToString()); } }
public override object GetValue(IBuilderContext context) { lock (cache) { string cacheKey = type.ToString(); if (settingsKey != null) { cacheKey += "-" + settingsKey; } ApplicationSettingsBase settings = cache[cacheKey]; if (settings == null) { settings = (ApplicationSettingsBase)context.HeadOfChain.BuildUp(context, type, null, null); if (settingsKey != null) { settings.SettingsKey = settingsKey; } cache.Add(cacheKey, settings); } return(settings); } }
public void AssignProviderToSettings(ApplicationSettingsBase settings) { Type saveType = typeof(UserScopedSettingAttribute); bool addedAny = false; foreach (SettingsProperty property in settings.Properties) { if (property.Attributes.ContainsKey(saveType)) { property.Provider = this; addedAny = true; } } if (addedAny) { bool containsProvider = false; foreach (SettingsProvider provider in settings.Providers) { if (provider == this) { containsProvider = true; break; } } if (!containsProvider) { settings.Providers.Add(this); } } }
/// <summary> /// Load Application Settings from a Settings File /// </summary> /// <param name="settings">Application Settings Object for the running Application</param> public static void Load(ref ApplicationSettingsBase settings) { // Create new XmlDocument for Settings File XmlDocument settingsDoc = new XmlDocument(); settingsDoc.Load(SettingsPath + SettingsFile); // Get a list of all XmlNodes with the Tag Setting foreach (XmlNode node in settingsDoc.GetElementsByTagName("setting")) { // Change Setting if (node.Attributes != null) { string name = node.Attributes[0].Value; string type = node.Attributes[1].Value; string value = node.FirstChild.InnerText; if (settings[name] != null) { // ReSharper disable AssignNullToNotNullAttribute settings[name] = Convert.ChangeType(value, Type.GetType(type)); // ReSharper restore AssignNullToNotNullAttribute } } } }
internal static void MigrateUserSettings(ApplicationSettingsBase settings) { if (settings is IMigrateSettings) { IMigrateSettings customMigrator = (IMigrateSettings)settings; foreach (SettingsProperty property in settings.Properties) { if (!SettingsPropertyExtensions.IsUserScoped(property)) { continue; } object previousValue = settings.GetPreviousVersion(property.Name); //need to do this to force the values to load before accessing the PropertyValues in order to migrate, //otherwise the SettingsPropertyValue will always be null. var iForceSettingsPropertyValuesToLoad = settings[property.Name]; var currentValue = settings.PropertyValues[property.Name]; MigrateProperty(customMigrator, MigrationScope.User, currentValue, previousValue); } } else { settings.Upgrade(); } //Don't need to reload because the user settings will be current. SaveIfDirty(settings); }
public static object GetPreviousSharedPropertyValue(this ApplicationSettingsBase settings, string propertyName, string previousExeConfigFilename) { SettingsProperty property = settings.Properties[propertyName]; if (property == null) { throw new ArgumentException(String.Format("The specified property does not exist: {0}", propertyName), "propertyName"); } ISharedApplicationSettingsProvider provider = GetSharedSettingsProvider(property.Provider); if (provider == null) { return(null); } SettingsPropertyValueCollection values = provider.GetPreviousSharedPropertyValues(settings.Context, new SettingsPropertyCollection { property }, previousExeConfigFilename); SettingsPropertyValue value = values[propertyName]; return(value == null ? null : value.PropertyValue); }
public static void ImportSharedSettings(this ApplicationSettingsBase settings, string configurationFilename) { SystemConfiguration configuration = SystemConfigurationHelper.GetExeConfiguration(configurationFilename); var values = SystemConfigurationHelper.GetSettingsValues(configuration, settings.GetType()); SetSharedPropertyValues(settings, values); }
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(); }
public SettingsManager(IApplicationState state, IPluginManager pluginManager, IApplicationConfig config, ApplicationSettingsBase settings) { _settings = settings; _state = state; _pluginManager = pluginManager; _config = config; }
/// <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(); } }
/// <summary> /// Reset property to it's default value /// </summary> public static void Reset(this ApplicationSettingsBase settings, string propertyName) { SettingsProperty property = settings.Properties[propertyName]; TypeConverter converter = TypeDescriptor.GetConverter(property.PropertyType); settings[propertyName] = converter.ConvertFromString(property.DefaultValue.ToString()); }
public static UserSettingsUpgradeStep Create(Type settingsClass) { //Important: this line first so we can't get into infinite recursion issues with trying //to migrate the UpgradeSettings class on first access (SettingsStoreSettingsProvider does that). if (!ApplicationSettingsHelper.IsUserSettingsMigrationEnabled(settingsClass)) { return(null); } if (!new SettingsGroupDescriptor(settingsClass).HasUserScopedSettings) { return(null); //no point } if (!UpgradeSettings.IsUserUpgradeEnabled()) { return(null); } if (UpgradeSettings.Default.IsUserUpgradeStepCompleted(settingsClass.FullName)) { return(null); } ApplicationSettingsBase settings = ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass); return(new UserSettingsUpgradeStep(settings)); }
static public string Txt(ApplicationSettingsBase appSettings, string settingName) { return(Txt( appSettings, _nilnul.cfg.on_._DllX.Cfg(appSettings.GetType().Assembly) , settingName )); }
/// <summary> /// IEnumerableなKeyValuePairでそれぞれ指定したプロパティ名へ値をセットして保存する /// </summary> /// <param name="settings"></param> /// <param name="keyValues">IEnumerableなプロパティ名と値のペア</param> public static void SaveSettings(ApplicationSettingsBase settings, IEnumerable <KeyValuePair <string, object> > keyValues) { foreach (var keyValue in keyValues) { settings[keyValue.Key] = keyValue.Value; } settings.Save(); }
public ConfigurableWindowSettings(ApplicationSettingsBase settings, string isFirstRunProp, string windowLocationProp, string windowSizeProp, string windowStateProp) { _settings = settings; _isFirstRunProp = isFirstRunProp; _windowLocationProp = windowLocationProp; _windowSizeProp = windowSizeProp; _windowStateProp = windowStateProp; }
public static void MakePortable(ApplicationSettingsBase settings) { MakePortable<IracingApplicationVersionManagerProvider>(settings); }