/// <summary>
        /// Initializes a new instance of the <see cref="HackedBaseActorTest"/> class.
        /// </summary>
        /// <param name="description">
        /// The description.
        /// </param>
        protected HackedBaseActorTest(TestDescription description) : base(description.System)
        {
            var containerBuilder = description.ContainerBuilder;

            containerBuilder.RegisterInstance(this.TestActor).As <IActorRef>().Named("testActor", typeof(IActorRef));
            this.Container = containerBuilder.Build();
            this.Sys.AddDependencyResolver(new AutoFacDependencyResolver(this.Container, this.Sys));

            if (description.Configurator.RunPostStart)
            {
                BaseInstaller.RunPostStart(containerBuilder, this.Container);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Service main entry point
        /// </summary>
        /// <param name="args">
        /// Startup parameters
        /// </param>
        public static void Main(string[] args)
        {
            // preset logger
            var loggerConfig = new LoggerConfiguration().MinimumLevel.Debug().WriteTo.ColoredConsole();
            var logger       = loggerConfig.CreateLogger();

            Log.Logger = logger;

            var arguments      = new Docopt().Apply(CommandUsage, args, exit: true);
            var configurations = new List <string>();

            ValueObject config;

            if (arguments.TryGetValue("--config", out config) && config != null)
            {
                configurations.Add(config.ToString());
                Console.WriteLine($@"Will use config from {config}");
            }

            Container = new ContainerBuilder();
#if APPDOMAIN
            AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) =>
            {
                Log.Logger.Error(
                    eventArgs.ExceptionObject as Exception,
                    "{Type}: Unhandled domain exception {ExceptionMessage} from {SenderType}, terminating: {IsTerminating}\n{StackTrace}",
                    "System",
                    (eventArgs.ExceptionObject as Exception)?.Message,
                    sender?.GetType().Name ?? "unknown",
                    eventArgs.IsTerminating,
                    (eventArgs.ExceptionObject as Exception)?.StackTrace);
            };
#endif
#if CORECLR
            // todo: Handle exception
#endif

            var container = Bootstrapper.ConfigureAndStart(Container, configurations.ToArray());
            var system    = container.Resolve <ActorSystem>();
            Log.Logger.Warning("{Type}: Started", "System");
            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                Log.Logger.Warning("{Type}: Shutdown sequence initiated", "System");
                var cluster = Akka.Cluster.Cluster.Get(system);

                var timeout = TimeSpan.FromSeconds(10);
                if (cluster.IsTerminated || cluster.State.Members.Count == 0)
                {
                    system.Terminate().Wait(timeout);
                }
                else
                {
                    cluster.LeaveAsync().Wait(timeout);
                    system.Terminate().Wait(timeout);
                }

                Log.Logger.Warning("{Type}: Hard stopped", "System");
                eventArgs.Cancel = true;
            };

            system.StartNameSpaceActorsFromConfiguration();
            BaseInstaller.RunPostStart(Container, container);

            var waitedTask = new System.Threading.Tasks.TaskCompletionSource <bool>();
            system.WhenTerminated.ContinueWith(task => waitedTask.SetResult(true));
            waitedTask.Task.Wait();
            Log.Logger.Warning("{Type}: Stopped", "System");
        }