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