/// <summary>
        /// Updates the configuration.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        public void UpdateConfiguration <T>(string key, T value)
        {
            try
            {
                key.CheckEmptyString(nameof(key));

                using (var controller = string.IsNullOrWhiteSpace(SqlConnection) ? new ConfigurationRawItemAccessController() : new ConfigurationRawItemAccessController(SqlConnection))
                {
                    var rawItem = new ConfigurationRawItem
                    {
                        Key   = key,
                        Type  = typeof(T).GetFullName(),
                        Value = (typeof(T) == typeof(string) ? value.ToString() : value.ToJson(false))
                    };

                    controller.UpdateSystemConfiguration(rawItem);
                }

                TriggerReload();
            }
            catch (Exception ex)
            {
                throw ex.Handle();
            }
        }
Exemple #2
0
        /// <summary>
        /// Deletes the configuration.
        /// </summary>
        /// <param name="key">The key.</param>
        public void DeleteConfiguration(string key)
        {
            try
            {
                key.CheckEmptyString(nameof(key));

                using (var controller = string.IsNullOrWhiteSpace(SqlConnection) ? new ConfigurationRawItemAccessController() : new ConfigurationRawItemAccessController(SqlConnection))
                {
                    var rawItem = new ConfigurationRawItem {
                    };

                    controller.DeleteSystemConfiguration(key);
                }
            }
            catch (Exception ex)
            {
                throw ex.Handle(key);
            }
        }
        /// <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 });
                }
            }
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LocalConfigurationRawItem"/> class.
 /// </summary>
 /// <param name="item">The item.</param>
 internal LocalConfigurationRawItem(ConfigurationRawItem item)
     : base(item)
 {
 }
        /// <summary>
        /// Froms the raw.
        /// </summary>
        /// <param name="sourceAssembly">The source assembly.</param>
        /// <param name="readerType">Type of the reader.</param>
        /// <param name="coreComponentVersion">The core component version.</param>
        /// <param name="configurationItem">The configuration item.</param>
        /// <returns></returns>
        public static RuntimeConfigurationItem FromRaw(string sourceAssembly, string readerType, Version coreComponentVersion, ConfigurationRawItem configurationItem)
        {
            try
            {
                configurationItem.CheckNullObject(nameof(configurationItem));
                configurationItem.Type.CheckEmptyString(nameof(configurationItem.Type));

                var result = new RuntimeConfigurationItem(configurationItem)
                {
                    Assembly    = sourceAssembly,
                    ReaderType  = readerType,
                    RuntimeType = ReflectionExtension.SmartGetType(configurationItem.Type, false) ?? ReflectionExtension.SmartGetType(configurationItem.Type, true)
                };

                result.IsActive = JudgeActive(coreComponentVersion, result.MinComponentVersionRequired, result.MaxComponentVersionLimited);
                result.Value    = RawStringToObject(configurationItem.Value, result.RuntimeType);

                return(result);
            }
            catch (Exception ex)
            {
                throw ex.Handle();
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="RuntimeConfigurationItem"/> class.
 /// </summary>
 /// <param name="configurationItem">The configuration item.</param>
 private RuntimeConfigurationItem(ConfigurationRawItem configurationItem) : base(configurationItem)
 {
 }