Beispiel #1
0
        public AppSettingsConfigurationSource(IConfigurationOptions options)
        {
            Config = new T();
            var props = typeof(T).GetProperties();

            foreach (var prop in props)
            {
                string name;
                var    attrs = prop.GetCustomAttributes(typeof(ConfigurationPropertyAttribute), true);
                if (attrs.Length == 1)
                {
                    name = ((ConfigurationPropertyAttribute)attrs[0]).Name;
                }
                else
                {
                    name = options.ConvertPropertyNameToAppSettingsName(prop.Name);
                }

                var converted = TypeDescriptor
                                .GetConverter(prop.PropertyType)
                                .ConvertFromString(
                    ConfigurationManager.AppSettings[name]);
                prop.SetValue(Config, converted, null);
            }
        }
Beispiel #2
0
 public AutofacGlassFactoryBuilder(IConfigurationOptions options, IContainer container,
                                   Func <ILookup <Type, GlassInterfaceMetadata>, IGlassTemplateCacheService> templateCacheFactory,
                                   IGlassTypesLoader typeLoader, IImplementationFactory implFactory)
     : base(options)
 {
     if (container == null)
     {
         throw new ArgumentNullException(nameof(container));
     }
     if (templateCacheFactory == null)
     {
         throw new ArgumentNullException(nameof(templateCacheFactory));
     }
     if (typeLoader == null)
     {
         throw new ArgumentNullException(nameof(typeLoader));
     }
     if (implFactory == null)
     {
         throw new ArgumentNullException(nameof(implFactory));
     }
     _container            = container;
     _templateCacheFactory = templateCacheFactory;
     _typeLoader           = typeLoader;
     _implFactory          = implFactory;
 }
Beispiel #3
0
        public static IConfigurationFactory Create(IConfigurationOptions options = null)
        {
            // Construct the IConfiguration
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json");

            var configuration = (IConfiguration)builder.Build();

            // Configure the core pieces
            var keynameResolver     = new KeyNameResolver();
            var parserResolver      = new ParserResolver();
            var configResolver      = new ConfigurationReaderResolver();
            var constructorResolver = new ValueConstructorResolver();

            options = options ?? ConfigurationOptions.Create();

            var configuratinFactory = new ConfigurationFactory(configuration,
                                                               options,
                                                               keynameResolver,
                                                               configResolver,
                                                               parserResolver,
                                                               constructorResolver);

            return(configuratinFactory);
        }
 public DefaultGlassFactoryBuilder(IConfigurationOptions options, Func <ISitecoreService> serviceFactory) : base(options)
 {
     if (serviceFactory == null)
     {
         throw new ArgumentNullException(nameof(serviceFactory));
     }
     _serviceFactory = serviceFactory;
 }
 protected AbstractGlassFactoryBuilder(IConfigurationOptions options)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     Options = options;
 }
Beispiel #6
0
 public WebClientFactory(ILogger <WebClientFactory> logger,
                         IDownloadProgressCache downloadProgressCache,
                         IConfigurationOptions configurationService)
 {
     _logger = logger;
     _downloadProgressCache = downloadProgressCache;
     _configurationService  = configurationService;
 }
Beispiel #7
0
        public IKeyName Resolve(Type type, IConfigurationOptions configurationOptions)
        {
            var autoResolvedKeyName = ResolveInternally(type, configurationOptions);

            // Try to resolve a custom key name from options
            var customKeyName = configurationOptions.CustomKeyName?.Invoke(type, autoResolvedKeyName);

            return(customKeyName ?? autoResolvedKeyName);
        }
Beispiel #8
0
        public IValueConstructor Resolve(Type configType, IConfigurationOptions configurationOptions)
        {
            var autoResolvedConstructor = ResolveInternally(configType, configurationOptions);

            // Try to resolve a custom constructor from options
            var customConstructor = configurationOptions.CustomConstructor?.Invoke(configType, autoResolvedConstructor);

            return(customConstructor ?? autoResolvedConstructor);
        }
        public void TestSetup()
        {
            _mockOptions = Substitute.For <IConfigurationOptions>();
            _mockOptions.Assemblies.Returns(new[] { Assembly.GetAssembly(GetType()).FullName });

            _mockService = Substitute.For <ISitecoreService>();

            _builder = new DefaultGlassFactoryBuilder(_mockOptions, () => _mockService);
        }
Beispiel #10
0
        public IParser Resolve(Type configType, IConfigurationOptions configurationOptions)
        {
            var autoResolvedParser = ResolveInternally(configType, configurationOptions);

            // Try to resolve a custom parser from options
            var customParser = configurationOptions.CustomParser?.Invoke(configType, autoResolvedParser);

            return(customParser ?? autoResolvedParser);
        }
        public IConfigurationReader Resolve(Type type, IConfigurationOptions configurationOptions)
        {
            var autoResolvedReader = ResolveInternally(type, configurationOptions);

            // Try to resolve a custom reader from options
            var customReader = configurationOptions.CustomReader?.Invoke(type, autoResolvedReader);

            return(customReader ?? autoResolvedReader);
        }
 public DownloadProgressProvider(ILogger <DownloadProgressProvider> logger,
                                 IDownloadProgressCache downloadProgressCache,
                                 IConfigurationOptions configurationService,
                                 ITextProvider textProvider)
 {
     _logger = logger;
     _downloadProgressCache = downloadProgressCache;
     _configurationService  = configurationService;
     _textProvider          = textProvider;
 }
Beispiel #13
0
        public WebClient(IDownloadProgressCache progressCache,
                         IConfigurationOptions configurationService)
        {
            _progressCache        = progressCache;
            _configurationService = configurationService;

            if (!string.IsNullOrEmpty(_configurationService.User) && !string.IsNullOrEmpty(_configurationService.Password))
            {
                Credentials = new System.Net.NetworkCredential(_configurationService.User, _configurationService.Password);
            }
        }
        public static object GetSetting(Type type, IConfiguration configuration, IConfigurationOptions options = null)
        {
            if (type.GetConfigurationSettingType() == ConfigurationSettingType.None)
            {
                throw new ArgumentException($"{type} is not a Configuration Setting type.", nameof(type));
            }

            var factory = Create(configuration, options);

            return(factory.CreateConfigurationSetting(type));
        }
Beispiel #15
0
        public void TestSetup()
        {
            _mockOptions = Substitute.For <IConfigurationOptions>();
            _mockOptions.Assemblies.Returns(new[] { Assembly.GetAssembly(GetType()).FullName });
            _mockContainer = Substitute.For <IContainer>();

            _mockImplFactory = Substitute.For <IImplementationFactory>();
            _mockCache       = Substitute.For <IGlassTemplateCacheService>();
            _mockTypeLoader  = Substitute.For <IGlassTypesLoader>();

            _builder = new AutofacGlassFactoryBuilder(_mockOptions, _mockContainer, lookup => _mockCache, _mockTypeLoader, _mockImplFactory);
        }
Beispiel #16
0
 public FileDownloader(ILogger <FileDownloader> logger,
                       IWebClientFactory webClientFactory,
                       IConfigurationOptions configuration,
                       ILinksCache linksCache,
                       IDownloadProgressCache downloadProgressCache,
                       INotificationService notificationService)
 {
     _logger                = logger;
     _webClientFactory      = webClientFactory;
     _configuration         = configuration;
     _linksCache            = linksCache;
     _downloadProgressCache = downloadProgressCache;
     _notificationService   = notificationService;
 }
        public DownloadProgressMonitor(ILogger <DownloadProgressMonitor> logger,
                                       IDownloadProgressProvider downloadProgressProvider,
                                       IConfigurationOptions configurationService,
                                       IDownloadProgressCache downloadProgressCache,
                                       ITextProvider textProvider)
        {
            _logger = logger;
            _downloadProgressProvider = downloadProgressProvider;
            _downloadProgressCache    = downloadProgressCache;
            _textProvider             = textProvider;

            _progressTimer          = new Timer(TimeSpan.FromSeconds(configurationService.MonitorPeriodInSecond).TotalMilliseconds);
            _progressTimer.Elapsed += ProgressTimer_Elapsed;
        }
        public IConfigurationReader ResolveInternally(Type type, IConfigurationOptions configurationOptions)
        {
            if (type.GetConfigurationSettingType() == ConfigurationSettingType.GenericType)
            {
                var genericType = type.GetGenericTypeOfConfigurationSetting();

                return(genericType.IsValueType
                    ? GenericValueTypeConfigurationReader
                    : GenericNonValueTypeConfigurationReader);
            }
            else
            {
                return(ComplexTypeConfigurationReader);
            }
        }
        public SimpleAuthenticationController(IAuthenticationCallbackProvider callbackProvider,
                                              ICache cache,
                                              IConfigurationOptions configurationOptions)
        {
            if (callbackProvider == null)
            {
                throw new ArgumentNullException("callbackProvider");
            }

            _callbackProvider     = callbackProvider;
            _cache                = cache;                // Can be null / not provided.
            _configurationOptions = configurationOptions; // Can be null / not provided.

            _authenticationProviderFactory = new AuthenticationProviderFactory();
        }
        public SimpleAuthenticationController(IAuthenticationCallbackProvider callbackProvider,
            ICache cache,
            IConfigurationOptions configurationOptions)
        {
            if (callbackProvider == null)
            {
                throw new ArgumentNullException("callbackProvider");
            }

            _callbackProvider = callbackProvider;
            _cache = cache; // Can be null / not provided.
            _configurationOptions = configurationOptions; // Can be null / not provided.

            _authenticationProviderFactory = new AuthenticationProviderFactory();
        }
        public void Configure(IConfigurationOptions configurationOptions)
        {
            if (configurationOptions is not DatabaseConfigurationOptions)
            {
                throw new ArgumentException($"Invalid IConfigurationsOptions argument; got '{configurationOptions.GetType()}' instead.");
            }

            var configOptions  = configurationOptions as DatabaseConfigurationOptions;
            var optionsBuilder = new DbContextOptionsBuilder <StoreManagerContext>();

            optionsBuilder.UseSqlServer(configOptions.ConnectionString);
            optionsBuilder.LogTo(configOptions.Logger.Log, LogLevel.Information);

            var contextOptions = optionsBuilder.Options;

            _interfacerManager = new DbSetInterfacerManager(contextOptions);
        }
Beispiel #22
0
        private IKeyName ResolveInternally(Type type, IConfigurationOptions configurationOptions)
        {
            var prefix = string.Empty;

            // Try to resolve via SettingInfo attribute
            var attribute = type.CustomAttributes.SingleOrDefault(c => c.AttributeType == typeof(SettingInfo));

            if (attribute?.NamedArguments != null)
            {
                var keyName = attribute.NamedArguments.SingleOrDefault(a => a.MemberName == nameof(SettingInfo.Key));
                var value   = keyName.TypedValue.Value;
                return(new KeyName(prefix, value.ToString()));
            }

            // Revert to type name
            return(new KeyName(prefix, type.Name));
        }
Beispiel #23
0
        public IValueConstructor ResolveInternally(Type configType, IConfigurationOptions configurationOptions)
        {
            var settingType = configType.GetConfigurationSettingType();

            switch (settingType)
            {
            case ConfigurationSettingType.ComplexType:
                return(ComplexTypeValueConstructor);

            case ConfigurationSettingType.GenericType:
                return(GenericTypeValueConstructor);

            case ConfigurationSettingType.None:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(null);
        }
        private static IConfigurationFactory Create(IConfiguration configuration, IConfigurationOptions options = null)
        {
            configuration.EnsureNotNull(nameof(configuration));

            // Configure the core pieces
            var keynameResolver     = new KeyNameResolver();
            var parserResolver      = new ParserResolver();
            var configResolver      = new ConfigurationReaderResolver();
            var constructorResolver = new ValueConstructorResolver();

            options = options ?? ConfigurationOptions.Create();

            var configuratinFactory = new ConfigurationFactory(configuration,
                                                               options,
                                                               keynameResolver,
                                                               configResolver,
                                                               parserResolver,
                                                               constructorResolver);

            return(configuratinFactory);
        }
Beispiel #25
0
        public static IConfigurationOptions WithGlobalPrefix(this IConfigurationOptions configurationOptions,
                                                             string prefix,
                                                             Type[] onlyForTheseTypes = null,
                                                             Type[] exceptTheseTypes  = null)
        {
            ConfigurationOptionDelegates.CustomKeyNameFunc keyNameResolverFunc = (type, name) =>
            {
                if (onlyForTheseTypes != null && !onlyForTheseTypes.Contains(type))
                {
                    return(name);
                }

                if (exceptTheseTypes != null && exceptTheseTypes.Contains(type))
                {
                    return(name);
                }

                return(new KeyName(prefix, name.QualifiedKeyName));
            };

            return(configurationOptions.WithNamingScheme(keyNameResolverFunc));
        }
Beispiel #26
0
        public static IConfigurationOptions WithConstructor(this IConfigurationOptions configurationOptions,
                                                            ConfigurationOptionDelegates.CustomConstructorFunc resolverFunction)
        {
            ConfigurationOptionDelegates.CustomConstructorFunc currentResolverFunc = null;

            currentResolverFunc = configurationOptions.CustomConstructor;
            if (currentResolverFunc == null)
            {
                configurationOptions.CustomConstructor = resolverFunction;
            }
            else
            {
                // Chain the functions
                configurationOptions.CustomConstructor = (type, constructor) =>
                {
                    var customConstructor = currentResolverFunc.Invoke(type, constructor);
                    return(resolverFunction.Invoke(type, customConstructor));
                };
            }

            return(configurationOptions);
        }
        public SimpleAuthenticationModule(IAuthenticationCallbackProvider callbackProvider, IConfigurationOptions configurationOptions)
        {
            _callbackProvider = callbackProvider;
            _authenticationProviderFactory = new AuthenticationProviderFactory();
            _configurationOptions = configurationOptions;

            // Define the routes and how they are handled.
            Get[RedirectRoute] = parameters => RedirectToProvider(parameters);
            Post[RedirectRoute] = parameters => RedirectToProvider(parameters);
            Get[CallbackRoute] = parameters => AuthenticateCallback();

            // If no Cache type is provided, we'll use a Session as the default.
            Before += context =>
            {
                if (Cache == null)
                {
                    Cache = new SessionCache(context.Request.Session);
                }

                return null;
            };
        }
Beispiel #28
0
        public static ServiceProvider SetupConfigurationDependencies(this IConfiguration configuration,
                                                                     Assembly[] assemblies,
                                                                     IConfigurationOptions configurationOptions = null)
        {
            // Configure your DI Container
            // We are using 'Microsoft.Extensions.DependencyInjection' in this example
            // but you can use your favourite one like Autofac, StructureMap, Ninject etc

            var services = new ServiceCollection();

            // Add single IConfiguration
            services.AddSingleton(configuration);

            // Add configuration options instance
            configurationOptions = configurationOptions ?? ConfigurationOptions.Create();
            services.AddSingleton <IConfigurationOptions>((s) => configurationOptions);

            // Add required resolvers
            services.AddSingleton <IResolver <IKeyName>, KeyNameResolver>();
            services.AddSingleton <IResolver <IParser>, ParserResolver>();
            services.AddSingleton <IResolver <IConfigurationReader>, ConfigurationReaderResolver>();
            services.AddSingleton <IResolver <IValueConstructor>, ValueConstructorResolver>();

            // Add configuration factory
            services.AddSingleton <IConfigurationFactory, ConfigurationFactory>();

            var settingTypes = GetConfigurationSettings(assemblies);

            foreach (var settingType in settingTypes)
            {
                services.AddSingleton(settingType, (s) =>
                {
                    var factory = s.GetService <IConfigurationFactory>();
                    return(factory.CreateConfigurationSetting(settingType));
                });
            }

            return(services.BuildServiceProvider());
        }
Beispiel #29
0
        public static IConfigurationOptions WithNamingScheme(this IConfigurationOptions configurationOptions,
                                                             ConfigurationOptionDelegates.CustomKeyNameFunc resolverFunction)
        {
            ConfigurationOptionDelegates.CustomKeyNameFunc currentResolverFunc = null;

            currentResolverFunc = configurationOptions.CustomKeyName;
            if (currentResolverFunc == null)
            {
                configurationOptions.CustomKeyName = resolverFunction;
            }
            else
            {
                // Chain the functions
                configurationOptions.CustomKeyName = (type, name) =>
                {
                    var customName = currentResolverFunc.Invoke(type, name);
                    return(resolverFunction.Invoke(type, customName));
                };
            }

            return(configurationOptions);
        }
        public SimpleAuthenticationModule(IAuthenticationCallbackProvider callbackProvider, IConfigurationOptions configurationOptions)
        {
            _callbackProvider = callbackProvider;
            _authenticationProviderFactory = new AuthenticationProviderFactory();
            _configurationOptions          = configurationOptions;

            // Define the routes and how they are handled.
            Get[RedirectRoute]  = parameters => RedirectToProvider(parameters);
            Post[RedirectRoute] = parameters => RedirectToProvider(parameters);
            Get[CallbackRoute]  = parameters => AuthenticateCallback();

            // If no Cache type is provided, we'll use a Session as the default.
            Before += context =>
            {
                if (Cache == null)
                {
                    Cache = new SessionCache(context.Request.Session);
                }

                return(null);
            };
        }
        public ConfigurationFactory(IConfiguration configuration,
                                    IConfigurationOptions configurationOptions,
                                    IResolver <IKeyName> keyNameResolver,
                                    IResolver <IConfigurationReader> configurationReaderResolver,
                                    IResolver <IParser> parserResolver,
                                    IResolver <IValueConstructor> valueConstructorResolver,
                                    IConfigLogger configLogger = null)
        {
            _configuration = configuration
                             .EnsureNotNull(nameof(configuration));
            _configurationOptions = configurationOptions
                                    .EnsureNotNull(nameof(configurationOptions));
            _keyNameResolver = keyNameResolver
                               .EnsureNotNull(nameof(keyNameResolver));
            _configurationReaderResolver = configurationReaderResolver
                                           .EnsureNotNull(nameof(configurationReaderResolver));
            _parserResolver = parserResolver
                              .EnsureNotNull(nameof(parserResolver));
            _valueConstructorResolver = valueConstructorResolver
                                        .EnsureNotNull(nameof(valueConstructorResolver));

            StaticLoggingHelper.ConfigLogger = configLogger;
        }
 /// <summary>
 /// Initializes a new instance of the ConfigurableActiveRecordGenerator class.
 /// </summary>
 /// <param name="configOptions"></param>
 public ConfigurableActiveRecordGenerator(IConfigurationOptions configOptions)
 {
     base.ConfigOptions = configOptions;
 }
 public EnumerationGenerator(IDbProvider dbProvider, IConfigurationOptions configOptions, NameProvider nameProvider)
 {
     _dbProvider = dbProvider;
     _configOptions = configOptions;
     _nameProvider = nameProvider;
 }
 public SimpleAuthenticationController(IAuthenticationCallbackProvider callbackProvider,
     IConfigurationOptions configurationOptions)
     : this(callbackProvider, null, configurationOptions)
 {
 }
Beispiel #35
0
 private NameProvider InitializeNameProvider(IConfigurationOptions config, Ioc ioc)
 {
     Log.WriteLine("Initializing NameProvider");
     var nameProvider = ioc.Get<NameProvider>() ?? new NameProvider();
     nameProvider.TablePrefixes.AddRange(config.OnlyTablesWithPrefix);
     nameProvider.TablePrefixes.AddRange(config.SkipTablesWithPrefix);
     nameProvider.EnumReplacements = config.EnumReplacements;
     return nameProvider;
 }
Beispiel #36
0
 private void EnsureOutputPath(IConfigurationOptions config)
 {
     Log.Write("Ensuring output path... ");
     string outputPath = config.OutputPath;
     if (!Path.IsPathRooted(outputPath))
     {
         outputPath = Path.Combine(_configDirectory, outputPath);
     }
     if (!Directory.Exists(outputPath))
     {
         Directory.CreateDirectory(outputPath);
     }
     config.OutputPath = outputPath;
     Log.WriteLine(config.OutputPath);
 }
Beispiel #37
0
        private void EnsureEnumOutputPath(IConfigurationOptions config)
        {
            if (config.Enums.Count() == 0)
                return;

            Log.Write("Ensuring enum output path... ");
            string enumOutputPath = config.EnumOutputPath;
            if (!Path.IsPathRooted(enumOutputPath))
            {
                enumOutputPath = Path.Combine(_configDirectory, enumOutputPath);
            }
            if (!Directory.Exists(enumOutputPath))
            {
                Directory.CreateDirectory(enumOutputPath);
            }

            config.EnumOutputPath = enumOutputPath;
            Log.WriteLine(config.EnumOutputPath);
        }
        private void LoadEnumReplacements(XmlNode configNode, IConfigurationOptions options)
        {
            var nodeList = configNode.SelectNodes("./enums/replacement");
            foreach (XmlNode node in nodeList)
            {
                string lookfor = node.Attributes["lookfor"] != null ? node.Attributes["lookfor"].Value : String.Empty;
                string replacewith = node.Attributes["replacewith"] != null ? node.Attributes["replacewith"].Value : String.Empty;
                if (String.IsNullOrEmpty(lookfor) || String.IsNullOrEmpty(replacewith))
                {
                    continue;
                }

                options.EnumReplacements.Add(lookfor, replacewith);
            }
        }
 public static void Initialize(IStorageRepository storage = null, ISerializer serializer = null, IConfigurationOptions configurationOptions = null)
 {
     s_storeManager ??= new StoreManagerApplication(storage, serializer, configurationOptions);
 }
Beispiel #40
0
 public CodeRunnerImpl(CodeRunnerConfig codeRunnerConfig)
 {
     _codeRunnerConfig = codeRunnerConfig;
     _options = _codeRunnerConfig.Options;
 }