using System; using System.Collections.Generic; using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Utils; namespace Sarand.Net.Standard.Base.App { //======================================================================= public partial class SacsSystem { //------------------------------------------------------------------- // Data members. private static readonly List statusCodes = new List(); private static readonly List messageLevels = new List(); private static readonly List interfaceCategories = new List(); private static readonly List interfaceProcessDirections = new List(); //------------------------------------------------------------------- // Static initialisation. static SacsSystem () { // Status codes. statusCodes.Add(SaStatus.Current, "CUR", "Current"); statusCodes.Add(SaStatus.Redundant, "RED", "Redundant"); statusCodes.Add(SaStatus.Superseded, "SUP", "Superseded"); statusCodes.Add(SaStatus.Discontinued, "DSC", "Discontinued"); statusCodes.Add(SaStatus.Provisional, "PRO", "Provisional"); statusCodes.Add(SaStatus.Confirmed, "CON", "Confirmed"); statusCodes.Add(SaStatus.Enabled, "ENA", "Enabled"); statusCodes.Add(SaStatus.Disabled, "DIS", "Disabled"); statusCodes.Add(SaStatus.Created, "CRE", "Created"); statusCodes.Add(SaStatus.Updated, "UPD", "Updated"); statusCodes.Add(SaStatus.Reinstated, "REI", "Reinstated"); statusCodes.Add(SaStatus.Deleted, "DEL", "Deleted"); statusCodes.Add(SaStatus.Required, "REQ", "Required"); statusCodes.Add(SaStatus.Awaiting, "AWA", "Awaiting"); statusCodes.Add(SaStatus.Preparation, "PRE", "Preparation"); statusCodes.Add(SaStatus.Raised, "RAI", "Raised"); statusCodes.Add(SaStatus.InProgress, "WIP", "In progress"); statusCodes.Add(SaStatus.Active, "ATV", "Active"); statusCodes.Add(SaStatus.Inactive, "INA", "Inactive"); statusCodes.Add(SaStatus.OnHold, "HLD", "On Hold"); statusCodes.Add(SaStatus.Imported, "IMP", "Imported"); statusCodes.Add(SaStatus.Exported, "EXP", "Exported"); statusCodes.Add(SaStatus.Open, "OPE", "Open"); statusCodes.Add(SaStatus.Closed, "CLO", "Closed"); statusCodes.Add(SaStatus.Completed, "COM", "Completed"); statusCodes.Add(SaStatus.Invoiced, "INV", "Invoiced"); statusCodes.Add(SaStatus.Cancelled, "CAN", "Cancelled"); statusCodes.Add(SaStatus.Successful, "SUC", "Successful"); statusCodes.Add(SaStatus.Failed, "FAI", "Failed"); statusCodes.Add(SaStatus.Actioned, "ACT", "Actioned"); statusCodes.Add(SaStatus.Authorised, "AUT", "Authorised"); statusCodes.Add(SaStatus.Accepted, "ACC", "Accepted"); statusCodes.Add(SaStatus.Rejected, "REJ", "Rejected"); statusCodes.Add(SaStatus.Submitted, "SUB", "Submitted"); statusCodes.Add(SaStatus.Queried, "QUE", "Queried"); statusCodes.Add(SaStatus.Granted, "GRA", "Granted"); statusCodes.Add(SaStatus.Denied, "DEN", "Denied"); statusCodes.Add(SaStatus.Logged, "LOG", "Logged"); // Message levels. messageLevels.Add(SaMessageLevel.Fatal, "FAT", "Fatal"); messageLevels.Add(SaMessageLevel.Exception, "EXC", "Exception"); messageLevels.Add(SaMessageLevel.Error, "ERR", "Error"); messageLevels.Add(SaMessageLevel.Warning, "WRN", "Warning"); messageLevels.Add(SaMessageLevel.Info, "INF", "Info"); messageLevels.Add(SaMessageLevel.Debug, "DBG", "Debug"); messageLevels.Add(SaMessageLevel.Trace, "TRC", "Trace"); // Interface categories. interfaceCategories.Add(SaInterfaceCategory.Website, "WEB", "Website"); interfaceCategories.Add(SaInterfaceCategory.Accounts, "ACC", "Accounts"); interfaceCategories.Add(SaInterfaceCategory.System, "SYS", "System"); interfaceCategories.Add(SaInterfaceCategory.File, "FIL", "File"); // Interface process directions. interfaceProcessDirections.Add(SaInterfaceProcessDirection.Inbound, "INB", "Inbound"); interfaceProcessDirections.Add(SaInterfaceProcessDirection.Outbound, "OUT", "Outbound"); interfaceProcessDirections.Add(SaInterfaceProcessDirection.Both, "BTH", "In/Out"); } //------------------------------------------------------------------- // Protected Construction. protected SacsSystem () : base() { } //------------------------------------------------------------------- // E n v i r o n m e n t //------------------------------------------------------------------- public enum AppMode { Debug, Release, } /// Debug or Release. public static AppMode Mode { get; } = #if !DEBUG AppMode.Release; #else AppMode.Debug; #endif public static bool DebugMode { get { return Mode == AppMode.Debug; } } public static bool ReleaseMode { get { return Mode == AppMode.Release; } } public static bool IsDevHost () { return ComputerName.StartsWithCI("sarand"); } //------------------------------------------------------------------- /// /// Computer name /// Windows: System.Environment.MachineName /// Web: HttpContext.Current.Server.MachineName /// FQDN: System.Net.Dns.GetHostName() /// public static String ComputerName { get; protected set; } = String.Empty; //------------------------------------------------------------------- /// To be populated by applicationWindows: Environment.UserName public static String UserName { get; protected set; } = String.Empty; //------------------------------------------------------------------- /// /// Application Path. /// Windows: System.Reflection.Assembly.GetEntryAssembly().Location; /// public static String ApplicationPath { get; protected set; } = String.Empty; //------------------------------------------------------------------- /// /// Application folder. /// Windows: System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); /// public static String ApplicationFolder { get; protected set; } = String.Empty; //------------------------------------------------------------------- /// /// DateTime when the executing assembly was built. /// public static DateTime AssemblyBuildAt { get; set; } = DateTime.Now; //------------------------------------------------------------------- // C o d e L i s t s //------------------------------------------------------------------- public static List GetCodesOfType (SaSysCodeType codeType) { switch (codeType) { case SaSysCodeType.MessageLevel: return new List(messageLevels); case SaSysCodeType.InterfaceCategory: return new List(interfaceCategories); case SaSysCodeType.InterfaceProcessDirection: return new List(interfaceProcessDirections); } return null; } //------------------------------------------------------------------- // Status utilities. public static SaStatus GetStatusForCode (String status) { return (SaStatus)statusCodes.GetTypeForCode(status,(int)SaStatus.Unknown); } public static String GetStatusCode (SaStatus status) { return statusCodes.GetCodeForType(status, status.ToString()); } public static String GetStatusDesc (SaStatus status) { return statusCodes.GetDescForType(status, status.ToString()); } public static String GetStatusDescForCode (String status) { return statusCodes.GetDescForCode(status, status); } public static List GetStatusCodeList (List statuses) { List statusCodeList = new List(); foreach (var status in statuses) { TypeCodeDesc statusCode = statusCodes.Find(x => x.Type==(int)status); if (statusCode != null) statusCodeList.Add(statusCode); } return statusCodeList; } //------------------------------------------------------------------- // Message level utilities. public static SaMessageLevel GetMessageLevelFromCode (String code) { return (SaMessageLevel)messageLevels.GetTypeForCode(code); } public static String GetMessageLevelCode (SaMessageLevel level) { return messageLevels.GetCodeForType(level); } //------------------------------------------------------------------- } //======================================================================= }