Updated Startup and Program to use new .NETCoreApp2.0 templates.Minor Refactorings
This commit is contained in:
parent
c4454b005b
commit
116d5b55bb
@ -1,10 +1,6 @@
|
|||||||
using System;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using Microsoft.Extensions.HealthChecks;
|
using Microsoft.Extensions.HealthChecks;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using WebStatus.Viewmodels;
|
using WebStatus.Viewmodels;
|
||||||
|
|
||||||
namespace WebStatus.Controllers
|
namespace WebStatus.Controllers
|
||||||
@ -29,6 +25,7 @@ namespace WebStatus.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
ViewBag.RefreshSeconds = 60;
|
ViewBag.RefreshSeconds = 60;
|
||||||
|
|
||||||
return View(data);
|
return View(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
using Microsoft.Extensions.HealthChecks;
|
using Microsoft.Extensions.HealthChecks;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace WebStatus.Extensions
|
namespace WebStatus.Extensions
|
||||||
{
|
{
|
||||||
@ -17,6 +14,5 @@ namespace WebStatus.Extensions
|
|||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
using System.IO;
|
using Microsoft.AspNetCore;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace WebStatus
|
namespace WebStatus
|
||||||
{
|
{
|
||||||
@ -7,14 +9,18 @@ namespace WebStatus
|
|||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var host = new WebHostBuilder()
|
BuildWebHost(args).Run();
|
||||||
.UseKestrel()
|
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
|
||||||
.UseIISIntegration()
|
|
||||||
.UseStartup<Startup>()
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
host.Run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IWebHost BuildWebHost(string[] args) =>
|
||||||
|
WebHost.CreateDefaultBuilder(args)
|
||||||
|
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||||
|
.UseStartup<Startup>()
|
||||||
|
.ConfigureLogging((hostingContext, builder) =>
|
||||||
|
{
|
||||||
|
builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
|
||||||
|
builder.AddConsole();
|
||||||
|
builder.AddDebug();
|
||||||
|
}).Build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,22 +13,18 @@ namespace WebStatus
|
|||||||
{
|
{
|
||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
||||||
public Startup(IHostingEnvironment env)
|
public Startup(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
var builder = new ConfigurationBuilder()
|
Configuration = configuration;
|
||||||
.SetBasePath(env.ContentRootPath)
|
|
||||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
|
||||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
|
|
||||||
.AddEnvironmentVariables();
|
|
||||||
Configuration = builder.Build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IConfigurationRoot Configuration { get; }
|
public IConfiguration Configuration { get; }
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to add services to the container.
|
// This method gets called by the runtime. Use this method to add services to the container.
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddOptions();
|
services.AddOptions();
|
||||||
|
|
||||||
// Add framework services.
|
// Add framework services.
|
||||||
services.AddHealthChecks(checks =>
|
services.AddHealthChecks(checks =>
|
||||||
{
|
{
|
||||||
@ -47,15 +43,13 @@ namespace WebStatus
|
|||||||
checks.AddUrlCheckIfNotNull(Configuration["mvc"], TimeSpan.FromMinutes(minutes));
|
checks.AddUrlCheckIfNotNull(Configuration["mvc"], TimeSpan.FromMinutes(minutes));
|
||||||
checks.AddUrlCheckIfNotNull(Configuration["spa"], TimeSpan.FromMinutes(minutes));
|
checks.AddUrlCheckIfNotNull(Configuration["spa"], TimeSpan.FromMinutes(minutes));
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddMvc();
|
services.AddMvc();
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||||
{
|
{
|
||||||
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
|
||||||
loggerFactory.AddDebug();
|
|
||||||
|
|
||||||
if (env.IsDevelopment())
|
if (env.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.UseDeveloperExceptionPage();
|
app.UseDeveloperExceptionPage();
|
||||||
|
@ -1,22 +1,23 @@
|
|||||||
using Microsoft.Extensions.HealthChecks;
|
using Microsoft.Extensions.HealthChecks;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace WebStatus.Viewmodels
|
namespace WebStatus.Viewmodels
|
||||||
{
|
{
|
||||||
public class HealthStatusViewModel
|
public class HealthStatusViewModel
|
||||||
{
|
{
|
||||||
private readonly CheckStatus _overall;
|
private readonly CheckStatus _overall;
|
||||||
|
|
||||||
private readonly Dictionary<string, IHealthCheckResult> _results;
|
private readonly Dictionary<string, IHealthCheckResult> _results;
|
||||||
|
|
||||||
public CheckStatus OverallStatus => _overall;
|
public CheckStatus OverallStatus => _overall;
|
||||||
|
|
||||||
public IEnumerable<NamedCheckResult> Results => _results.Select(kvp => new NamedCheckResult(kvp.Key, kvp.Value));
|
public IEnumerable<NamedCheckResult> Results => _results.Select(kvp => new NamedCheckResult(kvp.Key, kvp.Value));
|
||||||
|
|
||||||
private HealthStatusViewModel() => _results = new Dictionary<string, IHealthCheckResult>();
|
private HealthStatusViewModel() => _results = new Dictionary<string, IHealthCheckResult>();
|
||||||
|
|
||||||
public HealthStatusViewModel(CheckStatus overall) : this() => _overall = overall;
|
public HealthStatusViewModel(CheckStatus overall) : this() => _overall = overall;
|
||||||
|
|
||||||
public void AddResult(string name, IHealthCheckResult result) => _results.Add(name, result);
|
public void AddResult(string name, IHealthCheckResult result) => _results.Add(name, result);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
using Microsoft.Extensions.HealthChecks;
|
using Microsoft.Extensions.HealthChecks;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace WebStatus.Viewmodels
|
namespace WebStatus.Viewmodels
|
||||||
{
|
{
|
||||||
public class NamedCheckResult
|
public class NamedCheckResult
|
||||||
{
|
{
|
||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
|
|
||||||
public IHealthCheckResult Result { get; }
|
public IHealthCheckResult Result { get; }
|
||||||
|
|
||||||
public NamedCheckResult(string name, IHealthCheckResult result)
|
public NamedCheckResult(string name, IHealthCheckResult result)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user