コード例 #1
0
 private static SetupScript GetPrepareScript(Session Ctx)
 {
     var CtxVars = new SetupVariables();
     WiXSetup.FillFromSession(Ctx.CustomActionData, CtxVars);
     AppConfig.LoadConfiguration(new ExeConfigurationFileMap { ExeConfigFilename = GetProperty(Ctx, "MainConfig") });
     CtxVars.IISVersion = Tool.GetWebServerVersion();
     CtxVars.ComponentId = GetProperty(Ctx, "ComponentId");
     CtxVars.Version = AppConfig.GetComponentSettingStringValue(CtxVars.ComponentId, Global.Parameters.Release);
     CtxVars.SpecialBaseDirectory = Directory.GetParent(GetProperty(Ctx, "MainConfig")).FullName;
     CtxVars.FileNameMap = new Dictionary<string, string>();
     CtxVars.FileNameMap.Add(new FileInfo(GetProperty(Ctx, "MainConfig")).Name, BackupRestore.MainConfig);
     SetupScript Result = new ExpressScript(CtxVars);
     Result.Actions.Add(new InstallAction(ActionTypes.StopApplicationPool) { SetupVariables = CtxVars });
     Result.Actions.Add(new InstallAction(ActionTypes.Backup) { SetupVariables = CtxVars });
     Result.Actions.Add(new InstallAction(ActionTypes.DeleteDirectory) { SetupVariables = CtxVars, Path = CtxVars.InstallFolder });
     return Result;
 }
コード例 #2
0
ファイル: Adapter.cs プロジェクト: lwhitelock/Websitepanel
 protected override void Install()
 {
     if (ModeExtension == ModeExtension.Normal)
     {
         bool WiXThrow = default(bool);
         Context.ComponentId = Guid.NewGuid().ToString();
         Context.Instance = String.Empty;
         var sam = new WiXEnterpriseServerActionManager(Context);
         sam.PrepareDistributiveDefaults();
         try
         {
             sam.ActionError += new EventHandler<ActionErrorEventArgs>((object sender, ActionErrorEventArgs e) =>
             {
                 Log.WriteError(e.ErrorMessage);
                 WiXThrow = true;
             });
             sam.Start();
         }
         catch (Exception ex)
         {
             Log.WriteError("Failed to install the component", ex);
         }
         if (WiXThrow)
             InstallFailed();
     }
     else if (ModeExtension == ModeExtension.Restore)
     {
         Context.ComponentId = GetComponentID(Context);
         Context.UseUserCredentials = false;
         AppConfig.LoadComponentSettings(Context);
         if (string.IsNullOrWhiteSpace(Context.ServiceName) || string.IsNullOrWhiteSpace(Context.ServiceFile))
         {
             Context.ServiceName = Global.Parameters.SchedulerServiceName;
             Context.ServiceFile = Path.Combine(Context.InstallationFolder, "bin", Global.Parameters.SchedulerServiceFileName);
         }                
         SetupScript Script = new RestoreScript(Context);
         Script.Run();
         Script = new ExpressScript(Context);
         var XmlUp = new Dictionary<string, string[]>();
         XmlUp.Add("configuration/connectionStrings/add[@name='EnterpriseServer']", new string[] {"connectionString", Context.ConnectionString});
         XmlUp.Add("configuration/appSettings/add[@key='WebsitePanel.CryptoKey']", new string[] {"value", Context.CryptoKey });
         Context.XmlData = XmlUp;
         Script.Actions.Add(new InstallAction(ActionTypes.UpdateXml) { SetupVariables = Context, Path = string.Format("{0}.config", Context.ServiceFile) });
         Script.Actions.Add(new InstallAction(ActionTypes.RegisterWindowsService));
         Script.Actions.Add(new InstallAction(ActionTypes.StartWindowsService));                
         Script.Run();                
     }
     else
         throw new NotImplementedException("Install " + ModeExtension.ToString());
 }
コード例 #3
0
ファイル: Adapter.cs プロジェクト: jonwbstr/Websitepanel
 protected override void Uninstall()
 {
     const string LogExt = ".InstallLog";
     Context.ComponentId = GetComponentID(Context);
     AppConfig.LoadComponentSettings(Context);
     SetupScript Script = null;
     var ServiceName = AppConfig.GetComponentSettingStringValue(Context.ComponentId, "ServiceName");
     var ServiceFile = AppConfig.GetComponentSettingStringValue(Context.ComponentId, "ServiceFile");
     switch (ModeExtension)
     {
         case ModeExtension.Normal:
             {
                 Script = new ExpressScript(Context);
                 Script.Actions.Add(new InstallAction(ActionTypes.UnregisterWindowsService)
                 {
                     Name = ServiceName,
                     Path = ServiceFile,
                     Description = "Removing Windows service...",
                     Log = string.Format("- Remove {0} Windows service", ServiceName)
                 });
                 Script.Actions.Add(new InstallAction(ActionTypes.UpdateConfig)
                 {
                     Key = Context.ComponentId,
                     Description = "Updating configuration settings...",
                     Log = "- Update configuration settings"
                 });
                 Script.Actions.Add(new InstallAction(ActionTypes.DeleteDirectoryFiles)
                 {
                     Path = Context.InstallFolder,
                     FileFilter = x => x.ToLowerInvariant().EndsWith(LogExt.ToLowerInvariant())
                 });
             }
             break;
         case ModeExtension.Backup:
             {
                 Script = new ExpressScript(Context);
                 Script.Actions.Add(new InstallAction(ActionTypes.Backup) { SetupVariables = Script.Context });
                 Script.Actions.Add(new InstallAction(ActionTypes.UnregisterWindowsService)
                 {
                     Name = ServiceName,
                     Path = ServiceFile,
                     Description = "Removing Windows service...",
                     Log = string.Format("- Remove {0} Windows service", ServiceName)
                 });
                 Script.Actions.Add(new InstallAction(ActionTypes.DeleteDirectoryFiles)
                 {
                     Path = Context.InstallFolder,
                     FileFilter = x => x.ToLowerInvariant().EndsWith(LogExt.ToLowerInvariant())
                 });
             }
             break;
         default:
             throw new NotImplementedException("Uninstall " + ModeExtension.ToString());
     }
     Script.Run();
 }
コード例 #4
0
ファイル: Adapter.cs プロジェクト: jonwbstr/Websitepanel
 protected override void Install()
 {
     if (ModeExtension == ModeExtension.Normal)
     {
         Context.ComponentId = Guid.NewGuid().ToString();
         Context.Instance = String.Empty;
         try
         {
             if (new string[] { Context.DatabaseServer, Context.Database, Context.DatabaseUser, Context.DatabaseUserPassword, Context.CryptoKey }.All(x => string.IsNullOrWhiteSpace(x)))
             {
                 var ESVars = new SetupVariables() { ComponentCode = Global.EntServer.ComponentCode, InstallerFolder = Context.InstallerFolder };
                 ESVars.ComponentId = WiXSetup.GetComponentID(ESVars);
                 AppConfig.LoadComponentSettings(ESVars);
                 Context.ConnectionString = ESVars.ConnectionString;
                 Context.CryptoKey = ESVars.CryptoKey;
             }
             else
             {
                 Context.ConnectionString = string.Format(Context.ConnectionString, Context.DatabaseServer, Context.Database, Context.DatabaseUser, Context.DatabaseUserPassword);
             }
             if (string.IsNullOrWhiteSpace(Context.ServiceName) || string.IsNullOrWhiteSpace(Context.ServiceFile))
             {
                 Context.ServiceName = Global.Parameters.SchedulerServiceName;
                 Context.ServiceFile = Path.Combine(Context.InstallationFolder, Global.Parameters.SchedulerServiceFileName);
             }
             var XmlUp = new Dictionary<string, string[]>();
             XmlUp.Add("configuration/connectionStrings/add[@name='EnterpriseServer']", new string[] { "connectionString", Context.ConnectionString });
             XmlUp.Add("configuration/appSettings/add[@key='WebsitePanel.CryptoKey']", new string[] { "value", Context.CryptoKey });
             Context.XmlData = XmlUp;
             var Script = new ExpressScript(Context);
             Script.Actions.Add(new InstallAction(ActionTypes.UpdateXml) { SetupVariables = Context, Path = string.Format("{0}.config", Context.ServiceFile) });
             Script.Actions.Add(new InstallAction(ActionTypes.RegisterWindowsService));
             Script.Actions.Add(new InstallAction(ActionTypes.StartWindowsService));
             Script.Actions.Add(new InstallAction(ActionTypes.SaveConfig));
             Script.Run();
         }
         catch (Exception ex)
         {
             Log.WriteError("Failed to install the component", ex);
         }
     }
     else if (ModeExtension == ModeExtension.Restore)
     {
         try
         {
             Context.ComponentId = GetComponentID(Context);
             bool SaveConfig = false;
             if (string.IsNullOrWhiteSpace(Context.ComponentId))
             {
                 Context.ComponentId = Context.ComponentId = Guid.NewGuid().ToString();
                 SaveConfig = true;
             }
             if (string.IsNullOrWhiteSpace(Context.ServiceName) || string.IsNullOrWhiteSpace(Context.ServiceFile))
             {
                 Context.ServiceName = Global.Parameters.SchedulerServiceName;
                 Context.ServiceFile = Path.Combine(Context.InstallationFolder, Global.Parameters.SchedulerServiceFileName);
             }
             AppConfig.LoadComponentSettings(Context);
             var Script = new ExpressScript(Context);
             Script.Actions.Add(new InstallAction(ActionTypes.RestoreConfig) { SetupVariables = Context, Description = "Restoring xml configuration files..." });
             Script.Actions.Add(new InstallAction(ActionTypes.RegisterWindowsService));
             Script.Actions.Add(new InstallAction(ActionTypes.StartWindowsService));
             if(SaveConfig)
                 Script.Actions.Add(new InstallAction(ActionTypes.SaveConfig));
             Script.Actions.Add(new InstallAction(ActionTypes.UpdateConfig) { Description = "Updating system configuration..." });
             Script.Run();
         }
         catch (Exception ex)
         {
             Log.WriteError("Failed to restore the component", ex);
         }
     }
     else
         throw new NotImplementedException("Install " + ModeExtension.ToString());
 }
コード例 #5
0
ファイル: CustomAction.cs プロジェクト: jonwbstr/Websitepanel
        public static ActionResult InstallRollback(Session Ctx)
        {
            PopUpDebugger();
            Ctx.AttachToSetupLog();
            const string Title = "Rolling back component";
            Log.WriteStart(Title);
            Log.WriteInfo("It is normal that here occurs error.");
            try
            {
                SetupVariables SetupVar = new SetupVariables();
                WiXSetup.FillFromSession(Ctx.CustomActionData, SetupVar);
                SetupVar.IISVersion = Tool.GetWebServerVersion();
                SetupVar.ComponentId = GetProperty(Ctx, "ComponentId");

                SetupVar.WebSiteId = SetupVar.ComponentFullName;
                SetupVar.WebApplicationPoolName = string.Format("{0} Pool", SetupVar.ComponentFullName);
                SetupVar.DatabaseUser = SetupVar.Database;

                SetupScript Script = new ExpressScript(SetupVar);
                InstallAction Act = null;

                Act = new InstallAction(ActionTypes.DeleteWebSite);
                Act.SiteId = SetupVar.WebSiteId;
                Act.Description = "Deleting web site...";
                Act.Log = string.Format("- Delete {0} web site", SetupVar.WebSiteId);
                Script.Actions.Add(Act);

                Act = new InstallAction(ActionTypes.DeleteApplicationPool);
                Act.Name = SetupVar.ApplicationPool;
                Act.Description = "Deleting application pool...";
                Act.Log = string.Format("- Delete {0} application pool", SetupVar.ApplicationPool);
                Script.Actions.Add(Act);

                if (SetupVar.UserMembership != null && SetupVar.UserMembership.Length > 0)
                {
                    Act = new InstallAction(ActionTypes.DeleteUserMembership);
                    Act.Name = SetupVar.UserAccount;
                    Act.Domain = SetupVar.UserDomain;
                    Act.Membership = SetupVar.UserMembership;
                    Act.Description = "Removing user account membership...";
                    Act.Log = string.Format("- Remove {0} user account membership", SetupVar.UserAccount);
                    Script.Actions.Add(Act);
                }

                if (SetupVar.NewUserAccount)
                {
                    Act = new InstallAction(ActionTypes.DeleteUserAccount);
                    Act.Name = SetupVar.UserAccount;
                    Act.Domain = SetupVar.UserDomain;
                    Act.Description = "Deleting user account...";
                    Act.Log = string.Format("- Delete {0} user account", SetupVar.UserAccount);
                    Script.Actions.Add(Act);
                }

                if (SetupVar.ComponentCode == Global.EntServer.ComponentCode)
                {
                    Act = new InstallAction(ActionTypes.DeleteDatabaseUser);
                    Act.ConnectionString = SetupVar.InstallConnectionString;
                    Act.UserName = SetupVar.DatabaseUser;
                    Act.Description = "Deleting database user...";
                    Act.Log = string.Format("- Delete {0} database user", SetupVar.DatabaseUser);
                    Script.Actions.Add(Act);

                    Act = new InstallAction(ActionTypes.DeleteDatabaseLogin);
                    Act.ConnectionString = SetupVar.InstallConnectionString;
                    Act.UserName = SetupVar.DatabaseUser;
                    Act.Description = "Deleting database login...";
                    Act.Log = string.Format("- Delete {0} database login", SetupVar.DatabaseUser);
                    Script.Actions.Add(Act);
                }

                if (SetupVar.ComponentCode == Global.WebPortal.ComponentCode)
                {
                    Act = new InstallAction(ActionTypes.DeleteShortcuts);
                    Act.Description = "Deleting shortcuts...";
                    Act.Log = "- Delete shortcuts";
                    Act.Name = "Login to MSPControl.url";
                    Script.Actions.Add(Act);
                }

                Script.Run();
            }
            catch (Exception ex)
            {
                Log.WriteError(ex.ToString());
            }
            Log.WriteEnd(Title);
            return ActionResult.Success;
        }
コード例 #6
0
ファイル: CustomAction.cs プロジェクト: jonwbstr/Websitepanel
        public static ActionResult SchedulerInstallRollback(Session Ctx)
        {
            PopUpDebugger();
            Ctx.AttachToSetupLog();
            const string LogExt = ".InstallLog";
            const string Title = "Rolling back component";
            Log.WriteStart(Title);
            Log.WriteInfo("It is normal that here occurs error.");
            try
            {
                SetupVariables SetupVar = new SetupVariables();
                WiXSetup.FillFromSession(Ctx.CustomActionData, SetupVar);
                SetupVar.IISVersion = Tool.GetWebServerVersion();
                SetupVar.ComponentId = GetProperty(Ctx, "ComponentId");

                SetupVar.ServiceName = Global.Parameters.SchedulerServiceName;
                SetupVar.ServiceFile = Path.Combine(SetupVar.InstallationFolder, Global.Parameters.SchedulerServiceFileName);

                var Script = new ExpressScript(SetupVar);
                Script.Actions.Add(new InstallAction(ActionTypes.UnregisterWindowsService)
                {
                    Name = SetupVar.ServiceName,
                    Path = SetupVar.ServiceFile,
                    Description = string.Format("Removing Windows service '{0}' ...", SetupVar.ServiceFile),
                    Log = string.Format("- Remove {0} Windows service", SetupVar.ServiceName)
                });
                Script.Actions.Add(new InstallAction(ActionTypes.DeleteDirectoryFiles)
                {
                    Path = SetupVar.InstallFolder,
                    FileFilter = x => x.ToLowerInvariant().EndsWith(LogExt.ToLowerInvariant())
                });

                Script.Run();
            }
            catch (Exception ex)
            {
                Log.WriteError(ex.ToString());
            }
            Log.WriteEnd(Title);
            return ActionResult.Success;
        }