Пример #1
0
        void IInstallAction.Run(SetupVariables vars)
        {
            try
            {
                Begin(LogStartInstallMessage);
                //
                var connectionString = vars.DbInstallConnectionString;
                var database         = vars.Database;

                Log.WriteStart(LogStartInstallMessage);
                Log.WriteInfo(String.Format("SQL Server Database Name: \"{0}\"", database));
                //
                if (SqlUtils.DatabaseExists(connectionString, database))
                {
                    throw new Exception(String.Format("SQL Server database \"{0}\" already exists", database));
                }
                SqlUtils.CreateDatabase(connectionString, database);
                //
                Log.WriteEnd("Created SQL Server database");
                //
                InstallLog.AppendLine(String.Format("- Created a new SQL Server database \"{0}\"", database));
            }
            catch (Exception ex)
            {
                if (Utils.IsThreadAbortException(ex))
                {
                    return;
                }
                //
                Log.WriteError("Create database error", ex);
                //
                throw;
            }
        }
Пример #2
0
        void IInstallAction.Run(SetupVariables vars)
        {
            try
            {
                //
                Log.WriteStart(String.Format("Creating database user {0}", vars.Database));
                //
                vars.DatabaseUserPassword = Utils.GetRandomString(20);
                //user name should be the same as database
                vars.NewDatabaseUser = SqlUtils.CreateUser(vars.DbInstallConnectionString, vars.Database, vars.DatabaseUserPassword, vars.Database);
                //
                Log.WriteEnd("Created database user");
                InstallLog.AppendLine("- Created database user \"{0}\"", vars.Database);
            }
            catch (Exception ex)
            {
                if (Utils.IsThreadAbortException(ex))
                {
                    return;
                }

                Log.WriteError("Create db user error", ex);
                throw;
            }
        }
        void IUninstallAction.Run(SetupVariables vars)
        {
            try
            {
                Log.WriteStart(LogStartUninstallMessage);

                Log.WriteInfo(String.Format(LogUninstallInfoMessage, vars.ComponentFullName));

                XmlUtils.RemoveXmlNode(AppConfig.GetComponentConfig(vars.ComponentId));

                AppConfig.SaveConfiguration();

                Log.WriteEnd(LogEndUninstallMessage);

                InstallLog.AppendLine("- Updated system configuration");
            }
            catch (Exception ex)
            {
                if (Utils.IsThreadAbortException(ex))
                {
                    return;
                }
                //
                Log.WriteError(LogErrorUninstallMessage, ex);
                throw;
            }
        }
 void IInstallAction.Run(SetupVariables vars)
 {
     try
     {
         Begin(LogStartInstallMessage);
         //
         var source      = vars.InstallerFolder;
         var destination = vars.InstallationFolder;
         //
         string component = vars.ComponentFullName;
         //
         Log.WriteStart(LogStartInstallMessage);
         Log.WriteInfo(String.Format("Copying files from \"{0}\" to \"{1}\"", source, destination));
         //showing copy process
         DoFilesCopyProcess(source, destination);
         //
         InstallLog.AppendLine(String.Format("- Copied {0} files", component));
         // rollback
         //RollBack.RegisterDirectoryAction(destination);
     }
     catch (Exception ex)
     {
         if (Utils.IsThreadAbortException(ex))
         {
             return;
         }
         Log.WriteError("Copy error", ex);
         throw;
     }
 }
        private void CreateUserAccount(SetupVariables vars)
        {
            //SetProgressText("Creating windows user account...");

            var domain   = vars.UserDomain;
            var userName = vars.UserAccount;
            //
            var description = String.Format(UserAccountDescription, vars.ComponentName);
            var memberOf    = vars.UserMembership;
            var password    = vars.UserPassword;

            Log.WriteStart(LogStartMessage);

            Log.WriteInfo(String.Format(LogInfoMessage, userName));

            // create account
            SystemUserItem user = new SystemUserItem
            {
                Domain               = domain,
                Name                 = userName,
                FullName             = userName,
                Description          = description,
                MemberOf             = memberOf,
                Password             = password,
                PasswordCantChange   = true,
                PasswordNeverExpires = true,
                AccountDisabled      = false,
                System               = true
            };

            //
            SecurityUtils.CreateUser(user);

            // add rollback action
            //RollBack.RegisterUserAccountAction(domain, userName);

            // update log
            Log.WriteEnd(LogEndMessage);

            // update install log
            if (String.IsNullOrEmpty(domain))
            {
                InstallLog.AppendLine(String.Format(InstallLogMessageLocal, userName));
            }
            else
            {
                InstallLog.AppendLine(String.Format(InstallLogMessageDomain, userName, domain));
            }
        }
        void IUninstallAction.Run(SetupVariables vars)
        {
            try
            {
                var appPoolName = String.Format(AppPoolNameFormatString, vars.ComponentFullName);
                var iisVersion  = vars.IISVersion;
                var iis7        = (iisVersion.Major == 7);
                var poolExists  = false;
                //
                Log.WriteStart(LogStartUninstallMessage);
                //
                vars.WebApplicationPoolName = appPoolName;

                // Maintain backward compatibility
                if (iis7)
                {
                    poolExists = WebUtils.IIS7ApplicationPoolExists(appPoolName);
                }
                else
                {
                    poolExists = WebUtils.ApplicationPoolExists(appPoolName);
                }

                if (!poolExists)
                {
                    Log.WriteInfo(LogUninstallAppPoolNotFoundMessage);
                    return;
                }
                //
                if (iis7)
                {
                    WebUtils.DeleteIIS7ApplicationPool(appPoolName);
                }
                else
                {
                    WebUtils.DeleteApplicationPool(appPoolName);
                }
                //update install log
                InstallLog.AppendLine(String.Format("- Removed application pool named \"{0}\"", appPoolName));
            }
            finally
            {
                //update log
                //Log.WriteEnd(LogEndUninstallMessage);
            }
        }
        void IInstallAction.Run(SetupVariables vars)
        {
            try
            {
                Begin(LogStartInstallMessage);

                Log.WriteStart(LogStartInstallMessage);

                var ServiceName = Global.Parameters.SchedulerServiceName;
                var ServiceFile = Path.Combine(vars.InstallationFolder, "bin", Global.Parameters.SchedulerServiceFileName);

                Log.WriteInfo(String.Format("Scheduler Service Name: \"{0}\"", Global.Parameters.SchedulerServiceName));

                if (ServiceController.GetServices().Any(s => s.DisplayName.Equals(Global.Parameters.SchedulerServiceName, StringComparison.CurrentCultureIgnoreCase)))
                {
                    Log.WriteEnd("Scheduler Service Already Installed.");
                    InstallLog.AppendLine(String.Format("- Scheduler Service \"{0}\" Already Installed.", Global.Parameters.SchedulerServiceName));
                    return;
                }

                ManagedInstallerClass.InstallHelper(new[] { "/i /LogFile=\"\" ", ServiceFile });
                Utils.StartService(Global.Parameters.SchedulerServiceName);

                AppConfig.EnsureComponentConfig(vars.ComponentId);
                AppConfig.SetComponentSettingStringValue(vars.ComponentId, "ServiceName", ServiceName);
                AppConfig.SetComponentSettingStringValue(vars.ComponentId, "ServiceFile", ServiceFile);
                AppConfig.SaveConfiguration();
            }
            catch (Exception ex)
            {
                UninstallService(vars);

                if (Utils.IsThreadAbortException(ex))
                {
                    return;
                }

                Log.WriteError("Installing scheduler service error.", ex);
                throw;
            }
        }
        void IInstallAction.Run(SetupVariables vars)
        {
            var siteName     = vars.ComponentFullName;
            var ip           = vars.WebSiteIP;
            var port         = vars.WebSitePort;
            var domain       = vars.WebSiteDomain;
            var contentPath  = vars.InstallationFolder;
            var iisVersion   = vars.IISVersion;
            var iis7         = (iisVersion.Major == 7);
            var userName     = CreateWebApplicationPoolAction.GetWebIdentity(vars);
            var userPassword = vars.UserPassword;
            var appPool      = vars.WebApplicationPoolName;
            var componentId  = vars.ComponentId;
            var newSiteId    = String.Empty;

            //
            Begin(LogStartMessage);
            //
            Log.WriteStart(LogStartMessage);
            //
            Log.WriteInfo(String.Format("Creating web site \"{0}\" ( IP: {1}, Port: {2}, Domain: {3} )", siteName, ip, port, domain));

            //check for existing site
            var oldSiteId = iis7 ? WebUtils.GetIIS7SiteIdByBinding(ip, port, domain) : WebUtils.GetSiteIdByBinding(ip, port, domain);

            //
            if (oldSiteId != null)
            {
                // get site name
                string oldSiteName = iis7 ? oldSiteId : WebUtils.GetSite(oldSiteId).Name;
                throw new Exception(
                          String.Format("'{0}' web site already has server binding ( IP: {1}, Port: {2}, Domain: {3} )",
                                        oldSiteName, ip, port, domain));
            }

            // create site
            var site = new WebSiteItem
            {
                Name                         = siteName,
                SiteIPAddress                = ip,
                ContentPath                  = contentPath,
                AllowExecuteAccess           = false,
                AllowScriptAccess            = true,
                AllowSourceAccess            = false,
                AllowReadAccess              = true,
                AllowWriteAccess             = false,
                AnonymousUsername            = userName,
                AnonymousUserPassword        = userPassword,
                AllowDirectoryBrowsingAccess = false,
                AuthAnonymous                = true,
                AuthWindows                  = true,
                DefaultDocs                  = null,
                HttpRedirect                 = "",
                InstalledDotNetFramework     = AspNetVersion.AspNet20,
                ApplicationPool              = appPool,
                //
                Bindings = new ServerBinding[] {
                    new ServerBinding(ip, port, domain)
                },
            };

            // create site
            if (iis7)
            {
                newSiteId = WebUtils.CreateIIS7Site(site);
            }
            else
            {
                newSiteId = WebUtils.CreateSite(site);
            }

            vars.VirtualDirectory    = String.Empty;
            vars.NewWebSite          = true;
            vars.NewVirtualDirectory = false;

            // update setup variables
            vars.WebSiteId = newSiteId;

            //update log
            Log.WriteEnd("Created web site");
            //
            Finish(LogStartMessage);

            //update install log
            InstallLog.AppendLine(string.Format("- Created a new web site named \"{0}\" ({1})", siteName, newSiteId));
            InstallLog.AppendLine("  You can access the application by the following URLs:");
            string[] urls = Utils.GetApplicationUrls(ip, domain, port, null);
            foreach (string url in urls)
            {
                InstallLog.AppendLine("  http://" + url);
            }
        }
        void IInstallAction.Run(SetupVariables vars)
        {
            var appPoolName   = String.Format(AppPoolNameFormatString, vars.ComponentFullName);
            var userDomain    = vars.UserDomain;
            var netbiosDomain = userDomain;
            var userName      = vars.UserAccount;
            var userPassword  = vars.UserPassword;
            var identity      = GetWebIdentity(vars);
            var componentId   = vars.ComponentId;
            var iisVersion    = vars.IISVersion;
            var iis7          = (iisVersion.Major == 7);
            var poolExists    = false;

            //
            vars.WebApplicationPoolName = appPoolName;

            // Maintain backward compatibility
            if (iis7)
            {
                poolExists = WebUtils.IIS7ApplicationPoolExists(appPoolName);
            }
            else
            {
                poolExists = WebUtils.ApplicationPoolExists(appPoolName);
            }

            // This flag is the opposite of poolExists flag
            vars.NewWebApplicationPool = !poolExists;

            if (poolExists)
            {
                //update app pool
                Log.WriteStart("Updating application pool");
                Log.WriteInfo(String.Format("Updating application pool \"{0}\"", appPoolName));
                //
                if (iis7)
                {
                    WebUtils.UpdateIIS7ApplicationPool(appPoolName, userName, userPassword);
                }
                else
                {
                    WebUtils.UpdateApplicationPool(appPoolName, userName, userPassword);
                }

                //
                //update log
                Log.WriteEnd("Updated application pool");

                //update install log
                InstallLog.AppendLine(String.Format("- Updated application pool named \"{0}\"", appPoolName));
            }
            else
            {
                // create app pool
                Log.WriteStart("Creating application pool");
                Log.WriteInfo(String.Format("Creating application pool \"{0}\"", appPoolName));
                //
                if (iis7)
                {
                    WebUtils.CreateIIS7ApplicationPool(appPoolName, userName, userPassword);
                }
                else
                {
                    WebUtils.CreateApplicationPool(appPoolName, userName, userPassword);
                }

                //update log
                Log.WriteEnd("Created application pool");

                //update install log
                InstallLog.AppendLine(String.Format("- Created a new application pool named \"{0}\"", appPoolName));
            }
        }