示例#1
0
        public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            Name = name;

            var options = providerRuntime.ServiceProvider.GetRequiredService <IOptions <DashboardOptions> >();

            if (options.Value.HostSelf)
            {
                var logger = providerRuntime.ServiceProvider.GetRequiredService <ILogger <Dashboard> >();

                try
                {
                    host =
                        new WebHostBuilder()
                        .ConfigureServices(services =>
                    {
                        services.AddServicesForHostedDashboard(providerRuntime.GrainFactory, options);
                    })
                        .Configure(app =>
                    {
                        if (options.Value.HasUsernameAndPassword())
                        {
                            // only when usename and password are configured
                            // do we inject basicauth middleware in the pipeline
                            app.UseMiddleware <BasicAuthMiddleware>();
                        }

                        app.UseOrleansDashboard();
                    })
                        .UseKestrel()
                        .UseUrls($"http://{options.Value.Host}:{options.Value.Port}")
                        .Build();

                    host.Start();
                }
                catch (Exception ex)
                {
                    logger.Error(10001, ex.ToString());
                }

                logger.LogInformation($"Dashboard listening on {options.Value.Port}");
            }

            // horrible hack to grab the scheduler
            // to allow the stats publisher to push
            // counters to grains
            SiloDispatcher.Setup();

            await ActivateDashboardGrainAsync(providerRuntime);
            await ActivateSiloGrainAsync(providerRuntime);
        }
        public Task Execute(CancellationToken cancellationToken)
        {
            if (dashboardOptions.HostSelf)
            {
                try
                {
                    host =
                        new WebHostBuilder()
                        .ConfigureServices(services =>
                    {
                        services.AddServicesForHostedDashboard(grainFactory, dashboardOptions);
                    })
                        .Configure(app =>
                    {
                        if (dashboardOptions.HasUsernameAndPassword())
                        {
                            // only when usename and password are configured
                            // do we inject basicauth middleware in the pipeline
                            app.UseMiddleware <BasicAuthMiddleware>();
                        }

                        app.UseOrleansDashboard();
                    })
                        .UseKestrel()
                        .UseUrls($"http://{dashboardOptions.Host}:{dashboardOptions.Port}")
                        .Build();

                    host.Start();
                }
                catch (Exception ex)
                {
                    logger.Error(10001, ex.ToString());
                }

                logger.LogInformation($"Dashboard listening on {dashboardOptions.Port}");
            }

            // horrible hack to grab the scheduler
            // to allow the stats publisher to push
            // counters to grains
            SiloDispatcher.Setup();

            return(Task.WhenAll(
                       ActivateDashboardGrainAsync(),
                       ActivateSiloGrainAsync()));
        }