Esempio n. 1
0
 public static void Run(OpenService[] servicesToRun, bool asWinService)
 {
     if (asWinService)
         Run(servicesToRun);
     else
         Start(servicesToRun);
 }
Esempio n. 2
0
 public void TestGetInfoForNonRegisteredService()
 {
     OpenService os = new OpenService();
     os.ServiceName = "doesn't exists";
     OpenService.ServiceInfo info = os.GetInfo();
     Assert.IsNotNull(info);
     Assert.IsFalse(info.Installed);
     Assert.AreEqual(0, (int)info.WinState);
     Assert.AreEqual(os.ServiceName, info.Name);
     Assert.IsNull(info.DisplayName);
 }
Esempio n. 3
0
 public void TestGetInfoForStandartService()
 {
     OpenService os = new OpenService();
     os.ServiceName = "Workstation";
     OpenService.ServiceInfo info = os.GetInfo();
     Assert.IsNotNull(info);
     Assert.IsTrue(info.Installed);
     Assert.AreEqual("Workstation", info.Name);
     Assert.AreEqual(ServiceControllerStatus.Running, info.WinState);
     Assert.IsNotNull(info.DisplayName);
     Console.WriteLine(info.DisplayName);
 }
Esempio n. 4
0
        public static void Stop(OpenService[] services)
        {
            List<Pair<VoidAction, IAsyncResult>> results = new List<Pair<VoidAction, IAsyncResult>>();

            foreach (OpenService service in services)
            {
                Pair<VoidAction, IAsyncResult> p = new Pair<VoidAction, IAsyncResult>();
                p.A = service.OnStop;
                p.B = p.A.BeginInvoke(null, null);
                results.Add(p);
            }

            foreach (Pair<VoidAction, IAsyncResult> result in results)
                result.A.EndInvoke(result.B);
        }
Esempio n. 5
0
        public static void Start(OpenService[] services)
        {
            List<Pair<StartHandler, IAsyncResult>> results = new List<Pair<StartHandler, IAsyncResult>>();
            string [] args = new string[0];

            foreach (OpenService service in services)
            {
                Pair<StartHandler, IAsyncResult> p = new Pair<StartHandler, IAsyncResult>();
                p.A = service.OnStart;
                p.B = p.A.BeginInvoke(args, null, null);
                results.Add(p);
            }

            foreach (Pair<StartHandler,IAsyncResult> result in results)
                result.A.EndInvoke(result.B);
        }
Esempio n. 6
0
        public static void RunServicesInConsole(OpenService[] services, TextReader input, TextWriter output)
        {
            output.WriteLine("Running in console mode");
            output.Write("Starting {0} services...", services.Length);

            Run(services, false);

            output.WriteLine(" done");

            ListServices(services, output);

            output.WriteLine("Press enter to stop services");
            input.ReadLine();

            output.WriteLine("Stopping services...");
            
            Stop(services);
        }