Esempio n. 1
0
File: Hybrid.cs Progetto: erynet/IMS
        static void Main(string[] args)
        {
            bool useAppointedLibrary = false;

            var options = new CommandLineOptions();
            
            if (args.Length == 0)
            {
            }
            else
            {
                if (CommandLine.Parser.Default.ParseArguments(args, options))
                {
                    if (options.InstallService || options.UninstallService)
                    {
                        if (options.InstallService)
                        {
                            if (!CheckPrivilege())
                            {
                                Console.WriteLine("This action require administrator privilege");
                                Environment.Exit(0);
                            }
                            ServiceControl.InstallService(StringTable.ServiceName, typeof(HostService).Assembly);
                            ServiceControl.StartService(StringTable.ServiceName);
                        }
                        else
                        {
                            if (!CheckPrivilege())
                            {
                                Console.WriteLine("This action require administrator privilege");
                                Environment.Exit(0);
                            }
                            ServiceControl.StopService(StringTable.ServiceName);
                            ServiceControl.UninstallService(StringTable.ServiceName, typeof(HostService).Assembly);
                        }
                        Environment.Exit(0);
                    }

                    useAppointedLibrary = options.LibName != "NoSuchValue";
                }
                else
                {
                    Environment.Exit(0);
                }
            }


            if (Environment.UserInteractive)
            {
                var core = new Core();

                core.Log += LogEventTerminalReceiver;
                if (useAppointedLibrary)
                {
                    if (!core.Attach(options.LibName))
                    {
                        Console.WriteLine("Error occur in initializing sub components");
                        Environment.Exit(0);
                    }
                }
                else
                {
                    if (!core.Attach())
                    {
                        Console.WriteLine("Error occur in initializing sub components");
                        Environment.Exit(0);
                    }
                }
                
                Console.CancelKeyPress += new ConsoleCancelEventHandler(
                    delegate (object sender, ConsoleCancelEventArgs arg)
                    {
                        //Console.WriteLine("Ctrl-C detected");

                        core.Dispose();
                        arg.Cancel = true;
                    }
                );

                var t = new Thread(core.Run);
                t.Start();
            }
            else
            {
                var cs = new HostService();
                ServiceBase.Run(cs);
            }

        }
Esempio n. 2
0
File: Hybrid.cs Progetto: erynet/IMS
 private void InitializeComponent()
 {
     components = new System.ComponentModel.Container();
     ServiceName = StringTable.ServiceName;
     
     _core = new Core();
 }