44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
namespace Landmark.OLA.Application
|
|
{
|
|
public interface IStatus
|
|
{
|
|
string Application { get; }
|
|
DateTime CurrentDate { get; }
|
|
string BuildVersion { get; }
|
|
DateTime BuildDate { get; }
|
|
string Environment { get; }
|
|
}
|
|
|
|
public class Status : IStatus
|
|
{
|
|
public string Application => _env.ApplicationName;
|
|
public DateTime CurrentDate => DateTime.Now;
|
|
public string BuildVersion => Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
public DateTime BuildDate => AssemblyBuildDate();
|
|
public string Environment => _env.EnvironmentName;
|
|
|
|
private readonly IWebHostEnvironment _env;
|
|
|
|
public Status(IWebHostEnvironment env)
|
|
{
|
|
_env = env;
|
|
}
|
|
|
|
public static DateTime AssemblyBuildDate()
|
|
{
|
|
//https://stackoverflow.com/a/804310/266594
|
|
//TODO #246: Look up this value at start up to avoid hitting the filesystem repeatedly
|
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
|
System.IO.FileInfo fileInfo = new(assembly.Location);
|
|
DateTime lastModified = fileInfo.LastWriteTime;
|
|
|
|
return lastModified;
|
|
}
|
|
|
|
}
|
|
}
|