Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
        public InstallationResult EnsureAccessToFileSystem()
        {
            var result = new InstallationResult();
            //validate permissions
            string rootDir     = _context.Server.MapPath("~/");
            var    dirsToCheck = new List <string>();

            dirsToCheck.Add(rootDir);
            dirsToCheck.Add(rootDir + "App_Data");
            dirsToCheck.Add(rootDir + "bin");
            dirsToCheck.Add(rootDir + "content");
            dirsToCheck.Add(rootDir + "content/upload");
            foreach (string dir in dirsToCheck)
            {
                if (!CheckPermissions(new RequiredCheck(false, true, true, true), dir))
                {
                    result.AddModelError(
                        String.Format(
                            "The '{0}' account is not granted with Modify permission on folder '{1}'. Please configure these permissions.",
                            WindowsIdentity.GetCurrent().Name, dir));
                }
                else
                {
                    var directoryInfo = new DirectoryInfo(dir);
                    if (!directoryInfo.Exists)
                    {
                        directoryInfo.Create();
                    }
                }
            }


            var filesToCheck = new List <string>();

            filesToCheck.Add(rootDir + "web.config");
            filesToCheck.Add(rootDir + "ConnectionStrings.config");
            foreach (string file in filesToCheck)
            {
                if (!CheckPermissions(new RequiredCheck(false, true, true, true), file))
                {
                    result.AddModelError(
                        String.Format(
                            "The '{0}' account is not granted with Modify permission on file '{1}'. Please configure these permissions.",
                            WindowsIdentity.GetCurrent().Name, file));
                }
            }
            return(result);
        }
Ejemplo 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);
        }
Ejemplo n.º 4
0
        public InstallationResult EnsureAccessToFileSystem()
        {
            var result = new InstallationResult();
            //validate permissions
            string rootDir = _context.Server.MapPath("~/");
            var dirsToCheck = new List<string>();
            dirsToCheck.Add(rootDir);
            dirsToCheck.Add(rootDir + "App_Data");
            dirsToCheck.Add(rootDir + "bin");
            dirsToCheck.Add(rootDir + "content");
            dirsToCheck.Add(rootDir + "content/upload");
            foreach (string dir in dirsToCheck)
                if (!CheckPermissions(new RequiredCheck(false, true, true, true), dir))
                    result.AddModelError(
                        String.Format(
                            "The '{0}' account is not granted with Modify permission on folder '{1}'. Please configure these permissions.",
                            WindowsIdentity.GetCurrent().Name, dir));
                else
                {
                    var directoryInfo = new DirectoryInfo(dir);
                    if (!directoryInfo.Exists)
                    {
                        directoryInfo.Create();
                    }
                }

            var filesToCheck = new List<string>();
            filesToCheck.Add(rootDir + "web.config");
            filesToCheck.Add(rootDir + "ConnectionStrings.config");
            foreach (string file in filesToCheck)
                if (!CheckPermissions(new RequiredCheck(false, true, true, true), file))
                    result.AddModelError(
                        String.Format(
                            "The '{0}' account is not granted with Modify permission on file '{1}'. Please configure these permissions.",
                            WindowsIdentity.GetCurrent().Name, file));
            return result;
        }
Ejemplo n.º 5
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);
        }