public BusinessInstaller(InstallerConfiguration config) { BeforeInstall += new InstallEventHandler((obj, state) => { Initialize(config); }); BeforeUninstall += new InstallEventHandler((obj, state) => { Initialize(config); }); InitializeComponent(); }
/// <summary> /// GetConfig() returns an instance of the <b>StaticPageConfiguration</b> class with the values populated from /// the Web.config file. It uses XML deserialization to convert the XML structure in Web.config into /// a <b>StaticPageConfiguration</b> instance. /// </summary> /// <returns>A <see cref="StaticPageConfiguration"/> instance.</returns> public static InstallerConfiguration GetConfig() { string key = "mysoft.framework/installer"; InstallerConfiguration obj = CacheHelper.Get <InstallerConfiguration>(key); if (obj == null) { var tmp = ConfigurationManager.GetSection(key); obj = tmp as InstallerConfiguration; CacheHelper.Permanent(key, obj);; } return(obj); }
/// <summary> /// 初始化服务 /// </summary> private void Initialize(InstallerConfiguration config) { if (config == null) return; string _ServiceName = config.ServiceName; string _DisplayName = config.DisplayName; string _Description = config.Description; string _UserName = config.UserName; string _Password = config.Password; if (string.IsNullOrEmpty(_DisplayName)) { _DisplayName = _ServiceName; } ServiceProcessInstaller spi = new ServiceProcessInstaller(); //指定服务帐号类型 if (String.IsNullOrEmpty(_UserName) || String.IsNullOrEmpty(_Password)) { spi.Account = ServiceAccount.LocalSystem; } else { spi.Account = ServiceAccount.User; spi.Username = _UserName; spi.Password = _Password; } ServiceInstaller si = new ServiceInstaller(); si.ServiceName = _ServiceName; si.DisplayName = _DisplayName + " (Paltform Service)"; si.Description = _Description + " (平台服务中心)"; si.StartType = ServiceStartMode.Automatic; // adding this.Installers.Add(spi); this.Installers.Add(si); }