202 lines
8.3 KiB
C#
202 lines
8.3 KiB
C#
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<TypeCodeDesc> statusCodes = new List<TypeCodeDesc>();
|
|
private static readonly List<TypeCodeDesc> messageLevels = new List<TypeCodeDesc>();
|
|
private static readonly List<TypeCodeDesc> interfaceCategories = new List<TypeCodeDesc>();
|
|
private static readonly List<TypeCodeDesc> interfaceProcessDirections = new List<TypeCodeDesc>();
|
|
|
|
//-------------------------------------------------------------------
|
|
// 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, }
|
|
/// <summary>Debug or Release.</summary>
|
|
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");
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>
|
|
/// Computer name
|
|
/// <para>Windows: System.Environment.MachineName</para>
|
|
/// <para>Web: HttpContext.Current.Server.MachineName</para>
|
|
/// <para>FQDN: System.Net.Dns.GetHostName()</para>
|
|
/// </summary>
|
|
public static String ComputerName { get; protected set; } = String.Empty;
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>To be populated by application<para>Windows: Environment.UserName</para></summary>
|
|
public static String UserName { get; protected set; } = String.Empty;
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>
|
|
/// Application Path.
|
|
/// <para>Windows: System.Reflection.Assembly.GetEntryAssembly().Location;</para>
|
|
/// </summary>
|
|
public static String ApplicationPath { get; protected set; } = String.Empty;
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>
|
|
/// Application folder.
|
|
/// <para>Windows: System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);</para>
|
|
/// </summary>
|
|
public static String ApplicationFolder { get; protected set; } = String.Empty;
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>
|
|
/// DateTime when the executing assembly was built.
|
|
/// </summary>
|
|
public static DateTime AssemblyBuildAt { get; set; } = DateTime.Now;
|
|
|
|
//-------------------------------------------------------------------
|
|
// C o d e L i s t s
|
|
//-------------------------------------------------------------------
|
|
public static List<TypeCodeDesc> GetCodesOfType (SaSysCodeType codeType)
|
|
{
|
|
switch (codeType)
|
|
{
|
|
case SaSysCodeType.MessageLevel:
|
|
return new List<TypeCodeDesc>(messageLevels);
|
|
case SaSysCodeType.InterfaceCategory:
|
|
return new List<TypeCodeDesc>(interfaceCategories);
|
|
case SaSysCodeType.InterfaceProcessDirection:
|
|
return new List<TypeCodeDesc>(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<TypeCodeDesc> GetStatusCodeList (List<SaStatus> statuses)
|
|
{
|
|
List <TypeCodeDesc> statusCodeList = new List<TypeCodeDesc>();
|
|
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);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|