Example #1
0
        public override void Install(System.Collections.IDictionary savedState)
        {
            String args = this.Context.Parameters["Args"];

            String[] individualArgs;
            String   filePath    = "";
            string   installUser = "";
            string   installPwd  = "";

            individualArgs = args.Split(Convert.ToChar(","));
            if (args == "")
            {
                // throw an exception, we're expecting parameters/argumen
                throw new InstallException("No arguments specified");
            }

            // store the setup options we need for uninstall
            if (!saveInstallState(savedState, individualArgs))
            {
                throw new InstallException("Can't persist install parameters");
            }

            // valid arguments, do the install work
            filePath = individualArgs[(int)InstallParams.ProgramFilesFolder] + "Assignment Manager\\Setup";
            // grab the db install user/pwd
            installUser = individualArgs[(int)InstallParams.DBUserID];
            installPwd  = individualArgs[(int)InstallParams.DBPassword];

            if (individualArgs[(int)InstallParams.TargetVDir] == "")
            {
                throw new InstallException("individualArgs[VDir] = " + individualArgs[(int)InstallParams.TargetVDir] +
                                           "\nargs[web] = " + individualArgs[(int)InstallParams.TargetWebDirectory]);
            }

            // create the db
            if (!createDB(individualArgs))
            {
                throw new  InstallException("Error occured creating the database");
            }

            // do the web site config
            Process p2;
            string  targetVDir = individualArgs[(int)InstallParams.TargetVDir];
            string  sslValue   = getBooleanValue(individualArgs[(int)InstallParams.SSLEnabled]);

            ProcessStartInfo si2 = new System.Diagnostics.ProcessStartInfo("\"" + filePath + "\\RemoveScriptMaps.vbs\"", "\"" + targetVDir + "\" \"" + sslValue + "\"");

            si2.WindowStyle = ProcessWindowStyle.Hidden;
            try
            {
                p2 = Process.Start(si2);
                p2.WaitForExit();
            }
            catch (Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry("AMInstall", ex.ToString());
                throw new InstallException(ex.Message);
            }


            try
            {
                createApplicationPool(appPoolName);
                if (DirectoryEntry.Exists("IIS://localhost/w3svc/AppPools/AssignmentManager"))
                {
                    // if Application Pools exist, then add AssignmentManager to our newly created pool
                    addVDirToAppPool(individualArgs[(int)InstallParams.TargetVDir], appPoolName);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry("AMInstall", ex.ToString());
            }


            // Set the upload directory to Read/Write/Delete for Everyone, Full Control for System.
            if (!SecurityPermissions.SetVDirSecurityDescriptor("AMUpload", "D:(A;OICI;GWGRSD;;;WD)(A;OICI;GA;;;SY)"))
            {
                System.Diagnostics.EventLog.WriteEntry("AMInstall", "Unable to set the AMUpload directory writeable for Everyone.");
            }
            // Set the download directory to Full Control for Local System, Read/Delete for Everyone.
            if (!SecurityPermissions.SetVDirSecurityDescriptor("AMDownload", "D:(A;OICI;GA;;;SY)(A;OICI;GRSD;;;WD)"))
            {
                System.Diagnostics.EventLog.WriteEntry("AMInstall", "Unable to set permissions on the AMDownload directory.");
            }

            // update the web.config file
            if (!updateConfigFile(individualArgs[(int)InstallParams.TargetWebDirectory] + "web.config", individualArgs))
            {
                System.Diagnostics.EventLog.WriteEntry("AMInstall", "Error occured while updating configuration files", System.Diagnostics.EventLogEntryType.Error);
                throw new InstallException();
            }

            // update the ActionService.exe.config file
            if (!updateConfigFile(individualArgs[(int)InstallParams.ProgramFilesFolder] + "Assignment Manager\\Controller\\ActionService.exe.config", individualArgs))
            {
                System.Diagnostics.EventLog.WriteEntry("AMInstall", "Error occured while updating application configuration files", System.Diagnostics.EventLogEntryType.Error);
                throw new InstallException();
            }

            // update the Controller.exe.config file
            if (!updateConfigFile(individualArgs[(int)InstallParams.ProgramFilesFolder] + "Assignment Manager\\Controller\\Controller.exe.config", individualArgs))
            {
                System.Diagnostics.EventLog.WriteEntry("AMInstall", "Error occured while updating application configuration files", System.Diagnostics.EventLogEntryType.Error);
                throw new InstallException();
            }

            if (!AMUser.CreateUser())
            {
                System.Diagnostics.EventLog.WriteEntry("AMInstall", "Error occured while creating the AssignmentManager user", System.Diagnostics.EventLogEntryType.Error);
                throw new InstallException();
            }

            if (!AMUser.AddUserToGroup())
            {
                System.Diagnostics.EventLog.WriteEntry("AMInstall", "Error occured while addding the AssignmentManager user to the Users group", System.Diagnostics.EventLogEntryType.Error);
                throw new InstallException();
            }

            //Create data directory
            if (!CreateDataDirectory())
            {
                System.Diagnostics.EventLog.WriteEntry("AMInstall", "Cannot create c:\\data directory.", System.Diagnostics.EventLogEntryType.Error);
                throw new InstallException();
            }

            if (!setASPNETProcessInfinite())
            {
                // Do not abort in this case; they can still continue with installation.
                System.Diagnostics.EventLog.WriteEntry("AMInstall", "Unable to set the ASP .NET worker process timeout to Infinite.", System.Diagnostics.EventLogEntryType.Warning);
            }

            // Change process model to run as Local System
            if (!changeASPNETProcessModel())
            {
                // Do not abort on this case; the user may have custom set their machine.config file.
                System.Diagnostics.EventLog.WriteEntry("AMInstall", "Cannot change the ASP.NET Process model in machine.config", EventLogEntryType.Information);
            }

            string acl = "D:"                         // DACL
                         + "(A;OICI;GA;;;SY)"         // Local System full control
                         + "(A;OICI;GA;;;BA)"         // Administrators full control
                         + "(A;OICI;GR;;;WD)";        // Everyone Read

            if (!SecurityPermissions.RecurseAndSetSecurity(individualArgs[(int)InstallParams.TargetWebDirectory], acl))
            {
                System.Diagnostics.EventLog.WriteEntry("AMInstall", "Cannot change permissions on " + individualArgs[(int)InstallParams.TargetWebDirectory]);
            }

            base.Install(savedState);
        }