feat: Moving environment to 3 properties for Framework, Series, and Runtime

This commit is contained in:
Drew Tingen
2021-01-12 14:56:09 -05:00
committed by Chris Cameron
parent 68365553ed
commit 237b5d3e86
9 changed files with 127 additions and 150 deletions

View File

@@ -17,7 +17,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added eDaysOfWeek flags enum
- Added support for reading the primitive type double to IcdXmlReader and XmlUtils
- Added ProcessorUtils.GetSystemStartTime() to get DateTime the system started instead of a TimeSpan
- Added SimplSharpMono environment to IcdEnvironment, for non-pro 4-series environment
### Changed
- Repeater changed to use configured callbacks instead of a dumb event
@@ -25,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Handling a Crestron bug where File.Exists throws an exception on 4-Series instead of returning false
- Changed ProcessorUtils.ModelVersion to be a string, Crestron pulls model version from CrestronEnvironment
- For 4-series console outputs, replacing \n with \r\n to help console readability
- Changed RuntimeEnvironment to be 3 variables - Framework for Crestron vs Standard, CrestronSeries for 3 vs 4, and CrestronRuntimeEnvironment for Simpl vs SimplSharpPro vs Server
## [13.0.0] - 2020-09-03
### Added

View File

@@ -62,8 +62,7 @@ namespace ICD.Common.Utils
message = FixLineEndings(message);
#if SIMPLSHARP
if (IcdEnvironment.RuntimeEnvironment == IcdEnvironment.eRuntimeEnvironment.SimplSharpPro ||
IcdEnvironment.RuntimeEnvironment == IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono)
if (IcdEnvironment.CrestronRuntimeEnvironment == IcdEnvironment.eCrestronRuntimeEnvironment.Appliance)
{
try
{
@@ -89,7 +88,7 @@ namespace ICD.Common.Utils
try
{
#if SIMPLSHARP
if (IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer)
if (IcdEnvironment.CrestronRuntimeEnvironment != IcdEnvironment.eCrestronRuntimeEnvironment.Server)
CrestronConsole.PrintLine(fixedMessage);
#else
Console.WriteLine(fixedMessage);
@@ -130,7 +129,7 @@ namespace ICD.Common.Utils
try
{
#if SIMPLSHARP
if (IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer)
if (IcdEnvironment.CrestronRuntimeEnvironment != IcdEnvironment.eCrestronRuntimeEnvironment.Server)
CrestronConsole.Print(fixedMessage);
#else
Console.Write(message);
@@ -166,7 +165,7 @@ namespace ICD.Common.Utils
{
#if SIMPLSHARP
// No console on VC4
if (IcdEnvironment.RuntimeEnvironment == IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer)
if (IcdEnvironment.CrestronRuntimeEnvironment == IcdEnvironment.eCrestronRuntimeEnvironment.Server)
return false;
return CrestronConsole.SendControlSystemCommand(command, ref result);
@@ -179,8 +178,7 @@ namespace ICD.Common.Utils
{
#if SIMPLSHARP
// Avoid crashing Simpl applications
if (IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpPro &&
IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono)
if (IcdEnvironment.CrestronRuntimeEnvironment != IcdEnvironment.eCrestronRuntimeEnvironment.Appliance)
return false;
if (CrestronConsole.ConsoleRegistered)
@@ -203,8 +201,7 @@ namespace ICD.Common.Utils
/// <returns></returns>
private static string FixLineEndings(string input)
{
if (IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono
&& IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpMono)
if (IcdEnvironment.CrestronSeries != IcdEnvironment.eCrestronSeries.FourSeries)
return input;
return s_NewLineRegex.Replace(input, NEWLINE);

View File

@@ -14,14 +14,10 @@ namespace ICD.Common.Utils
/// </summary>
private const string INVALID_VALUE = "Invalid Value";
private static eRuntimeEnvironment s_RuntimeEnvironment;
#region Properties
public static string NewLine { get { return CrestronEnvironment.NewLine; } }
public static eRuntimeEnvironment RuntimeEnvironment { get { return s_RuntimeEnvironment; } }
/// <summary>
/// Gets the network address(es) of the processor.
/// </summary>
@@ -197,10 +193,16 @@ namespace ICD.Common.Utils
static IcdEnvironment()
{
// Cache the runtime environment
s_RuntimeEnvironment =
CrestronEnvironment.DevicePlatform == eDevicePlatform.Server
? eRuntimeEnvironment.SimplSharpProServer
: GetRuntimeEnvironment(CrestronEnvironment.RuntimeEnvironment, Type.GetType("Mono.Runtime") != null);
s_Framework = eFramework.Crestron;
if (CrestronEnvironment.RuntimeEnvironment == eRuntimeEnvironment.SIMPL)
s_CrestronRuntimeEnvironment = eCrestronRuntimeEnvironment.Simpl;
else if (CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance)
s_CrestronRuntimeEnvironment = eCrestronRuntimeEnvironment.Appliance;
else
s_CrestronRuntimeEnvironment = eCrestronRuntimeEnvironment.Server;
s_CrestronSeries = Type.GetType("Mono.Runtime") != null ? eCrestronSeries.FourSeries : eCrestronSeries.ThreeSeries;
CrestronEnvironment.ProgramStatusEventHandler += CrestronEnvironmentOnProgramStatusEventHandler;
CrestronEnvironment.EthernetEventHandler += CrestronEnvironmentOnEthernetEventHandler;
@@ -258,19 +260,6 @@ namespace ICD.Common.Utils
}
}
private static eRuntimeEnvironment GetRuntimeEnvironment(Crestron.SimplSharp.eRuntimeEnvironment runtimeEnvironment, bool mono)
{
switch (runtimeEnvironment)
{
case Crestron.SimplSharp.eRuntimeEnvironment.SIMPL:
return mono ? eRuntimeEnvironment.SimplSharpMono : eRuntimeEnvironment.SimplSharp;
case Crestron.SimplSharp.eRuntimeEnvironment.SimplSharpPro:
return mono ? eRuntimeEnvironment.SimplSharpProMono : eRuntimeEnvironment.SimplSharpPro;
default:
throw new ArgumentOutOfRangeException("runtimeEnvironment");
}
}
#endregion
#region Private Methods

View File

@@ -14,8 +14,6 @@ namespace ICD.Common.Utils
{
public static string NewLine { get { return Environment.NewLine; } }
public static eRuntimeEnvironment RuntimeEnvironment { get { return eRuntimeEnvironment.Standard; } }
/// <summary>
/// Gets the network address(es) of the processor.
/// </summary>
@@ -88,6 +86,13 @@ namespace ICD.Common.Utils
[PublicAPI]
public static IEnumerable<string> Hostnames { get { yield return Dns.GetHostName(); } }
static IcdEnvironment()
{
s_Framework = eFramework.Standard;
s_CrestronSeries = eCrestronSeries.Na;
s_CrestronRuntimeEnvironment = eCrestronRuntimeEnvironment.Na;
}
public static DateTime GetLocalTime()
{
return DateTime.Now;

View File

@@ -7,18 +7,35 @@ namespace ICD.Common.Utils
public static partial class IcdEnvironment
{
/// <summary>
/// Enumeration to define the various runtime environments a module can run in.
/// Enumeration to define the various frameworks a module can run in.
/// </summary>
public enum eRuntimeEnvironment
public enum eFramework
{
SimplSharp,
SimplSharpMono,
SimplSharpPro,
SimplSharpProMono,
SimplSharpProServer,
Crestron,
Standard
}
/// <summary>
/// Enumeration to define the Crestron series a module can run it
/// </summary>
public enum eCrestronSeries
{
Na, //Non-Crestron
ThreeSeries,
FourSeries
}
/// <summary>
/// Enumeration to define the various Crestron runtime environments a module can run in
/// </summary>
public enum eCrestronRuntimeEnvironment
{
Na, //Non-Crestron
Simpl, // Running in Simpl, Non-Pro
Appliance, // S#Pro running on a Crestron hardware appliance
Server // S#Pro running on a server (VC-4)
}
/// <summary>
/// Enum for the Program Event Types
/// </summary>
@@ -69,9 +86,19 @@ namespace ICD.Common.Utils
/// </summary>
public static event EventHandler OnSystemDateTimeChanged;
private static eFramework s_Framework;
private static eCrestronSeries s_CrestronSeries;
private static eCrestronRuntimeEnvironment s_CrestronRuntimeEnvironment;
private static readonly SafeCriticalSection s_ProgramInitializationSection = new SafeCriticalSection();
private static bool s_ProgramInitializationComplete;
public static eFramework Framework {get { return s_Framework; }}
public static eCrestronSeries CrestronSeries {get { return s_CrestronSeries; }}
public static eCrestronRuntimeEnvironment CrestronRuntimeEnvironment {get { return s_CrestronRuntimeEnvironment; }}
/// <summary>
/// Returns true if the program has been flagged as completely initialized.
/// </summary>

View File

@@ -160,9 +160,8 @@ namespace ICD.Common.Utils
if (args.Length > 0)
message = string.Format(message, args);
switch (IcdEnvironment.RuntimeEnvironment)
if (IcdEnvironment.Framework == IcdEnvironment.eFramework.Standard)
{
case IcdEnvironment.eRuntimeEnvironment.Standard:
// Prepend the exception type, append the stack trace
if (exception != null)
message = string.Format("{0}: {1}{2}{3}",
@@ -175,13 +174,12 @@ namespace ICD.Common.Utils
string fixedSeverity = severity.Substring(0, Math.Min(6, severity.Length));
fixedSeverity = string.Format("{0,-6}", fixedSeverity);
message = string.Format("{0} - {1} - {2}", fixedSeverity, IcdEnvironment.GetLocalTime(), message);
break;
case IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono:
// Add an extra newline
message += IcdEnvironment.NewLine;
break;
}
// Add an extra newline for 4-series to help formatting
else if(IcdEnvironment.CrestronSeries == IcdEnvironment.eCrestronSeries.FourSeries)
message += IcdEnvironment.NewLine;
// Color formatting
return s_SeverityToColor[severity].FormatAnsi(message);

View File

@@ -26,7 +26,7 @@ namespace ICD.Common.Utils
public static string RootPath {
get
{
if (IcdEnvironment.RuntimeEnvironment == IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer)
if (IcdEnvironment.CrestronRuntimeEnvironment == IcdEnvironment.eCrestronRuntimeEnvironment.Server)
return IcdDirectory.GetApplicationRootDirectory();
return IcdDirectory.GetDirectoryRoot(IcdPath.DirectorySeparatorChar.ToString());
@@ -63,10 +63,9 @@ namespace ICD.Common.Utils
get
{
#if SIMPLSHARP
switch (IcdEnvironment.RuntimeEnvironment)
switch (IcdEnvironment.CrestronSeries)
{
case IcdEnvironment.eRuntimeEnvironment.SimplSharpMono:
case IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono:
case IcdEnvironment.eCrestronSeries.FourSeries:
return Join(RootPath, "user");
default:
return Join(RootPath, "User");
@@ -94,21 +93,11 @@ namespace ICD.Common.Utils
{
get
{
switch (IcdEnvironment.RuntimeEnvironment)
{
case IcdEnvironment.eRuntimeEnvironment.SimplSharp:
case IcdEnvironment.eRuntimeEnvironment.SimplSharpMono:
case IcdEnvironment.eRuntimeEnvironment.SimplSharpPro:
case IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono:
case IcdEnvironment.eRuntimeEnvironment.Standard:
return string.Format("Program{0:D2}Config", ProgramUtils.ProgramNumber);
case IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer:
// Crestron Server doesn't have meaningful program number
if (IcdEnvironment.CrestronRuntimeEnvironment == IcdEnvironment.eCrestronRuntimeEnvironment.Server)
return "ProgramConfig";
default:
throw new ArgumentOutOfRangeException();
}
return string.Format("Program{0:D2}Config", ProgramUtils.ProgramNumber);
}
}
@@ -127,21 +116,11 @@ namespace ICD.Common.Utils
{
get
{
switch (IcdEnvironment.RuntimeEnvironment)
{
case IcdEnvironment.eRuntimeEnvironment.SimplSharp:
case IcdEnvironment.eRuntimeEnvironment.SimplSharpMono:
case IcdEnvironment.eRuntimeEnvironment.SimplSharpPro:
case IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono:
case IcdEnvironment.eRuntimeEnvironment.Standard:
return string.Format("Program{0:D2}Data", ProgramUtils.ProgramNumber);
case IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer:
// Crestron Server doesn't have meaningful program number
if (IcdEnvironment.CrestronRuntimeEnvironment == IcdEnvironment.eCrestronRuntimeEnvironment.Server)
return "ProgramData";
default:
throw new ArgumentOutOfRangeException();
}
return string.Format("Program{0:D2}Data", ProgramUtils.ProgramNumber);
}
}
@@ -177,23 +156,11 @@ namespace ICD.Common.Utils
{
string directoryName;
switch (IcdEnvironment.RuntimeEnvironment)
{
case IcdEnvironment.eRuntimeEnvironment.SimplSharp:
case IcdEnvironment.eRuntimeEnvironment.SimplSharpMono:
case IcdEnvironment.eRuntimeEnvironment.SimplSharpPro:
case IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono:
case IcdEnvironment.eRuntimeEnvironment.Standard:
directoryName = string.Format("Program{0:D2}Logs", ProgramUtils.ProgramNumber);
break;
case IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer:
// Crestron Server doesn't have meaningful program number
if (IcdEnvironment.CrestronRuntimeEnvironment == IcdEnvironment.eCrestronRuntimeEnvironment.Server)
directoryName = "ProgramLogs";
break;
default:
throw new ArgumentOutOfRangeException();
}
else
directoryName = string.Format("Program{0:D2}Logs", ProgramUtils.ProgramNumber);
return Join(RootConfigPath, directoryName);
}
@@ -208,29 +175,25 @@ namespace ICD.Common.Utils
{
get
{
switch (IcdEnvironment.RuntimeEnvironment)
if (IcdEnvironment.Framework == IcdEnvironment.eFramework.Crestron)
{
case IcdEnvironment.eRuntimeEnvironment.SimplSharp:
case IcdEnvironment.eRuntimeEnvironment.SimplSharpPro:
// 3-series
if (IcdEnvironment.CrestronSeries == IcdEnvironment.eCrestronSeries.ThreeSeries)
return Join(RootPath, "HTML");
case IcdEnvironment.eRuntimeEnvironment.SimplSharpMono:
case IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono:
// 4-series non-server (because Crestron)
if (IcdEnvironment.CrestronRuntimeEnvironment == IcdEnvironment.eCrestronRuntimeEnvironment.Appliance)
return Join(RootPath, "html");
case IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer:
// 4-series server (because Crestron)
return Join(RootPath, "Html");
}
case IcdEnvironment.eRuntimeEnvironment.Standard:
#if LINUX
return Join(RootPath, "var", "www", "html");
#else
return "C:\\INetPub";
#endif
default:
throw new ArgumentOutOfRangeException();
}
}
}

View File

@@ -109,16 +109,13 @@ namespace ICD.Common.Utils
try
{
switch (IcdEnvironment.RuntimeEnvironment)
if (IcdEnvironment.CrestronSeries == IcdEnvironment.eCrestronSeries.FourSeries)
{
case IcdEnvironment.eRuntimeEnvironment.SimplSharpMono:
case IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono:
date = StringUtils.RemoveDuplicateWhitespace(date);
return DateTime.ParseExact(date, "MMM d yyyy", CultureInfo.InvariantCulture).ToUniversalTime();
default:
return DateTime.ParseExact(date, "MMM dd yyyy", CultureInfo.InvariantCulture).ToUniversalTime();
}
return DateTime.ParseExact(date, "MMM dd yyyy", CultureInfo.InvariantCulture).ToUniversalTime();
}
catch (FormatException)
{

View File

@@ -21,28 +21,29 @@ namespace ICD.Common.Utils
{
name = (name ?? string.Empty).Trim();
switch (IcdEnvironment.RuntimeEnvironment)
switch (IcdEnvironment.Framework)
{
case IcdEnvironment.eRuntimeEnvironment.SimplSharp:
case IcdEnvironment.eRuntimeEnvironment.SimplSharpMono:
case IcdEnvironment.eFramework.Crestron:
switch (IcdEnvironment.CrestronRuntimeEnvironment)
{
case IcdEnvironment.eCrestronRuntimeEnvironment.Simpl:
int length = Math.Min(13, name.Length);
name = name.Substring(0, length).PadRight(13);
break;
case IcdEnvironment.eRuntimeEnvironment.SimplSharpPro:
case IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono:
case IcdEnvironment.eCrestronRuntimeEnvironment.Appliance:
int proLength = Math.Min(26 - 1, name.Length);
name = name.Substring(0, proLength).PadRight(26);
break;
case IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer:
case IcdEnvironment.eCrestronRuntimeEnvironment.Server:
// No console
return;
case IcdEnvironment.eRuntimeEnvironment.Standard:
default:
throw new ArgumentOutOfRangeException();
}
break;
case IcdEnvironment.eFramework.Standard:
name += ' ';
break;
default:
throw new ArgumentOutOfRangeException();
}