示例#1
0
        public virtual void OnStart(StageArgs args)
        {
            var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
            var logs          = Path.Combine(baseDirectory, "logs");

            Directory.CreateDirectory(logs);

            var logConfig = new LoggerConfiguration()
                            .Enrich.FromLogContext()
                            .Enrich.WithProperty("SoftwareName", _serviceName)
                            .WriteTo.ColoredConsole()
                            .WriteTo.RollingFile(logs);

            var config = args.TryGetInstance <ILogConfig>();

            if (config != null && config.EnableKibana)
            {
                logConfig.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(config.LoggingEndpoint)
                {
                    AutoRegisterTemplate = true
                });
            }

            Log.Logger = logConfig.CreateLogger();

            AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
        }
示例#2
0
        public void OnStart(StageArgs args)
        {
            var name        = _attributes.OfType <AssemblyTitleAttribute>().SingleOrDefault()?.Title;
            var description = _attributes.OfType <AssemblyDescriptionAttribute>().SingleOrDefault()?.Description;

            args.Metadata.Name        = name ?? string.Empty;
            args.Metadata.Description = description ?? string.Empty;
        }
示例#3
0
        public void When_an_IStartup_implementation_cannot_be_found()
        {
            var args = new StageArgs(new string[0])
            {
                InstanceFactory = type => null
            };

            Should.Throw <StartupNotFoundException>(() => _asyncRunner.OnStart(args));
        }
示例#4
0
        public virtual void OnStart(StageArgs args)
        {
            var registration = args.TryGetInstance <IConsulRegistration>();

            if (registration != null)
            {
                var client = new ConsulClient();
                client.Catalog.Register(registration.CreateRegistration());
            }
        }
示例#5
0
        public void OnStart(StageArgs args)
        {
            _startup = args.TryGetInstance <IStartup>();

            if (_startup == null)
            {
                throw new StartupNotFoundException();
            }

            _startup.Execute(new ServiceArgs(args.StartArgs, () => false));
        }
示例#6
0
        public virtual void OnStop(StageArgs args)
        {
            try
            {
                _source.Cancel();
                _runner.Wait();
            }
            catch (TaskCanceledException)
            {
            }

            (_startup as IDisposable)?.Dispose();
        }
示例#7
0
        public virtual void OnStart(StageArgs args)
        {
            _startup = args.TryGetInstance <IStartup>();

            if (_startup == null)
            {
                throw new StartupNotFoundException();
            }

            _serviceArgs = new ServiceArgs(args.StartArgs, () => _source.IsCancellationRequested);

            _runner.Start();
        }
示例#8
0
        public void The_args_used_in_stop_are_same_as_start()
        {
            StageArgs startArgs = null;
            StageArgs stopArgs  = null;

            var stage = new TestStage((ts, a) => startArgs = a, (ts, a) => stopArgs = a);

            var pipeline = new Pipeline(new[] { stage });

            pipeline.OnStart(new string[0]);
            pipeline.OnStop();

            stopArgs.ShouldBe(startArgs);
        }
示例#9
0
        public virtual void OnStart(StageArgs args)
        {
            _container = new Container(c =>
            {
                c.Scan(a =>
                {
                    a.TheCallingAssembly();
                    a.LookForRegistries();

                    a.Convention <AllInterfacesConvention>();
                    a.WithDefaultConventions();
                });
            });

            args.InstanceFactory = _container.TryGetInstance;
        }
 public ServiceMetadataStageTests()
 {
     _stageArgs = new StageArgs(new string[0]);
 }
示例#11
0
 public void OnStop(StageArgs args)
 {
     throw new System.NotImplementedException();
 }
示例#12
0
 public void OnStop(StageArgs args)
 {
     (_startup as IDisposable)?.Dispose();
 }
示例#13
0
 public virtual void OnStop(StageArgs args)
 {
     _container?.Dispose();
 }
示例#14
0
 public void OnStop(StageArgs args)
 {
 }
示例#15
0
 public StageArgsTests()
 {
     _args = new StageArgs(new PipelineCustomisation(), new string[0]);
 }
示例#16
0
 public virtual void OnStop(StageArgs args)
 {
     AppDomain.CurrentDomain.UnhandledException -= OnUnhandledException;
 }
示例#17
0
 public StageArgsTests()
 {
     _args = new StageArgs(new string[0]);
 }
示例#18
0
 public virtual void OnStart(StageArgs args) => _onExecute?.Invoke(this, args);
示例#19
0
 public virtual void OnStop(StageArgs args) => _onDispose?.Invoke(this, args);