2017-10-27 05:08:18 +02:00
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Text;
|
2018-01-17 08:34:01 +01:00
|
|
|
|
using NBXplorer;
|
2018-04-19 09:54:25 +02:00
|
|
|
|
using NBitcoin;
|
2018-07-11 15:40:10 +02:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2017-10-27 05:08:18 +02:00
|
|
|
|
|
|
|
|
|
namespace BTCPayServer.Services
|
|
|
|
|
{
|
|
|
|
|
public class BTCPayServerEnvironment
|
|
|
|
|
{
|
2019-03-04 10:33:57 +01:00
|
|
|
|
IHttpContextAccessor httpContext;
|
2018-07-11 15:40:10 +02:00
|
|
|
|
public BTCPayServerEnvironment(IHostingEnvironment env, BTCPayNetworkProvider provider, IHttpContextAccessor httpContext)
|
2017-10-27 10:53:04 +02:00
|
|
|
|
{
|
2019-03-04 10:33:57 +01:00
|
|
|
|
this.httpContext = httpContext;
|
2017-10-27 10:53:04 +02:00
|
|
|
|
Version = typeof(BTCPayServerEnvironment).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>().Version;
|
2017-10-27 05:08:18 +02:00
|
|
|
|
#if DEBUG
|
2017-10-27 10:53:04 +02:00
|
|
|
|
Build = "Debug";
|
2017-10-27 05:08:18 +02:00
|
|
|
|
#else
|
|
|
|
|
Build = "Release";
|
|
|
|
|
#endif
|
2017-10-27 10:53:04 +02:00
|
|
|
|
Environment = env;
|
2018-04-19 09:54:25 +02:00
|
|
|
|
NetworkType = provider.NetworkType;
|
2017-10-27 10:53:04 +02:00
|
|
|
|
}
|
|
|
|
|
public IHostingEnvironment Environment
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
2018-07-11 15:40:10 +02:00
|
|
|
|
|
2019-03-04 10:33:57 +01:00
|
|
|
|
public string ExpectedDomain => httpContext.HttpContext.Request.Host.Host;
|
|
|
|
|
public string ExpectedHost => httpContext.HttpContext.Request.Host.Value;
|
|
|
|
|
public string ExpectedProtocol => httpContext.HttpContext.Request.Scheme;
|
2018-07-11 15:40:10 +02:00
|
|
|
|
|
2018-04-19 09:54:25 +02:00
|
|
|
|
public NetworkType NetworkType { get; set; }
|
2017-10-27 10:53:04 +02:00
|
|
|
|
public string Version
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
|
|
|
|
public string Build
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
2018-02-25 16:48:12 +01:00
|
|
|
|
|
|
|
|
|
public bool IsDevelopping
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2018-04-19 09:54:25 +02:00
|
|
|
|
return NetworkType == NetworkType.Regtest && Environment.IsDevelopment();
|
2018-02-25 16:48:12 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-27 10:53:04 +02:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
StringBuilder txt = new StringBuilder();
|
|
|
|
|
txt.Append($"@Copyright BTCPayServer v{Version}");
|
2017-12-17 14:50:05 +01:00
|
|
|
|
if (!Environment.IsProduction() || !Build.Equals("Release", StringComparison.OrdinalIgnoreCase))
|
2017-10-27 10:53:04 +02:00
|
|
|
|
{
|
|
|
|
|
txt.Append($" Environment: {Environment.EnvironmentName} Build: {Build}");
|
|
|
|
|
}
|
|
|
|
|
return txt.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-27 05:08:18 +02:00
|
|
|
|
}
|