134 lines
4.1 KiB
C#
134 lines
4.1 KiB
C#
using Sarand.BusinessMgr.Net.Standard.Dbas.App;
|
|
using Sarand.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Core.Web.App
|
|
{
|
|
//=======================================================================
|
|
public class SbmSystem_Web : SbmSystem_Dbas
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Static initialisation.</summary>
|
|
static SbmSystem_Web()
|
|
{
|
|
InitComputerName();
|
|
InitUserName();
|
|
InitApplicationPath();
|
|
InitApplicationFolder();
|
|
InitAssemblyBuildAt();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SbmSystem_Web(PropertySet properties) : base(properties)
|
|
{
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>
|
|
/// Computer name
|
|
/// <para>Windows: System.Environment.MachineName</para>
|
|
/// <para>Web: HttpContext.Current.Server.MachineName</para>
|
|
/// <para>FQDN: System.Net.Dns.GetHostName()</para>
|
|
/// </summary>
|
|
private static void InitComputerName()
|
|
{
|
|
try
|
|
{
|
|
ComputerName = System.Environment.MachineName;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
SaLogger.Warn("SbmSystem.InitComputerName Failed to initialise computer name from environment. " + ExceptionUtil.GetErrorStateMessage(exc));
|
|
}
|
|
try
|
|
{
|
|
if (StringUtil.IsEmpty(ComputerName))
|
|
ComputerName = Environment.GetEnvironmentVariable("CUMPUTERNAME") ?? Environment.GetEnvironmentVariable("HOSTNAME");
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
SaLogger.Warn("SbmSystem.InitComputerName Failed to initialise computer name from environment variable. " + ExceptionUtil.GetErrorStateMessage(exc));
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>To be populated by application<para>Windows: Environment.UserName</para></summary>
|
|
private static void InitUserName()
|
|
{
|
|
try
|
|
{
|
|
UserName = Environment.UserName;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
SaLogger.Warn("SbmSystem.InitUserName Failed to initialise user name. " + ExceptionUtil.GetErrorStateMessage(exc));
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>
|
|
/// Application Path.
|
|
/// <para>Windows: System.Reflection.Assembly.GetEntryAssembly().Location;</para>
|
|
/// </summary>
|
|
private static void InitApplicationPath()
|
|
{
|
|
try
|
|
{
|
|
ApplicationPath = Assembly.GetEntryAssembly().Location;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
SaLogger.Warn("SbmSystem.InitApplicationPath Failed to initialise application path. " + ExceptionUtil.GetErrorStateMessage(exc));
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>
|
|
/// Application folder.
|
|
/// <para>Windows: System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);</para>
|
|
/// </summary>
|
|
private static void InitApplicationFolder()
|
|
{
|
|
try
|
|
{
|
|
ApplicationFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
SaLogger.Warn("SbmSystem.InitApplicationFolder Failed to initialise application folder. " + ExceptionUtil.GetErrorStateMessage(exc));
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>
|
|
/// DateTime when the executing assembly was built.
|
|
/// </summary>
|
|
private static void InitAssemblyBuildAt()
|
|
{
|
|
try
|
|
{
|
|
// Assembly build date.
|
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
|
AssemblyBuildAt = File.GetLastWriteTime(assembly.Location);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
SaLogger.Warn("SbmSystem.InitAssemblyBuildAt Failed to initialise assembly build date. " + ExceptionUtil.GetErrorStateMessage(exc));
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|