Exemplo n.º 1
0
        public static void Register(string fullServiceName, HostServiceInstaller installer)
        {
            _log.DebugFormat("Attempting to install '{0}'", fullServiceName);
            if (!IsInstalled(fullServiceName))
            {
                using (var ti = new TransactedInstaller())
                {
                    ti.Installers.Add(installer);

                    var assembly = Assembly.GetEntryAssembly();
                    if(assembly == null) throw new Exception("Assembly.GetEntryAssembly() is null for some reason.");

                    string path = string.Format("/assemblypath={0}", assembly.Location);
                    string[] commandLine = {path};

                    var context = new InstallContext(null, commandLine);
                    ti.Context = context;

                    var savedState = new Hashtable();

                    ti.Install(savedState);
                }
            }
            else
            {
                    _log.Info("Service is already installed");
            }
        }
Exemplo n.º 2
0
        public void Execute(IEnumerable<ICommandLineElement> args)
        {
            _log.Info("Received service install notification");

            if (WinServiceHelper.IsInstalled(_settings.FullServiceName))
            {
                string message = string.Format("The {0} service has already been installed.", _settings.FullServiceName);
                _log.Error(message);

                return;
            }

            var installer = new HostServiceInstaller(_settings);
            WinServiceHelper.Register(_settings.FullServiceName, installer);
        }