Ejemplo n.º 1
0
        // The main entry point for the process
        static void Main(string[] args)
        {
            ServiceBase[] ServicesToRun;

            //the unhandled exception handler is set here as opposed to the constructor, since the Main does a lot more things that
            //can cause errors.
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(DefaultErrorHandler);

            try
            {
                string configFilePath = string.Format("{0}.config", Assembly.GetExecutingAssembly().Location);

                logger = LogManager.GetLogger(typeof(ManagerService));
                XmlConfigurator.Configure(new FileInfo(configFilePath));
                Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;

                //create directory and set permissions for dat directory...for logging.
                string datDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "dat");
                Alchemi.Core.Utility.ServiceUtil.CreateDir(datDir, "SYSTEM");

                string opt = null;
                if (args.Length > 0)
                {
                    opt = args [0];
                }

                if (opt != null && opt.ToLower() == "/install")
                {
                    installService();
                }
                else if (opt != null && opt.ToLower() == "/uninstall")
                {
                    uninstallService();
                }
                else
                {
                    // More than one user Service may run within the same process. To add
                    // another service to this process, change the following line to
                    // create a second service object. For example,
                    //
                    //   ServicesToRun = new System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};
                    //

                    ManagerService ms = new ManagerService();
                    if (!ServiceHelper.checkServiceInstallation(ms.ServiceName))
                    {
                        installService();
                    }

                    ServicesToRun = new ServiceBase[] { ms };
                    ServiceBase.Run(ServicesToRun);
                    ms = null;
                }
            }
            catch (Exception ex)
            {
                HandleAllUnknownErrors("Error in Main: ", ex);
            }
        }
Ejemplo n.º 2
0
        // The main entry point for the process
        static void Main(string[] args)
        {
            ServiceBase[] ServicesToRun;

            //the unhandled exception handler is set here as opposed to the constructor, since the Main does a lot more things that
            //can cause errors.
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(DefaultErrorHandler);

            try
            {
                string configFilePath = string.Format("{0}.config",Assembly.GetExecutingAssembly ().Location);

                logger = LogManager.GetLogger(typeof(ManagerService));
                XmlConfigurator.Configure(new FileInfo(configFilePath));
                Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;

                //create directory and set permissions for dat directory...for logging.
                string datDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"dat");
                Alchemi.Core.Utility.ServiceUtil.CreateDir(datDir,"SYSTEM");

                string opt = null ;
                if ( args.Length > 0)
                {
                    opt = args [0];
                }

                if (opt != null && opt.ToLower () == "/install")
                {
                    installService();
                }
                else if (opt != null && opt.ToLower () == "/uninstall")
                {
                    uninstallService();
                }
                else
                {
                    // More than one user Service may run within the same process. To add
                    // another service to this process, change the following line to
                    // create a second service object. For example,
                    //
                    //   ServicesToRun = new System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};
                    //

                    ManagerService ms = new ManagerService();
                    if (!ServiceHelper.checkServiceInstallation(ms.ServiceName))
                    {
                        installService();
                    }

                    ServicesToRun = new ServiceBase[] { ms };
                    ServiceBase.Run(ServicesToRun);
                    ms = null;
                }
            }
            catch (Exception ex)
            {
                HandleAllUnknownErrors("Error in Main: ",ex);
            }
        }