public DiagnosticsExceptionLogger(IDiagnosticsLogger logger, IJsonConverter converter, IDiagnosticsDumpService dump)
 {
     this.logger    = logger;
     this.converter = converter;
     this.dump      = dump;
 }
Exemplo n.º 2
0
        public IWebHost Start()
        {
            container.Install(FromAssembly.This());

            BeforeStart();

            AppConfigurationProvider = container.Resolve <IAppConfigurationProvider>();
            Configuration            = AppConfigurationProvider.Get <WebHostConfiguration>();

            Index   = CreateIndex();
            Storage = CreateStorage();

            container
            .Register(Component.For <IPathResolver>().ImplementedBy <PathResolver>())
            .Register(Component.For <IJsonMergeVisitor>().ImplementedBy <JsonMergeVisitor>())
            .Register(Component.For <IDiagnosticsDumpService>().ImplementedBy <DiagnosticsDumpService>())
            .Register(Component.For <IJsonConverter>().ImplementedBy <DotjemJsonConverter>())
            .Register(Component.For <ILazyComponentLoader>().ImplementedBy <LazyOfTComponentLoader>())
            .Register(Component.For <IWindsorContainer>().Instance(container))
            .Register(Component.For <IWebHost>().Instance(this))
            .Register(Component.For <IStorageIndex>().Instance(Index))
            .Register(Component.For <IStorageContext>().Instance(Storage))
            .Register(Component.For <IWebHostConfiguration>().Instance(Configuration))
            .Register(Component.For <IInitializationTracker>().Instance(Initialization));

            ILogger             perf    = container.Resolve <ILogger>();
            IPerformanceTracker startup = perf.TrackTask("Start");

            DiagnosticsLogger = container.Resolve <IDiagnosticsLogger>();

            perf.TrackAction(BeforeConfigure);
            perf.TrackAction(() => Configure(container.Resolve <IPipeline>()), "Configure Pipeline");
            perf.TrackAction(() => Configure(container), "Configure Container");
            perf.TrackAction(() => Configure(Storage), "Configure Storage");
            perf.TrackAction(() => Configure(Index), "Configure Index");
            perf.TrackAction(() => Configure(new HttpRouterConfigurator(configuration.Routes)), "Configure Routes");
            perf.TrackAction(AfterConfigure);

            ResolveComponents();

            Initialization.SetProgress("Bootstrapping.");
            Task.Factory.StartNew(() =>
            {
                perf.TrackAction(BeforeInitialize);
                Initialization.SetProgress("Initializing storage.");
                perf.TrackAction(() => Initialize(Storage), "Initialize Storage");
                Initialization.SetProgress("Initializing index.");
                perf.TrackAction(() => Initialize(Index), "Initialize Index");

                perf.TrackAction(AfterInitialize);

                storageManager = container.Resolve <IStorageManager>();
                indexManager   = container.Resolve <IStorageIndexManager>();
                Initialization.SetProgress("Loading index.");


                perf.TrackAction(storageManager.Start);
                perf.TrackAction(indexManager.Start);
                perf.TrackAction(AfterStart);

                Initialization.Complete();
                startup.Dispose();
            }).ContinueWith(async result => {
                if (!result.IsFaulted)
                {
                    return;
                }

                IDiagnosticsDumpService dump = Resolve <IDiagnosticsDumpService>();

                Guid ticket = Guid.NewGuid();
                try
                {
                    if (result.Exception != null)
                    {
                        DiagnosticsLogger.LogException(Severity.Fatal, result.Exception, new { ticketId = ticket });
                        dump.Dump(ticket, result.Exception.ToString());
                    }
                    else
                    {
                        DiagnosticsLogger.LogFailure(Severity.Fatal, "Server startup failed. Unknown Error.", new { ticketId = ticket });
                        dump.Dump(ticket, "Server startup failed. Unknown Error.");
                    }

                    Initialization.SetProgress("Server startup failed. Please contact support. ({0})", ticket);
                }
                catch (Exception ex)
                {
                    //TODO: (jmd 2015-10-01) Temporary Dumping of failure we don't know where to put.
                    string dumpMessage =
                        $"{ex}{Environment.NewLine}-----------------------------------{Environment.NewLine}{result.Exception}";
                    Initialization.SetProgress(dumpMessage);
                    dump.Dump(ticket, dumpMessage);
                }

                await Task.Delay(10.Minutes())
                .ContinueWith(t =>
                {
                    //NOTE: (jmd 2019-11-04) This restarts the application.
                    HttpRuntime.UnloadAppDomain();
                });
            });
            return(this);
        }