Exemplo n.º 1
0
        protected override void OnExit(ExitEventArgs e)
        {
            base.OnExit(e);

            Logging.Log.Info("Stopping Zetbox Services");
            IServiceControlManager scm = null;

            if (container.TryResolve <IServiceControlManager>(out scm))
            {
                scm.Stop();
            }
            else
            {
                Logging.Log.Info("Service control manager not registered");
            }

            if (serverDomain != null)
            {
                serverDomain.Stop();
            }

            try
            {
                if (container != null)
                {
                    container.Dispose();
                }
            }
            catch (Exception ex)
            {
                // A WCF Proxy may throw an exception while shutting down when the server is not available - WTF?
                Logging.Log.Error("Application_Exit", ex);
            }
        }
Exemplo n.º 2
0
        public static int Main(string[] arguments)
        {
            Logging.Configure();

            Log.InfoFormat("Starting Zetbox Server with args [{0}]", String.Join(" ", arguments));

            try
            {
                var config = ExtractConfig(ref arguments);
                AssemblyLoader.Bootstrap(AppDomain.CurrentDomain, config);

                using (var container = CreateMasterContainer(config))
                {
                    OptionSet options = new OptionSet();

                    // activate all registered options
                    container.Resolve <IEnumerable <Option> >().OrderBy(o => o.Prototype).ForEach(o => options.Add(o));

                    List <string> extraArguments = null;
                    try
                    {
                        extraArguments = options.Parse(arguments);
                    }
                    catch (OptionException e)
                    {
                        Log.Fatal("Error in commandline", e);
                        return(1);
                    }

                    if (extraArguments != null && extraArguments.Count > 0)
                    {
                        Log.FatalFormat("Unrecognized arguments on commandline: {0}", string.Join(", ", extraArguments.ToArray()));
                        return(1);
                    }

                    var actions = config.AdditionalCommandlineActions;

                    // process command line
                    if (actions.Count > 0)
                    {
                        using (Log.DebugTraceMethodCall("CmdLineActions", "processing commandline actions"))
                        {
                            foreach (var action in actions)
                            {
                                using (var innerContainer = container.BeginLifetimeScope())
                                {
                                    action(innerContainer);
                                }
                            }
                        }
                        Log.Info("Shutting down");
                    }
                    else
                    {
                        IServiceControlManager scm = null;
                        if (container.TryResolve <IServiceControlManager>(out scm))
                        {
                            Log.Info("Starting zetbox Services");
                            scm.Start();
                            Log.Info("Waiting for console input to shutdown");
                            Console.WriteLine("Services started, press the anykey to exit");
                            Console.ReadKey();
                            Log.Info("Shutting down");
                        }
                        else
                        {
                            Log.Error("No IServiceControlManager registered");
                        }

                        if (scm != null)
                        {
                            scm.Stop();
                        }
                    }
                }
                Log.Info("Exiting");
                return(0);
            }
            catch (Exception ex)
            {
                Log.Error("Server Application failed:", ex);
                return(1);
            }
        }