This repository has been archived by the owner on Dec 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 310
/
WebHostOptions.cs
96 lines (74 loc) · 3.73 KB
/
WebHostOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Microsoft.Extensions.Configuration;
namespace Microsoft.AspNetCore.Hosting.Internal
{
public class WebHostOptions
{
public WebHostOptions() { }
public WebHostOptions(IConfiguration configuration)
: this(configuration, string.Empty) { }
public WebHostOptions(IConfiguration configuration, string applicationNameFallback)
{
if (configuration == null)
{
throw new ArgumentNullException(nameof(configuration));
}
ApplicationName = configuration[WebHostDefaults.ApplicationKey] ?? applicationNameFallback;
StartupAssembly = configuration[WebHostDefaults.StartupAssemblyKey];
DetailedErrors = WebHostUtilities.ParseBool(configuration, WebHostDefaults.DetailedErrorsKey);
CaptureStartupErrors = WebHostUtilities.ParseBool(configuration, WebHostDefaults.CaptureStartupErrorsKey);
Environment = configuration[WebHostDefaults.EnvironmentKey];
WebRoot = configuration[WebHostDefaults.WebRootKey];
ContentRootPath = configuration[WebHostDefaults.ContentRootKey];
PreventHostingStartup = WebHostUtilities.ParseBool(configuration, WebHostDefaults.PreventHostingStartupKey);
SuppressStatusMessages = WebHostUtilities.ParseBool(configuration, WebHostDefaults.SuppressStatusMessagesKey);
// Search the primary assembly and configured assemblies.
HostingStartupAssemblies = Split($"{ApplicationName};{configuration[WebHostDefaults.HostingStartupAssembliesKey]}");
HostingStartupExcludeAssemblies = Split(configuration[WebHostDefaults.HostingStartupExcludeAssembliesKey]);
var timeout = configuration[WebHostDefaults.ShutdownTimeoutKey];
if (!string.IsNullOrEmpty(timeout)
&& int.TryParse(timeout, NumberStyles.None, CultureInfo.InvariantCulture, out var seconds))
{
ShutdownTimeout = TimeSpan.FromSeconds(seconds);
}
}
public string ApplicationName { get; set; }
public bool PreventHostingStartup { get; set; }
public bool SuppressStatusMessages { get; set; }
public IReadOnlyList<string> HostingStartupAssemblies { get; set; }
public IReadOnlyList<string> HostingStartupExcludeAssemblies { get; set; }
public bool DetailedErrors { get; set; }
public bool CaptureStartupErrors { get; set; }
public string Environment { get; set; }
public string StartupAssembly { get; set; }
public string WebRoot { get; set; }
public string ContentRootPath { get; set; }
public TimeSpan ShutdownTimeout { get; set; } = TimeSpan.FromSeconds(5);
public IEnumerable<string> GetFinalHostingStartupAssemblies()
{
return HostingStartupAssemblies.Except(HostingStartupExcludeAssemblies, StringComparer.OrdinalIgnoreCase);
}
private IReadOnlyList<string> Split(string value)
{
if (string.IsNullOrWhiteSpace(value))
{
return Array.Empty<string>();
}
var list = new List<string>();
foreach (var part in value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
var trimmedPart = part;
if (!string.IsNullOrEmpty(trimmedPart))
{
list.Add(trimmedPart);
}
}
return list;
}
}
}