Esempio n. 1
0
 public static void Send(Action <ServiceMessage> actor, ServiceMessage message)
 {
     actor(message);
 }
Esempio n. 2
0
        static void UserDefinedServiceOperation(List <string> args)
        {
            IpcClientChannel clientChannel = new IpcClientChannel();

            try {
                ChannelServices.RegisterChannel(clientChannel, false);
                RemotingConfiguration.RegisterWellKnownClientType(typeof(ServiceDocker), ServiceHost.IpcUrl);
            } catch (RemotingException) {
                println("can not connect to the service host");
                try {
                    ChannelServices.UnregisterChannel(clientChannel);
                } catch (Exception) { }
                return;
            }

            var docker = new ServiceDocker();

            if (args[0] == "status" && args.Count == 1)   // user defined services status list
            {
                Console.WriteLine(docker.List());
                return;
            }

            var name   = args[0]; args.RemoveAt(0);
            var method = args[0]; args.RemoveAt(0);

            ServiceMessage message = null;

            if (method == "start")
            {
                if (!docker.Exists(name))
                {
                    var info = ServiceInfo.FindFromXMLConfig(ServicesConfigPath, name);
                    Console.WriteLine(info);
                    if (info != null)
                    {
                        docker.Install(info, out message);
                        println($"add service: {name}");
                    }
                    else
                    {
                        println($"can not find definition for {name}");
                        return;
                    }
                }
                docker.Start(name, out message);
            }
            else if (method == "stop")
            {
                docker.Stop(name, out message);
            }
            else if (method == "restart")
            {
                docker.Restart(name, out message);
            }
            else if (method == "status")
            {
                println(docker.Status(name, out message));
            }
            println(message);
        }