예제 #1
0
        public void pnArgs_PricingServiceLaunchedAndInConsoleOutput()
        {
            var call = A.CallTo(() => _testServiceLauncher.StartService(ServiceType.Pricing));

            call.Returns("p1");

            _program.Run(new LauncherConfig()
            {
                ServicesToStart = new[] { ServiceType.Pricing }
            });


            call.MustHaveHappened(Repeated.Exactly.Once);

            var output = _writer.ToString();

            Assert.Contains("Started Pricing Service: p1", output);
        }
예제 #2
0
        public bool ParseCommand(string input)
        {
            var command = input.ToLower();

            if (command.StartsWith("start"))
            {
                var a = command.Split(' ');

                var serviceType = a[1];

                try
                {
                    var type = ServiceTypeHelper.GetServiceTypeFromString(serviceType);

                    if (type == ServiceType.Unknown)
                    {
                        Log.Error("Could not start service, unknown service type '{0}'", serviceType);
                        return(false);
                    }

                    var name = _launcher.StartService(type);

                    Log.Info("Started {0} Service: {1}", type, name);
                }
                catch (Exception e)
                {
                    Log.Error("Could not start service: {0}", e.Message);
                }
                return(true);
            }

            if (command.StartsWith("kill"))
            {
                var a = command.Split(' ');

                var serviceName = a[1];

                Log.Info("Killing service {0}...", serviceName);

                if (_launcher.KillService(serviceName))
                {
                    Log.Info("Service Killed.");
                }
                else
                {
                    Log.Error("Service '{0}' does not exist.", serviceName);
                }

                return(true);
            }

            if (command == "status")
            {
                Log.Info("Running services");
                Log.Info("================");
                foreach (var s in _launcher.GetRunningServices())
                {
                    Log.Info("{0}", s);
                }

                return(true);
            }

            return(false);
        }