Ejemplo n.º 1
0
        protected void Application_Start()
        {
            GlobalConfiguration.Configure(WebApiConfig.Register);

            IoC.BootStrap(builder =>
            {
                var encryption = new Encryption.EncryptionService();
                var dbConfig   = new DatabaseConfigCollection();
                dbConfig.Add(new DatabaseConfigItem()
                {
                    Key = CommonConfigKeys.dbKeyMaster, ConnectionString = encryption.Decrypt(ConfigurationManager.ConnectionStrings["master"].ConnectionString), CommandTimeout = 100
                });
                builder.RegisterInstance(dbConfig).As <IDatabaseConfigCollection>().SingleInstance();
                builder.RegisterApiControllers(SparRetail.Api.Controllers.IoCRegistry.GetAssembly()).InstancePerRequest();
                SparRetail.Api.Controllers.IoCRegistry.Configure(builder);
            });


            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(IoC.Container);
        }
        public static List <DatabaseConfigElement> CreateValidatedDatabaseConfigCollection(DatabaseConfigCollection databases)
        {
            var validatedDatabaseConfigs = new List <DatabaseConfigElement>();

            for (int i = 0; i < databases.Count; i++)
            {
                var dbConfig = databases[i];

                var dbConfigValidationResult = ConfigurationValidator.IsDbConfigValid(dbConfig);

                if (!dbConfigValidationResult.IsValid)
                {
                    logger.Error($"The anonymization of the database with the following connection string was skipped: {dbConfig.ConnectionString}. " +
                                 $"Reason: {dbConfigValidationResult.ValidationMessage}");
                }
                else
                {
                    try
                    {
                        DbTypeInitializer.CreateDbTypes(dbConfig.ConnectionString);
                        validatedDatabaseConfigs.Add(databases[i]);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, $"The anonymization of the database with the following connection string was skipped: {dbConfig.ConnectionString}. " +
                                     $"Reason: {ex.Message}");
                    }
                }
            }

            return(validatedDatabaseConfigs);
        }