public frmMain() { InitializeComponent(); _progresStringBuilder = new StringBuilder(); btnImport.Enabled = true; _connectionStrings = GetConnectionStrings(); }
protected internal override void Start() { WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SharedConnectionWorkflowCommitWorkBatchService: Starting"); this.dbResourceAllocator = new DbResourceAllocator(base.Runtime, this.configParameters, this.unvalidatedConnectionString); if (this.transactionConnectionTable == null) { this.transactionConnectionTable = new Dictionary <Transaction, SharedConnectionInfo>(); } if (!this._ignoreCommonEnableRetries && (base.Runtime != null)) { NameValueConfigurationCollection commonParameters = base.Runtime.CommonParameters; if (commonParameters != null) { foreach (string str in commonParameters.AllKeys) { if (string.Compare("EnableRetries", str, StringComparison.OrdinalIgnoreCase) == 0) { this._enableRetries = bool.Parse(commonParameters[str].Value); break; } } } } base.Start(); }
public void SetElement_NoElementWithGivenName_Ok() { var collection = new NameValueConfigurationCollection(); collection["foo"] = new NameValueConfigurationElement("foo", "bar"); Assert.Equal("bar", collection["foo"].Value); }
/// <summary> /// Encode environment to byte array /// </summary> /// <param name="sd">indicating the string dictionary of environments</param> /// <returns>returns the byte array</returns> public static byte[] ToByteArray(NameValueConfigurationCollection sd) { IDictionary envs = Environment.GetEnvironmentVariables(); foreach (NameValueConfigurationElement pair in sd) { envs.Add(pair.Name, pair.Value); } string[] keys = new string[envs.Count]; string[] values = new string[envs.Count]; envs.Keys.CopyTo(keys, 0); envs.Values.CopyTo(values, 0); Array.Sort(keys, values, OrdinalCaseInsensitiveComparer.Default); StringBuilder builder = new StringBuilder(); for (int i = 0; i < envs.Count; i++) { builder.Append(keys[i]); builder.Append('='); builder.Append(values[i]); builder.Append('\0'); } builder.Append('\0'); return(Encoding.Unicode.GetBytes(builder.ToString())); }
public void Configure(NameValueConfigurationCollection parameters) { if (parameters != null) { foreach (NameValueConfigurationElement parameter in parameters) { _parameters.Add(parameter.Name, parameter.Value); SetParameter(parameter.Name, parameter.Value); } } List <string> notProvidedParameters = RequiredParameterNames.FindAll(x => string.IsNullOrWhiteSpace(_parameters[x])); if (notProvidedParameters != null && notProvidedParameters.Count > 0) { StringBuilder notProvidedParametersSB = new StringBuilder(); notProvidedParametersSB.AppendFormat("The following parameters are required by the class \"{0}\" and has not been provided: ", this.GetType().Name); foreach (string notProvidedParameter in notProvidedParameters) { notProvidedParametersSB.AppendFormat("{0}, ", notProvidedParameter); } throw new ConfigurationErrorsException(notProvidedParametersSB.Remove(notProvidedParametersSB.Length - 2, 2).Append(".").ToString()); } }
/// <summary> /// Private constructor /// </summary> private ConfigManager() { object expresslyConfigSection = null; try { expresslyConfigSection = ConfigurationManager.GetSection("expressly"); } catch (System.Exception ex) { throw new ConfigException("Unable to load 'expressly' section from *.config: " + ex.Message); } if (expresslyConfigSection == null) { throw new ConfigException( "Cannot parse *.Config file. Ensure you have configured the 'expressly' section correctly."); } NameValueConfigurationCollection settings = (NameValueConfigurationCollection)expresslyConfigSection.GetType().GetProperty("Settings").GetValue(expresslyConfigSection, null); this.configValues = new Dictionary <string, string>(); foreach (NameValueConfigurationElement setting in settings) { configValues.Add(setting.Name, setting.Value); } }
override protected internal void Start() { WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SharedConnectionWorkflowCommitWorkBatchService: Starting"); this.dbResourceAllocator = new DbResourceAllocator(this.Runtime, this.configParameters, this.unvalidatedConnectionString); if (this.transactionConnectionTable == null) { this.transactionConnectionTable = new Dictionary <Transaction, SharedConnectionInfo>(); } // // If we didn't find a local value for enable retries // check in the common section if ((!_ignoreCommonEnableRetries) && (null != base.Runtime)) { NameValueConfigurationCollection commonConfigurationParameters = base.Runtime.CommonParameters; if (commonConfigurationParameters != null) { // Then scan for connection string in the common configuration parameters section foreach (string key in commonConfigurationParameters.AllKeys) { if (string.Compare("EnableRetries", key, StringComparison.OrdinalIgnoreCase) == 0) { _enableRetries = bool.Parse(commonConfigurationParameters[key].Value); break; } } } } base.Start(); }
protected internal override void Start() { WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "DefaultWorkflowCommitWorkBatchService: Starting"); // // If we didn't find a local value for enable retries // check in the common section if ((!_ignoreCommonEnableRetries) && (null != base.Runtime)) { NameValueConfigurationCollection commonConfigurationParameters = base.Runtime.CommonParameters; if (commonConfigurationParameters != null) { // Then scan for connection string in the common configuration parameters section foreach (string key in commonConfigurationParameters.AllKeys) { if (string.Compare("EnableRetries", key, StringComparison.OrdinalIgnoreCase) == 0) { _enableRetries = bool.Parse(commonConfigurationParameters[key].Value); break; } } } } base.Start(); }
public void SetElement_IndexAndElementNameMismatch_ElementNameIsUsed() { var collection = new NameValueConfigurationCollection(); collection["foo"] = new NameValueConfigurationElement("fooMismatched", "bar"); Assert.Equal("bar", collection["fooMismatched"].Value); Assert.Null(collection["foo"]); }
public void Add_NullValue_Ok() { var collection = new NameValueConfigurationCollection(); var element = new NameValueConfigurationElement("foo", null); collection.Add(element); Assert.Null(collection["foo"].Value); }
public void Init(NameValueConfigurationCollection props) { Console.WriteLine("EventWriter.Init"); foreach (NameValueConfigurationElement prop in props) { Console.WriteLine("{0}={1}", prop.Name, prop.Value); } }
internal static T CreateConfigurableItem <T>(Type itemType, NameValueConfigurationCollection parameters) where T : ConfigurableBase { T configurableItem = Activator.CreateInstance(itemType) as T; configurableItem.Configure(parameters); return(configurableItem); }
public static void SetValue(string name, string value) { if (_values == null) { _values = new NameValueConfigurationCollection(); } _values.Add(new NameValueConfigurationElement(name, value)); }
public static void SetConnecitonString(string key, string connectionString) { if (_connectionString == null) { _connectionString = new NameValueConfigurationCollection(); } _connectionString.Add(new NameValueConfigurationElement(key, connectionString)); }
public void Value_AssignNewValue_Ok() { var collection = new NameValueConfigurationCollection(); var element = new NameValueConfigurationElement("foo", "foo"); collection.Add(element); collection["foo"].Value = "bar"; Assert.Equal("bar", collection["foo"].Value); }
public void Add_ElementWithExistingName_Throws() { var collection = new NameValueConfigurationCollection(); var element1 = new NameValueConfigurationElement("foo", "foo"); var element2 = new NameValueConfigurationElement("foo", "bar"); collection.Add(element1); Assert.Throws <ConfigurationErrorsException>(() => collection.Add(element2)); }
/// <summary> /// Converts the NameValueConfigurationCollection to a collection of key value pairs. /// </summary> /// <param name="collection">The name value configuration collection.</param> /// <returns>A collection of key value pairs.</returns> public static IEnumerable <KeyValuePair <string, string> > ToKeyValuePairs( this NameValueConfigurationCollection collection) { foreach (string key in collection.AllKeys) { NameValueConfigurationElement element = collection[key]; yield return(new KeyValuePair <string, string>(element.Name, element.Value)); } }
public void Clear_NotEmptyCollection_EmptyCollection() { var collection = new NameValueConfigurationCollection(); var element = new NameValueConfigurationElement("foo", "foo"); collection.Add(element); Assert.NotEmpty(collection); collection.Clear(); Assert.Empty(collection); }
public void Remove_ByName_ElementIsNull() { var collection = new NameValueConfigurationCollection(); var element = new NameValueConfigurationElement("foo", "foo"); collection.Add(element); Assert.Equal("foo", collection["foo"].Value); collection.Remove("foo"); Assert.Null(collection["foo"]); }
/// <summary> /// Private constructor /// </summary> private ConfigManager() { SDKConfigHandler configHandler = (SDKConfigHandler)ConfigurationManager.GetSection("paypal"); if (configHandler == null) { throw new ConfigException( "Cannot parse *.Config file. Ensure you have configured the 'paypal' section correctly."); } NameValueConfigurationCollection settings = configHandler.Settings; this.configValues = new Dictionary <string, string>(); foreach (NameValueConfigurationElement setting in settings) { configValues.Add(setting.Name, setting.Value); } int index = 0; foreach (ConfigurationElement element in configHandler.Accounts) { Account account = (Account)element; if (!string.IsNullOrEmpty(account.APIUserName)) { this.configValues.Add("account" + index + ".apiUsername", account.APIUserName); } if (!string.IsNullOrEmpty(account.APIPassword)) { this.configValues.Add("account" + index + ".apiPassword", account.APIPassword); } if (!string.IsNullOrEmpty(account.APISignature)) { this.configValues.Add("account" + index + ".apiSignature", account.APISignature); } if (!string.IsNullOrEmpty(account.APICertificate)) { this.configValues.Add("account" + index + ".apiCertificate", account.APICertificate); } if (!string.IsNullOrEmpty(account.PrivateKeyPassword)) { this.configValues.Add("account" + index + ".privateKeyPassword", account.PrivateKeyPassword); } if (!string.IsNullOrEmpty(account.CertificateSubject)) { this.configValues.Add("account" + index + ".subject", account.CertificateSubject); } if (!string.IsNullOrEmpty(account.ApplicationId)) { this.configValues.Add("account" + index + ".applicationId", account.ApplicationId); } index++; } }
private NameValueConfigurationCollection GetConnectionStrings() { NameValueConfigurationCollection connectionStrings = new NameValueConfigurationCollection(); for (int i = 0; i < ConfigurationManager.ConnectionStrings.Count; i++) { connectionStrings.Add(new NameValueConfigurationElement(ConfigurationManager.ConnectionStrings[i].Name, ConfigurationManager.ConnectionStrings[i].ConnectionString)); } return(connectionStrings); }
public static string GetValue(this NameValueConfigurationCollection collection, string key, string defaultValue) { var e = collection[key]; if (e == null) { return(defaultValue); } return(e.Value); }
public void Init(NameValueConfigurationCollection props) { Console.WriteLine("EventFormatter.Init"); foreach (NameValueConfigurationElement prop in props) { Console.WriteLine("{0}={1}", prop.Name, prop.Value); } if (props["format"] != null && !String.IsNullOrEmpty(props["format"].Value)) { _fieldId = props["format"].Value; } }
/// <summary> /// Initializes a new instance of the BrokerProcess class /// </summary> /// <param name="brokerFileName">indicating the broker file name</param> /// <param name="environments">indicating the environments</param> public BrokerProcess(string brokerFileName, NameValueConfigurationCollection environments) { this.startupInfo = new NativeMethods.STARTUPINFO(); this.startupInfo.cb = Marshal.SizeOf(typeof(NativeMethods.STARTUPINFO)); this.processInfo = new NativeMethods.PROCESS_INFORMATION(); string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string fileName = Path.Combine(path, brokerFileName); StringBuilder commandLine = null; TraceHelper.TraceEvent(TraceEventType.Information, "[BrokerProcess] Start broker process, FileName = {0}", fileName); IntPtr environmentPtr; if (environments != null) { this.environmentHandle = GCHandle.Alloc(ToByteArray(environments), GCHandleType.Pinned); environmentPtr = this.environmentHandle.AddrOfPinnedObject(); } else { environmentPtr = IntPtr.Zero; } if (!NativeMethods.CreateProcess(fileName, commandLine, IntPtr.Zero, IntPtr.Zero, true, creationFlags, environmentPtr, path, ref this.startupInfo, out this.processInfo)) { int errorCode = Marshal.GetLastWin32Error(); TraceHelper.TraceEvent(TraceEventType.Error, "[BrokerProcess] Start broker process failed: {0}", errorCode); ThrowHelper.ThrowSessionFault(SOAFaultCode.Broker_FailedToStartBrokerServiceProcess, SR.FailedToStartBrokerServiceProcess, errorCode.ToString()); } SafeWaitHandle handle = new SafeWaitHandle(this.processInfo.hProcess, false); if (handle.IsClosed || handle.IsInvalid) { TraceHelper.TraceEvent(TraceEventType.Error, "[BrokerProcess] Start broker process failed because the process handle is invalid or closed."); ThrowHelper.ThrowSessionFault(SOAFaultCode.Broker_FailedToStartBrokerServiceProcess, SR.FailedToStartBrokerServiceProcess, "Handle is invalid or closed"); } string uniqueWaitHandleName = BuildUniqueWaitHandle(this.Id, out this.readyWaitHandle); WaitOrTimerCallback brokerProcessReadyCallback = new ThreadHelper <object>(new WaitOrTimerCallback(this.BrokerProcessReadyCallback)).WaitOrTimerCallbackRoot; WaitOrTimerCallback processExitCallback = new ThreadHelper <object>(new WaitOrTimerCallback(this.ProcessExitCallback)).WaitOrTimerCallbackRoot; this.exitWaitHandle = new ManualResetEvent(false); this.exitWaitHandle.SafeWaitHandle = handle; // Register broker process exit callback ThreadPool.RegisterWaitForSingleObject(this.exitWaitHandle, processExitCallback, null, -1, true); // Register callback to be raised when broker process opened service host and is ready to initialize. ThreadPool.RegisterWaitForSingleObject(this.readyWaitHandle, brokerProcessReadyCallback, null, readyTimeout, true); }
private string FindField(NameValueConfigurationCollection cols, string key) { foreach (string name in cols.AllKeys) { if (name == key) { return(cols[name].Value); } } return(string.Empty); }
/// <summary> /// Private constructor /// </summary> private ConfigManager() { configHandler = (SDKConfigHandler)ConfigurationManager.GetSection("paypal"); if (configHandler == null) { throw new ConfigException("Cannot parse *.Config file. Ensure you have configured the 'paypal' section correctly."); } this.configValues = new Dictionary <string, string>(); NameValueConfigurationCollection settings = this.configHandler.Settings; foreach (string key in settings.AllKeys) { this.configValues.Add(settings[key].Name, settings[key].Value); } int i = 0; foreach (ConfigurationElement elem in this.configHandler.Accounts) { Account account = (Account)elem; if (account.APIUsername != null && account.APIUsername != "") { this.configValues.Add("account" + i + ".apiUsername", account.APIUsername); } if (account.APIPassword != null && account.APIPassword != "") { this.configValues.Add("account" + i + ".apiPassword", account.APIPassword); } if (account.APISignature != null && account.APISignature != "") { this.configValues.Add("account" + i + ".apiSignature", account.APISignature); } if (account.APICertificate != null && account.APICertificate != "") { this.configValues.Add("account" + i + ".apiCertificate", account.APICertificate); } if (account.PrivateKeyPassword != null && account.PrivateKeyPassword != "") { this.configValues.Add("account" + i + ".privateKeyPassword", account.PrivateKeyPassword); } if (account.CertificateSubject != null && account.CertificateSubject != "") { this.configValues.Add("account" + i + ".subject", account.CertificateSubject); } if (account.ApplicationId != null && account.ApplicationId != "") { this.configValues.Add("account" + i + ".applicationId", account.ApplicationId); } i++; } }
public void ShouldSetFalseValue_WhenItsNotConfigured() { var appSettings = new NameValueConfigurationCollection { new NameValueConfigurationElement("JobLogger:LogToFile", "true") }; var loggerConfiguration = new JobLoggerConfiguration(appSettings); Assert.True(loggerConfiguration.LogToFile); Assert.False(loggerConfiguration.LogToConsole); Assert.False(loggerConfiguration.LogToDb); }
public JobLoggerConfiguration(NameValueConfigurationCollection appSettingsCollection) { LogToDb = TryGet(appSettingsCollection, "LogToDB"); LogToFile = TryGet(appSettingsCollection, "LogToFile"); LogToConsole = TryGet(appSettingsCollection, "LogToConsole"); StoragePath = appSettingsCollection["JobLogger:StoragePath"]?.Value; ConnectionString = appSettingsCollection["JobLogger:ConnectionString"]?.Value; if (!LogToDb && !LogToConsole && !LogToFile) { throw new ConfigurationErrorsException("Invalid Configuration. You should choose at least one destination to log"); } }
private static bool TryGet(NameValueConfigurationCollection collection, string keyName) { var rawValue = collection[$"JobLogger:{keyName}"]; if (rawValue == null || string.IsNullOrWhiteSpace(rawValue.Value)) { return(false); } var canParse = bool.TryParse(rawValue.Value, out var result); return(canParse && result); }
public void Init(NameValueConfigurationCollection props) { _filteredTypes = new List <Message>(); var types = props[MESSAGE_TYPES_PARAMETER_NAME].Value.Split(';'); foreach (var type in types) { if (Enum.IsDefined(typeof(Message), type)) { _filteredTypes.Add((Message)Enum.Parse(typeof(Message), type)); } } }