示例#1
1
 public void Install(InstallModel model)
 {
     //settings
     _setupCoreLayouts.Setup();
     _setupCoreWebpages.Setup();
     _setupCoreMedia.Setup();
 }
示例#2
0
        private void SetUpInitialData(InstallModel model, IDatabaseProvider provider)
        {
            var configurator = new NHibernateConfigurator(provider);

            ISessionFactory sessionFactory = configurator.CreateSessionFactory();
            ISession session = sessionFactory.OpenFilteredSession(CurrentRequestData.CurrentContext);
            IStatelessSession statelessSession = sessionFactory.OpenStatelessSession();
            var kernel = MrCMSApplication.Get<IKernel>();
            kernel.Rebind<ISession>().ToMethod(context => session);
            kernel.Rebind<IStatelessSession>().ToMethod(context => statelessSession);
            var site = new Site
            {
                Name = model.SiteName,
                BaseUrl = model.SiteUrl,
                CreatedOn = DateTime.UtcNow,
                UpdatedOn = DateTime.UtcNow
            };
            using (ITransaction transaction = statelessSession.BeginTransaction())
            {
                statelessSession.Insert(site);
                transaction.Commit();
            }
            CurrentRequestData.CurrentSite = site;

            kernel.Get<IInitializeDatabase>().Initialize(model);
            kernel.Get<ICreateInitialUser>().Create(model);
            kernel.GetAll<IOnInstallation>()
                .OrderBy(installation => installation.Priority)
                .ForEach(installation => installation.Install(model));
        }
示例#3
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;
        }
示例#4
0
        public void CreateDatabase(InstallModel model)
        {
            string connectionString = GetConnectionString(model);

            if (model.SqlServerCreateDatabase)
            {
                if (!SqlServerDatabaseExists(connectionString))
                {
                    //create database
                    string errorCreatingDatabase = CreateSqlDatabase(connectionString);
                    if (!String.IsNullOrEmpty(errorCreatingDatabase))
                        throw new Exception(errorCreatingDatabase);

                    int tries = 0;
                    while (tries < 50)
                    {
                        if (NewDbIsReady(connectionString))
                            break;
                        tries++;
                        Thread.Sleep(100);
                    }
                }
            }
            else
            {
                //check whether database exists
                if (!SqlServerDatabaseExists(connectionString))
                    throw new Exception("Database does not exist or you don't have permissions to connect to it");
            }
        }
示例#5
0
        public void SaveConnectionSettings(ICreateDatabase provider, InstallModel installModel)
        {
            var databaseSettings = _systemConfigurationProvider.GetSystemSettings<DatabaseSettings>();

            databaseSettings.ConnectionString = provider.GetConnectionString(installModel);
            databaseSettings.DatabaseProviderType = installModel.DatabaseProvider;

            _systemConfigurationProvider.SaveSettings(databaseSettings);
        }
示例#6
0
 public string GetConnectionString(InstallModel model)
 {
     if (model.SqlConnectionInfo == SqlConnectionInfo.Raw)
     {
         //raw connection string
         return model.DatabaseConnectionString;
     }
     return CreateConnectionString(model);
 }
示例#7
0
 public IDatabaseProvider CreateDatabase(InstallModel model)
 {
     ICreateDatabase createDatabase = GetDatabaseCreator(model);
     if (createDatabase == null)
         return null;
     createDatabase.CreateDatabase(model);
     SaveConnectionSettings(createDatabase, model);
     return
         _kernel.GetAll<IDatabaseProvider>().FirstOrDefault(provider => provider.Type == model.DatabaseProvider);
 }
示例#8
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;
 }
示例#9
0
 public static bool ValidateConnectionString(this ICreateDatabase createDatabase, InstallModel installModel)
 {
     try
     {
         createDatabase.GetConnectionString(installModel);
         return true;
     }
     catch (Exception exception)
     {
         return false;
     }
 }
 public void Install(InstallModel model)
 {
     MediaModel mediaModel = _setupEcommerceMedia.Setup();
     LayoutModel layoutModel = _setupEcommerceLayouts.Setup(mediaModel);
     PageModel pageModel = _setupBaseDocuments.Setup(mediaModel);
     _setupEcommerceSettings.Setup(mediaModel);
     _setupCurrency.Setup();
     _importDummyCategories.Import(mediaModel);
     _importDummyProducts.Import();
     _setupEcommerceWidgets.Setup(pageModel, mediaModel, layoutModel);
     _setupNewsletterTemplate.Setup();
     _indexSetup.ReIndex();
 }
示例#11
0
        public IDatabaseProvider CreateDatabase(InstallModel model)
        {
            ICreateDatabase createDatabase = GetDatabaseCreator(model);

            if (createDatabase == null)
            {
                return(null);
            }
            createDatabase.CreateDatabase(model);
            SaveConnectionSettings(createDatabase, model);
            return
                (_kernel.GetAll <IDatabaseProvider>().FirstOrDefault(provider => provider.Type == model.DatabaseProvider));
        }
示例#12
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);
        }
示例#13
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);
        }
示例#14
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;
 }
示例#15
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);
        }
示例#16
0
 private string CreateConnectionString(InstallModel model)
 {
     var builder = new SqlConnectionStringBuilder();
     bool trustedConnection = model.SqlAuthenticationType == SqlAuthenticationType.Windows;
     builder.IntegratedSecurity = trustedConnection;
     builder.DataSource = model.SqlServerName;
     builder.InitialCatalog = model.SqlDatabaseName;
     if (!trustedConnection)
     {
         builder.UserID = model.SqlServerUsername;
         builder.Password = model.SqlServerPassword;
     }
     builder.PersistSecurityInfo = false;
     builder.MultipleActiveResultSets = true;
     return builder.ConnectionString;
 }
示例#17
0
        public ActionResult Setup(InstallModel installModel)
        {
            if (CurrentRequestData.DatabaseIsInstalled)
                return Redirect("~");

            //set page timeout to 5 minutes
            Server.ScriptTimeout = 300;

            var installationResult = _installationService.Install(installModel);

            if (!installationResult.Success)
            {
                ViewData["installationResult"] = installationResult;

                return ShowPage(installModel);
            }
            return Redirect("~");
        }
示例#18
0
        public void Install(InstallModel model)
        {
            _amazonAppSettings.FeedsApiVersion = "2009-01-01";
            _amazonAppSettings.OrdersApiVersion = "2011-01-01";
            _amazonAppSettings.ProductsApiVersion = "2011-10-01";
            _amazonAppSettings.ApiEndpoint = "https://mws.amazonservices.co.uk/";
            _amazonAppSettings.AmazonProductDetailsUrl = "http://www.amazon.co.uk/gp/product/";
            _amazonAppSettings.AmazonOrderDetailsUrl = "https://sellercentral.amazon.co.uk/gp/orders-v2/details/?orderID=";
            _amazonAppSettings.AmazonManageOrdersUrl = "https://sellercentral.amazon.co.uk/gp/orders-v2/list";
            _amazonAppSettings.AmazonManageInventoryUrl = "https://sellercentral.amazon.co.uk/myi/search/ProductSummary";

            _configurationProvider.SaveSettings(_amazonAppSettings);

            _amazonSellerSettings.BarcodeIsOfType = StandardProductIDType.EAN;
            _configurationProvider.SaveSettings(_amazonSellerSettings);

            var folderLocation = string.Format("{0}/{1}/", CurrentRequestData.CurrentSite.Id, "amazon");
            var fileSystem = new FileSystem();
            fileSystem.CreateDirectory(folderLocation);
        }
示例#19
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);
        }
示例#20
0
        public void Initialize(InstallModel model)
        {
            CurrentRequestData.CurrentSite = _site = _session.Get<Site>(_site.Id);
            SetupTasks();
            var siteSettings = new SiteSettings
            {
                TimeZone = model.TimeZone,
                UICulture = model.UiCulture,
                EnableInlineEditing = true,
                SiteIsLive = true,
                FormRendererType = FormRenderingType.Bootstrap3,

            };
            var mediaSettings = new MediaSettings
            {
                ThumbnailImageHeight = 50,
                ThumbnailImageWidth = 50,
                LargeImageHeight = 800,
                LargeImageWidth = 800,
                MediumImageHeight = 500,
                MediumImageWidth = 500,
                SmallImageHeight = 200,
                SmallImageWidth = 200,
                ResizeQuality = 90,
            };
            var mailSettings = new MailSettings
            {
                Port = 25,
            };
            var fileSystemSettings = new FileSystemSettings
            {
                StorageType = typeof(FileSystem).FullName
            };

            _configurationProvider.SaveSettings(siteSettings);
            _configurationProvider.SaveSettings(mediaSettings);
            _configurationProvider.SaveSettings(mailSettings);
            _configurationProvider.SaveSettings(fileSystemSettings);
        }
示例#21
0
        public ActionResult Setup_Get(InstallModel installModel)
        {
            if (CurrentRequestData.DatabaseIsInstalled)
                return Redirect("~");

            // if it is a new setup
            if (string.IsNullOrWhiteSpace(installModel.DatabaseProvider))
            {
                ModelState.Clear();
                installModel = new InstallModel
                            {
                                SiteUrl = Request.Url.Authority,
                                AdminEmail = "*****@*****.**",
                                DatabaseConnectionString = "",
                                DatabaseProvider = typeof(SqlServer2012Provider).FullName,
                                SqlAuthenticationType = SqlAuthenticationType.SQL,
                                SqlConnectionInfo = SqlConnectionInfo.Values,
                                SqlServerCreateDatabase = false,
                            };
            }
            return ShowPage(installModel);
        }
示例#22
0
        public void Initialize(InstallModel model)
        {
            CurrentRequestData.CurrentSite = _site = _session.Get <Site>(_site.Id);
            SetupTasks();
            var siteSettings = new SiteSettings
            {
                TimeZone            = model.TimeZone,
                UICulture           = model.UiCulture,
                EnableInlineEditing = true,
                SiteIsLive          = true,
                FormRendererType    = FormRenderingType.Bootstrap3
            };
            var mediaSettings = new MediaSettings
            {
                ThumbnailImageHeight = 50,
                ThumbnailImageWidth  = 50,
                LargeImageHeight     = 800,
                LargeImageWidth      = 800,
                MediumImageHeight    = 500,
                MediumImageWidth     = 500,
                SmallImageHeight     = 200,
                SmallImageWidth      = 200,
                ResizeQuality        = 90,
            };
            var mailSettings = new MailSettings
            {
                Port = 25,
            };
            var fileSystemSettings = new FileSystemSettings
            {
                StorageType = typeof(FileSystem).FullName
            };

            _configurationProvider.SaveSettings(siteSettings);
            _configurationProvider.SaveSettings(mediaSettings);
            _configurationProvider.SaveSettings(mailSettings);
            _configurationProvider.SaveSettings(fileSystemSettings);
        }
示例#23
0
        public void Create(InstallModel model)
        {
            var user = new User
                           {
                               Email = model.AdminEmail,
                               IsActive = true
                           };
            _passwordManagementService.SetPassword(user, model.AdminPassword, model.ConfirmPassword);

            _userService.AddUser(user);
            CurrentRequestData.CurrentUser = user;

            var adminUserRole = new UserRole
                                    {
                                        Name = UserRole.Administrator
                                    };

            user.Roles = new HashSet<UserRole> { adminUserRole };
            adminUserRole.Users = new HashSet<User> { user };

            _roleService.SaveRole(adminUserRole);
            _authorisationService.Logout();
            _authorisationService.SetAuthCookie(user, true);
        }
示例#24
0
 private ActionResult ShowPage(InstallModel installModel)
 {
     ViewData["provider-types"] = _installationService.GetProviderTypes();
     return View(installModel);
 }