示例#1
0
        public void Route(ApplicationMode applicationMode)
        {
            if (!_environmentProvider.IsUserInteractive)
            {
                applicationMode = ApplicationMode.Service;
            }

            logger.Info("Application mode: {0}", applicationMode);

            switch (applicationMode)
            {
            case ApplicationMode.Service:
            {
                logger.Trace("Service selected");
                _serviceProvider.Run(_applicationServer);
                break;
            }

            case ApplicationMode.Console:
            {
                logger.Trace("Console selected");
                _applicationServer.Start();
                if (ConsoleProvider.IsConsoleApplication)
                {
                    _consoleProvider.WaitForClose();
                }

                else
                {
                    _sysTrayProvider.Start();
                }

                break;
            }

            case ApplicationMode.InstallService:
            {
                logger.Trace("Install Service selected");
                if (_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME))
                {
                    _consoleProvider.PrintServiceAlreadyExist();
                }
                else
                {
                    _serviceProvider.Install(ServiceProvider.NZBDRONE_SERVICE_NAME);
                    _serviceProvider.Start(ServiceProvider.NZBDRONE_SERVICE_NAME);
                }
                break;
            }

            case ApplicationMode.UninstallService:
            {
                logger.Trace("Uninstall Service selected");
                if (!_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME))
                {
                    _consoleProvider.PrintServiceDoestExist();
                }
                else
                {
                    _serviceProvider.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME);
                }

                break;
            }

            default:
            {
                _consoleProvider.PrintHelp();
                break;
            }
            }
        }