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. //------------------------------------------------------------------- /// Static initialisation. static SbmSystem_Web() { InitComputerName(); InitUserName(); InitApplicationPath(); InitApplicationFolder(); InitAssemblyBuildAt(); } //------------------------------------------------------------------- // Construction. public SbmSystem_Web(PropertySet properties) : base(properties) { } //------------------------------------------------------------------- /// /// 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("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)); } } //------------------------------------------------------------------- /// To be populated by applicationWindows: Environment.UserName private static void InitUserName() { try { UserName = Environment.UserName; } catch (Exception exc) { SaLogger.Warn("SbmSystem.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("SbmSystem.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("SbmSystem.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("SbmSystem.InitAssemblyBuildAt Failed to initialise assembly build date. " + ExceptionUtil.GetErrorStateMessage(exc)); } } //------------------------------------------------------------------- } //======================================================================= }