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 eDaysOfWeek flags enum
- Added support for reading the primitive type double to IcdXmlReader and XmlUtils - 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 ProcessorUtils.GetSystemStartTime() to get DateTime the system started instead of a TimeSpan
- Added SimplSharpMono environment to IcdEnvironment, for non-pro 4-series environment
### Changed ### Changed
- Repeater changed to use configured callbacks instead of a dumb event - 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 - 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 - 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 - 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 ## [13.0.0] - 2020-09-03
### Added ### Added

View File

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

View File

@@ -14,14 +14,10 @@ namespace ICD.Common.Utils
/// </summary> /// </summary>
private const string INVALID_VALUE = "Invalid Value"; private const string INVALID_VALUE = "Invalid Value";
private static eRuntimeEnvironment s_RuntimeEnvironment;
#region Properties #region Properties
public static string NewLine { get { return CrestronEnvironment.NewLine; } } public static string NewLine { get { return CrestronEnvironment.NewLine; } }
public static eRuntimeEnvironment RuntimeEnvironment { get { return s_RuntimeEnvironment; } }
/// <summary> /// <summary>
/// Gets the network address(es) of the processor. /// Gets the network address(es) of the processor.
/// </summary> /// </summary>
@@ -197,10 +193,16 @@ namespace ICD.Common.Utils
static IcdEnvironment() static IcdEnvironment()
{ {
// Cache the runtime environment // Cache the runtime environment
s_RuntimeEnvironment = s_Framework = eFramework.Crestron;
CrestronEnvironment.DevicePlatform == eDevicePlatform.Server
? eRuntimeEnvironment.SimplSharpProServer if (CrestronEnvironment.RuntimeEnvironment == eRuntimeEnvironment.SIMPL)
: GetRuntimeEnvironment(CrestronEnvironment.RuntimeEnvironment, Type.GetType("Mono.Runtime") != null); 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.ProgramStatusEventHandler += CrestronEnvironmentOnProgramStatusEventHandler;
CrestronEnvironment.EthernetEventHandler += CrestronEnvironmentOnEthernetEventHandler; 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 #endregion
#region Private Methods #region Private Methods

View File

@@ -14,8 +14,6 @@ namespace ICD.Common.Utils
{ {
public static string NewLine { get { return Environment.NewLine; } } public static string NewLine { get { return Environment.NewLine; } }
public static eRuntimeEnvironment RuntimeEnvironment { get { return eRuntimeEnvironment.Standard; } }
/// <summary> /// <summary>
/// Gets the network address(es) of the processor. /// Gets the network address(es) of the processor.
/// </summary> /// </summary>
@@ -88,6 +86,13 @@ namespace ICD.Common.Utils
[PublicAPI] [PublicAPI]
public static IEnumerable<string> Hostnames { get { yield return Dns.GetHostName(); } } 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() public static DateTime GetLocalTime()
{ {
return DateTime.Now; return DateTime.Now;

View File

@@ -7,18 +7,35 @@ namespace ICD.Common.Utils
public static partial class IcdEnvironment public static partial class IcdEnvironment
{ {
/// <summary> /// <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> /// </summary>
public enum eRuntimeEnvironment public enum eFramework
{ {
SimplSharp, Crestron,
SimplSharpMono,
SimplSharpPro,
SimplSharpProMono,
SimplSharpProServer,
Standard 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> /// <summary>
/// Enum for the Program Event Types /// Enum for the Program Event Types
/// </summary> /// </summary>
@@ -69,9 +86,19 @@ namespace ICD.Common.Utils
/// </summary> /// </summary>
public static event EventHandler OnSystemDateTimeChanged; 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 readonly SafeCriticalSection s_ProgramInitializationSection = new SafeCriticalSection();
private static bool s_ProgramInitializationComplete; 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> /// <summary>
/// Returns true if the program has been flagged as completely initialized. /// Returns true if the program has been flagged as completely initialized.
/// </summary> /// </summary>

View File

@@ -160,28 +160,26 @@ namespace ICD.Common.Utils
if (args.Length > 0) if (args.Length > 0)
message = string.Format(message, args); 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
// Prepend the exception type, append the stack trace if (exception != null)
if (exception != null) message = string.Format("{0}: {1}{2}{3}",
message = string.Format("{0}: {1}{2}{3}", exception.GetType().Name,
exception.GetType().Name, message,
message, IcdEnvironment.NewLine,
IcdEnvironment.NewLine, exception.StackTrace);
exception.StackTrace);
// Prefix severity and time // Prefix severity and time
string fixedSeverity = severity.Substring(0, Math.Min(6, severity.Length)); string fixedSeverity = severity.Substring(0, Math.Min(6, severity.Length));
fixedSeverity = string.Format("{0,-6}", fixedSeverity); fixedSeverity = string.Format("{0,-6}", fixedSeverity);
message = string.Format("{0} - {1} - {2}", fixedSeverity, IcdEnvironment.GetLocalTime(), message); 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 // Color formatting
return s_SeverityToColor[severity].FormatAnsi(message); return s_SeverityToColor[severity].FormatAnsi(message);

View File

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

View File

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

View File

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