Exemplo n.º 1
0
        public IDatabaseProvider CreateDatabase(InstallModel model)
        {
            ICreateDatabase createDatabase = GetDatabaseCreator(model);

            if (createDatabase == null)
            {
                return(null);
            }
            createDatabase.CreateDatabase(model);
            var databaseSettings = SaveConnectionSettings(createDatabase, model);

            return(_kernel.Get(TypeHelper.GetTypeByName(model.DatabaseProvider), new ConstructorArgument("databaseSettings", databaseSettings)) as IDatabaseProvider);
        }
Exemplo n.º 2
0
        private ICreateDatabase GetDatabaseCreator(InstallModel model)
        {
            Type creatorType =
                TypeHelper.GetAllConcreteTypesAssignableFrom(
                    typeof(ICreateDatabase <>).MakeGenericType(TypeHelper.GetTypeByName(model.DatabaseProvider)))
                .FirstOrDefault();

            if (creatorType == null)
            {
                return(null);
            }
            return(_kernel.Get(creatorType) as ICreateDatabase);
        }
Exemplo n.º 3
0
        public InstallationResult ValidateConnectionString(InstallModel model)
        {
            var             result         = new InstallationResult();
            ICreateDatabase createDatabase = GetDatabaseCreator(model);

            if (createDatabase == null)
            {
                result.AddModelError("Cannot validate connection string for model.");
                return(result);
            }
            if (!createDatabase.ValidateConnectionString(model))
            {
                result.AddModelError("Unable to create the connection string with the provided details.");
            }
            return(result);
        }
Exemplo n.º 4
0
        public InstallationResult Install(InstallModel model)
        {
            if (model.DatabaseConnectionString != null)
            {
                model.DatabaseConnectionString = model.DatabaseConnectionString.Trim();
            }

            InstallationResult result = _databaseCreationService.ValidateConnectionString(model);

            if (!result.Success)
            {
                return(result);
            }

            result = _fileSystemAccessService.EnsureAccessToFileSystem();
            if (!result.Success)
            {
                return(result);
            }
            _fileSystemAccessService.EmptyAppData();

            try
            {
                IDatabaseProvider provider = _databaseCreationService.CreateDatabase(model);

                //save settings
                SetUpInitialData(model, provider);

                CurrentRequestData.OnEndRequest.Add(new InitializeIndexes());
                CurrentRequestData.OnEndRequest.Add(new ApplicationRestart());
            }
            catch (Exception exception)
            {
                result.AddModelError("Setup failed: " + exception);
                _fileSystemAccessService.EmptyAppData();
            }

            return(result);
        }