public CredentialSettings(IObjectData data) : base(data) { // prepare settings string endPoint = Defaults.EndPoint; string userName = Defaults.UserName; string password = string.Empty; CredentialPersistence persistence = Defaults.Persistence; bool enableAssumptionMode = Defaults.EnableAssumptionMode; if (data != null) { // get settings from data endPoint = data.GetStringValue(SettingNames.EndPoint, endPoint); userName = data.GetStringValue(SettingNames.UserName, userName); password = data.GetValue(SettingNames.ProtectedPassword, password, ExtractPasswordValue); persistence = (CredentialPersistence)data.GetEnumValue(SettingNames.Persistence, persistence, typeof(CredentialPersistence)); enableAssumptionMode = data.GetBooleanValue(SettingNames.EnableAssumptionMode, enableAssumptionMode); } // set settings try { // may throw ArgumentException for an invalid value this.EndPoint = endPoint; this.UserName = userName; this.Password = password; this.Persistence = persistence; this.EnableAssumptionMode = enableAssumptionMode; } catch (Exception exception) { throw new FormatException(exception.Message); } return; }
public ListenerSettings(IObjectData data) : base(data) { // prepare settings IPAddress address = Defaults.Address; int port = Defaults.Port; int backlog = Defaults.Backlog; if (data != null) { // get settings from data address = data.GetValue(SettingNames.Address, address, ExtractIPAddressValue); port = data.GetInt32Value(SettingNames.Port, port); backlog = data.GetInt32Value(SettingNames.Backlog, backlog); } // set settings try { // may throw ArgumentException for an invalid value this.Address = address; this.Port = port; this.Backlog = backlog; } catch (Exception exception) { throw new FormatException(exception.Message); } return; }
public CommandSettings(IObjectData data) : base(data) { // prepare settings int initialSetupLevel = Defaults.InitialSetupLevel; TraceLevel logLevel = Defaults.LogLevel; CultureInfo culture = null; bool noLogo = Defaults.NoLogo; CredentialSettings[] credentials = null; SystemSettingsSwitcherSettings systemSettingsSwitcher = null; GUISettings gui = null; ProxySettings proxy = null; if (data != null) { // get settings from data initialSetupLevel = data.GetInt32Value(SettingNames.InitialSetupLevel, Defaults.InitialSetupLevel); logLevel = (TraceLevel)data.GetEnumValue(SettingNames.LogLevel, logLevel, typeof(TraceLevel)); culture = data.GetValue(SettingNames.Culture, culture, ExtractCultureInfoValue); noLogo = data.GetBooleanValue(SettingNames.NoLogo, noLogo); credentials = data.GetObjectArrayValue(SettingNames.Credentials, credentials, CreateCredentialSettings); systemSettingsSwitcher = data.GetObjectValue(SettingNames.SystemSettingsSwitcher, systemSettingsSwitcher, this.CreateSystemSettingsSwitcherSettings); proxy = data.GetObjectValue(SettingNames.Proxy, proxy, this.CreateProxySettings); gui = data.GetObjectValue(SettingNames.GUI, gui, this.CreateGUISettings); } if (systemSettingsSwitcher == null) { // SystemSettingsSwitcher cannot be null systemSettingsSwitcher = CreateSystemSettingsSwitcherSettings(null); } if (proxy == null) { // Proxy cannot be null proxy = CreateProxySettings(null); } if (gui == null) { // GUI cannot be null gui = CreateGUISettings(null); } // set settings try { // may throw ArgumentException for an invalid value this.InitialSetupLevel = initialSetupLevel; this.LogLevel = logLevel; this.Culture = culture; this.NoLogo = noLogo; this.Credentials = credentials; this.SystemSettingsSwitcher = systemSettingsSwitcher; this.Proxy = proxy; this.GUI = gui; } catch (Exception exception) { throw new FormatException(exception.Message); } return; }
public static T?GetValue <T>(this IObjectData data, string name, Func <IObjectDataValue, T> extractValue) where T : struct { // argument checks if (data == null) { throw new ArgumentNullException(nameof(data)); } if (extractValue == null) { throw new ArgumentNullException(nameof(extractValue)); } // get the value IObjectDataValue value = data.GetValue(name); return((value == null) ? null : new Nullable <T>(extractValue(value))); }
public static Out GetValue <In, Out>(this IObjectData data, string name, In defaultValue, Func <IObjectDataValue, Out> extractValue) where Out : In { // argument checks if (data == null) { throw new ArgumentNullException(nameof(data)); } if (extractValue == null) { throw new ArgumentNullException(nameof(extractValue)); } // get the value IObjectDataValue value = data.GetValue(name); return((value == null) ? (Out)defaultValue : extractValue(value)); }
public SystemSettingsForWindows(IObjectData data) : base(data) { // prepare settings string autoConfigURL = null; int? proxyEnable = null; string proxyServer = null; string proxyOverride = null; bool autoDetect = false; string httpProxyEnvironmentVariable = null; string httpsProxyEnvironmentVariable = null; if (data != null) { // get settings from data autoConfigURL = data.GetStringValue(SettingNames.AutoConfigURL, null); proxyEnable = data.GetValue(SettingNames.ProxyEnable, ObjectDataExtension.ExtractInt32Value); proxyServer = data.GetStringValue(SettingNames.ProxyServer, null); proxyOverride = data.GetStringValue(SettingNames.ProxyOverride, null); autoDetect = data.GetBooleanValue(SettingNames.AutoDetect, false); httpProxyEnvironmentVariable = data.GetStringValue(SettingNames.HttpProxyEnvironmentVariable, null); httpsProxyEnvironmentVariable = data.GetStringValue(SettingNames.HttpsProxyEnvironmentVariable, null); } // set settings try { // may throw ArgumentException for an invalid value this.AutoConfigURL = autoConfigURL; this.ProxyEnable = proxyEnable; this.ProxyServer = proxyServer; this.ProxyOverride = proxyOverride; this.AutoDetect = autoDetect; this.HttpProxyEnvironmentVariable = httpProxyEnvironmentVariable; this.HttpsProxyEnvironmentVariable = httpsProxyEnvironmentVariable; } catch (Exception exception) { throw new FormatException(exception.Message); } return; }