GetServiceTypeFromString() public static method

public static GetServiceTypeFromString ( string serviceType ) : ServiceType
serviceType string
return ServiceType
Beispiel #1
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);
        }