Ejemplo n.º 1
0
 /// <summary>
 /// Injects the properties.
 /// </summary>
 /// <param name="extension">The extension.</param>
 protected void InjectProperties(BootstrapperExtension <T> extension)
 {
     Log.DebugFormat(CultureInfo.InvariantCulture, "Injecting configuration properties of type {0}", extension.GetType().Name);
     InjectConfigurationProperties(extension, typeof(ConfigurationDependencyAttribute), p => this.configurationManager.AppSettings[p.Name]);
     InjectConfigurationProperties(extension, typeof(ConnectionStringDependencyAttribute), p => this.configurationManager.ConnectionStrings[p.Name].ConnectionString);
     Log.DebugFormat(CultureInfo.InvariantCulture, "Add extension instance of type {0} to cache", extension.GetType().Name);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Injects the configuration properties.
        /// </summary>
        /// <param name="extension">The bootstrapper extension.</param>
        /// <param name="attributeType">Type of the attribute.</param>
        /// <param name="func">The func to access the configuration value.</param>
        private static void InjectConfigurationProperties(BootstrapperExtension <T> extension, Type attributeType, Func <PropertyInfo, string> func)
        {
            var query = from propertyInfo in extension.GetType().GetProperties()
                        let p = propertyInfo.GetCustomAttributes(true)
                                where p.Any(a => a.GetType().IsAssignableFrom(attributeType))
                                select propertyInfo;

            foreach (var propertyInfo in query)
            {
                try
                {
                    if (propertyInfo.GetCustomAttributes(true).Any(a => a.GetType().IsAssignableFrom(attributeType)))
                    {
                        var converter = TypeDescriptor.GetConverter(propertyInfo.PropertyType);
                        var value     = converter.ConvertFromInvariantString(func(propertyInfo));
                        Log.DebugFormat(CultureInfo.InvariantCulture, "Injecting property {0} to value {1}", propertyInfo.Name, value);
                        propertyInfo.SetValue(extension, value, null);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(string.Format(CultureInfo.InvariantCulture, "Error while inject the property {0}", propertyInfo.Name), ex);
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Adds the extension to cache.
 /// </summary>
 /// <param name="extension">The extension.</param>
 protected void AddExtensionToCache(BootstrapperExtension <T> extension)
 {
     Log.DebugFormat(CultureInfo.InvariantCulture, "Adding Extension of type {0}", extension.GetType().Name);
     this.extensionCache.Add(extension);
     Log.DebugFormat(CultureInfo.InvariantCulture, "Extension of type {0} added successfull", extension.GetType().Name);
 }