public Settings(IServiceProvider provider) { SettingsManager settingsManager = new ShellSettingsManager(provider); _settingsStore = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings); if (!_settingsStore.CollectionExists("DebugAttachManagerProcesses")) { return; } IEnumerable <string> services = _settingsStore.GetSubCollectionNames("DebugAttachManagerProcesses"); foreach (var s in services) { var p = new StoredProcessInfo { ProcessName = _settingsStore.GetString("DebugAttachManagerProcesses\\" + s, "ProcessName"), Title = _settingsStore.PropertyExists("DebugAttachManagerProcesses\\" + s, "Title") ? _settingsStore.GetString("DebugAttachManagerProcesses\\" + s, "Title") : null, RemoteServerName = _settingsStore.PropertyExists("DebugAttachManagerProcesses\\" + s, "RemoteServerName") ? _settingsStore.GetString("DebugAttachManagerProcesses\\" + s, "RemoteServerName") : null, RemotePortNumber = _settingsStore.PropertyExists("DebugAttachManagerProcesses\\" + s, "RemotePortNumber") ? _settingsStore.GetInt64("DebugAttachManagerProcesses\\" + s, "RemotePortNumber") : (long?)null, Selected = _settingsStore.GetBoolean("DebugAttachManagerProcesses\\" + s, "Selected"), DebugMode = _settingsStore.PropertyExists("DebugAttachManagerProcesses\\" + s, "DebugMode") ? _settingsStore.GetString("DebugAttachManagerProcesses\\" + s, "DebugMode") : null }; Processes.Add(p.Hash, p); } if (_settingsStore.PropertyExists("DebugAttachManagerProcesses", "RemoteServer")) { RemoteServer = _settingsStore.GetString("DebugAttachManagerProcesses", "RemoteServer"); } }
public object Read(string subPath, string property, object defaultValue) { Validate.IsNotNull(property, nameof(property)); Validate.IsNotEmpty(property, nameof(property)); var collection = subPath != null?Path.Combine(_root, subPath) : _root; _store.CreateCollection(collection); if (defaultValue is bool b) { return(_store.GetBoolean(collection, property, b)); } if (defaultValue is int i) { return(_store.GetInt32(collection, property, i)); } if (defaultValue is uint u) { return(_store.GetUInt32(collection, property, u)); } if (defaultValue is long l) { return(_store.GetInt64(collection, property, l)); } if (defaultValue is ulong ul) { return(_store.GetUInt64(collection, property, ul)); } return(_store.GetString(collection, property, defaultValue?.ToString() ?? "")); }
/// <summary> /// Read from a settings store /// </summary> /// <typeparam name="T"></typeparam> /// <param name="subpath">The subcollection path (appended to the path passed to the constructor)</param> /// <param name="property">The property name to read</param> /// <param name="defaultValue">The default value to use in case the property doesn't exist. /// The type of the default value will be used to figure out the proper way to read the property, so if pass null, /// the property will be read as a string (which may or may not be what you want)</param> /// <returns></returns> public object Read(string subpath, string property, object defaultValue) { Guard.ArgumentNotNull(property, nameof(property)); Guard.ArgumentNotEmptyString(property, nameof(property)); var collection = subpath != null?Path.Combine(root, subpath) : root; store.CreateCollection(collection); if (defaultValue is bool) { return(store.GetBoolean(collection, property, (bool)defaultValue)); } else if (defaultValue is int) { return(store.GetInt32(collection, property, (int)defaultValue)); } else if (defaultValue is uint) { return(store.GetUInt32(collection, property, (uint)defaultValue)); } else if (defaultValue is long) { return(store.GetInt64(collection, property, (long)defaultValue)); } else if (defaultValue is ulong) { return(store.GetUInt64(collection, property, (ulong)defaultValue)); } return(store.GetString(collection, property, defaultValue?.ToString() ?? "")); }
public Settings(IServiceProvider provider) { SettingsManager settingsManager = new ShellSettingsManager(provider); _settingsStore = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings); if (!_settingsStore.CollectionExists("DebugAttachManagerProcesses")) { return; } IEnumerable <string> services = _settingsStore.GetSubCollectionNames("DebugAttachManagerProcesses"); foreach (var s in services) { var p = new StoredProcessInfo { ProcessName = _settingsStore.GetString("DebugAttachManagerProcesses\\" + s, "ProcessName"), Title = _settingsStore.PropertyExists("DebugAttachManagerProcesses\\" + s, "Title") ? _settingsStore.GetString("DebugAttachManagerProcesses\\" + s, "Title") : null, RemoteServerName = _settingsStore.PropertyExists("DebugAttachManagerProcesses\\" + s, "RemoteServerName") ? _settingsStore.GetString("DebugAttachManagerProcesses\\" + s, "RemoteServerName") : null, RemotePortNumber = _settingsStore.PropertyExists("DebugAttachManagerProcesses\\" + s, "RemotePortNumber") ? _settingsStore.GetInt64("DebugAttachManagerProcesses\\" + s, "RemotePortNumber") : (long?)null, Selected = _settingsStore.GetBoolean("DebugAttachManagerProcesses\\" + s, "Selected"), DebugMode = _settingsStore.PropertyExists("DebugAttachManagerProcesses\\" + s, "DebugMode") ? _settingsStore.GetString("DebugAttachManagerProcesses\\" + s, "DebugMode") : null }; Processes.Add(p.Hash, p); } if (_settingsStore.PropertyExists("DebugAttachManagerProcesses", "RemoteServer")) { RemoteServer = _settingsStore.GetString("DebugAttachManagerProcesses", "RemoteServer"); } for (int i = 0; i < Constants.NUMBER_OF_OPTIONAL_COLUMNS; i++) { string columnName = $"Column{i}"; if (_settingsStore.PropertyExists("DebugAttachManagerProcesses", columnName)) { ProcessesColumns[i] = _settingsStore.GetBoolean("DebugAttachManagerProcesses", columnName); } else { if (i == 0) { // This is a hack, so we display PID by default ProcessesColumns[i] = true; } } } }
public static object GetValue(this WritableSettingsStore store, string collectionPath, PropertyDescriptor property) { if (store.PropertyExists(collectionPath, property.Name)) { switch (property.PropertyType) { case Type t when t == typeof(string): return(store.GetString(collectionPath, property.Name)); case Type t when t == typeof(int): return(store.GetInt32(collectionPath, property.Name)); case Type t when t == typeof(long): return(store.GetInt64(collectionPath, property.Name)); case Type t when t == typeof(bool): return(store.GetBoolean(collectionPath, property.Name)); } } return(null); }
public static T ReadSetting <T>(string propertyName) { CreatePropertyIfDoesNotExist <T>(propertyName); object value; switch (Type.GetTypeCode(typeof(T))) { case TypeCode.String: value = _userSettingsStore.GetString(CollectionName, propertyName); return((T)Convert.ChangeType(value, typeof(T))); case TypeCode.Boolean: value = _userSettingsStore.GetBoolean(CollectionName, propertyName); return((T)Convert.ChangeType(value, typeof(T))); case TypeCode.Int32: value = _userSettingsStore.GetInt32(CollectionName, propertyName); return((T)Convert.ChangeType(value, typeof(T))); case TypeCode.Int64: value = _userSettingsStore.GetInt64(CollectionName, propertyName); return((T)Convert.ChangeType(value, typeof(T))); case TypeCode.UInt32: value = _userSettingsStore.GetUInt32(CollectionName, propertyName); return((T)Convert.ChangeType(value, typeof(T))); case TypeCode.UInt64: value = _userSettingsStore.GetUInt64(CollectionName, propertyName); return((T)Convert.ChangeType(value, typeof(T))); default: value = _userSettingsStore.GetString(CollectionName, propertyName); return((T)Convert.ChangeType(value, typeof(T))); } }
//------ Last Extension Scan Time ------ public long GetLastExtensionScanTime() { return(UserSettingsStore.GetInt64(GENERAL_SETTINGS, LAST_EXTENSION_SCAN_TIME, 0L)); }