Exemplo n.º 1
0
        /// <summary>
        /// Initializes the specified throw exception.
        /// </summary>
        /// <param name="throwException">if set to <c>true</c> [throw exception].</param>
        /// <returns></returns>
        protected override Dictionary <string, RuntimeConfigurationItem> Initialize(bool throwException = false)
        {
            Dictionary <string, RuntimeConfigurationItem> result = new Dictionary <string, RuntimeConfigurationItem>();

            try
            {
                SqlConnectionString.CheckEmptyString(nameof(SqlConnectionString));

                using (var controller = new ConfigurationRawItemAccessController(SqlConnectionString))
                {
                    var rawConfigurations = controller.GetSystemConfigurations();

                    foreach (var item in rawConfigurations)
                    {
                        var runtimeConfigurationItem = RuntimeConfigurationItem.FromRaw(SourceAssembly, nameof(SqlConfigurationReader), CoreComponentVersion, item);
                        result.AddIfBothNotNull(runtimeConfigurationItem?.Key, runtimeConfigurationItem);
                    }
                }
            }
            catch (Exception ex)
            {
                if (throwException)
                {
                    throw ex.Handle();
                }
            }

            return(result);
        }
        /// <summary>
        /// Fills the object collection.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="coreComponentVersion">The core component version.</param>
        /// <param name="configurationRawItem">The configuration raw item.</param>
        /// <param name="sourceAssembly">The source assembly.</param>
        /// <param name="readerType">Type of the reader.</param>
        /// <param name="throwException">if set to <c>true</c> [throw exception].</param>
        protected static void FillObjectCollection(IDictionary <string, RuntimeConfigurationItem> container, Version coreComponentVersion, ConfigurationRawItem configurationRawItem, string sourceAssembly, string readerType, bool throwException = false)
        {
            try
            {
                container.CheckNullObject(nameof(container));
                configurationRawItem.CheckNullObject(nameof(configurationRawItem));
                configurationRawItem.Key.CheckEmptyString(nameof(configurationRawItem.Key));

                var runtimeConfigurationItem = RuntimeConfigurationItem.FromRaw(sourceAssembly, readerType, coreComponentVersion, configurationRawItem);
                runtimeConfigurationItem.CheckNullObject(nameof(runtimeConfigurationItem));
                container.Merge(runtimeConfigurationItem.Key, runtimeConfigurationItem);
            }
            catch (Exception ex)
            {
                if (throwException)
                {
                    throw ex.Handle(data: new { coreComponentVersion, configurationRawItem, sourceAssembly, readerType });
                }
            }
        }