mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-17 05:35:07 +00:00
Splitting ProgramUtils into NetStandard portion
This commit is contained in:
@@ -85,6 +85,8 @@
|
|||||||
<None Include="ObfuscationSettings.cs" />
|
<None Include="ObfuscationSettings.cs" />
|
||||||
<Compile Include="Extensions\ByteExtensions.cs" />
|
<Compile Include="Extensions\ByteExtensions.cs" />
|
||||||
<Compile Include="Extensions\ListExtensions.cs" />
|
<Compile Include="Extensions\ListExtensions.cs" />
|
||||||
|
<Compile Include="ProgramUtils.SimplSharp.cs" />
|
||||||
|
<Compile Include="ProgramUtils.Standard.cs" />
|
||||||
<Compile Include="Properties\Annotations.cs" />
|
<Compile Include="Properties\Annotations.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="RecursionUtils.cs" />
|
<Compile Include="RecursionUtils.cs" />
|
||||||
|
|||||||
@@ -27,6 +27,15 @@ namespace ICD.Common.Utils.IO
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[PublicAPI]
|
||||||
|
public static DateTime GetLastWriteTime(string path)
|
||||||
|
{
|
||||||
|
if (path == null)
|
||||||
|
throw new ArgumentNullException("path");
|
||||||
|
|
||||||
|
return File.GetLastWriteTime(path);
|
||||||
|
}
|
||||||
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static bool Exists(string path)
|
public static bool Exists(string path)
|
||||||
{
|
{
|
||||||
|
|||||||
134
ICD.Common.Utils/ProgramUtils.SimplSharp.cs
Normal file
134
ICD.Common.Utils/ProgramUtils.SimplSharp.cs
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
#if SIMPLSHARP
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
using ICD.Common.Properties;
|
||||||
|
using ICD.Common.Services;
|
||||||
|
using ICD.Common.Services.Logging;
|
||||||
|
using ICD.Common.Utils.Extensions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace ICD.Common.Utils
|
||||||
|
{
|
||||||
|
public static partial class ProgramUtils
|
||||||
|
{
|
||||||
|
private const string APPLICATION_NAME_KEY = "Application Name";
|
||||||
|
private const string APPLICATION_NAME_SIMPL_KEY = "System Name";
|
||||||
|
private const string PROGRAM_FILE_KEY = "Program File";
|
||||||
|
|
||||||
|
private const string COMPILED_ON_KEY = "Compiled On";
|
||||||
|
private const string COMPILER_REVISION_KEY = "Compiler Revision";
|
||||||
|
private const string COMPILER_REVISION_SIMPL_KEY = "Compiler Rev";
|
||||||
|
|
||||||
|
private static Dictionary<string, string> s_ProgComments;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Lazy-load the prog-comments map.
|
||||||
|
/// </summary>
|
||||||
|
private static Dictionary<string, string> ProgComments
|
||||||
|
{
|
||||||
|
get { return s_ProgComments ?? (s_ProgComments = ParseProgComments()); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the program number.
|
||||||
|
/// </summary>
|
||||||
|
[PublicAPI]
|
||||||
|
public static uint ProgramNumber
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return InitialParametersClass.ApplicationNumber;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the compile date of the program.
|
||||||
|
/// </summary>
|
||||||
|
[PublicAPI]
|
||||||
|
public static string CompiledDate { get { return ProgComments.GetDefault(COMPILED_ON_KEY, null); } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the compiler revision version.
|
||||||
|
/// </summary>
|
||||||
|
[PublicAPI]
|
||||||
|
public static Version CompilerRevision
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
string output;
|
||||||
|
|
||||||
|
if (ProgComments.TryGetValue(COMPILER_REVISION_KEY, out output))
|
||||||
|
return new Version(output);
|
||||||
|
|
||||||
|
if (ProgComments.TryGetValue(COMPILER_REVISION_SIMPL_KEY, out output))
|
||||||
|
return new Version(output);
|
||||||
|
|
||||||
|
return new Version(0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the name of the program dll.
|
||||||
|
/// </summary>
|
||||||
|
[PublicAPI]
|
||||||
|
public static string ProgramFile { get { return ProgComments.GetDefault(PROGRAM_FILE_KEY, null); } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the name of the application.
|
||||||
|
/// </summary>
|
||||||
|
[PublicAPI]
|
||||||
|
public static string ApplicationName
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
string output;
|
||||||
|
|
||||||
|
if (ProgComments.TryGetValue(APPLICATION_NAME_KEY, out output))
|
||||||
|
return output;
|
||||||
|
|
||||||
|
ProgComments.TryGetValue(APPLICATION_NAME_SIMPL_KEY, out output);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Parses the prog comments and pulls program information.
|
||||||
|
/// </summary>
|
||||||
|
private static Dictionary<string, string> ParseProgComments()
|
||||||
|
{
|
||||||
|
Dictionary<string, string> output = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
string progInfo = string.Empty;
|
||||||
|
string command = string.Format("progcomments:{0}", ProgramNumber);
|
||||||
|
|
||||||
|
if (!IcdConsole.SendControlSystemCommand(command, ref progInfo))
|
||||||
|
{
|
||||||
|
ServiceProvider.GetService<ILoggerService>().AddEntry(eSeverity.Warning, "Failed to parse prog comments");
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (string line in progInfo.Split(new[] { "\n\r", "\r\n", "\n", "\r" }))
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(line))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
string[] pair = line.Split(':', 2).ToArray();
|
||||||
|
|
||||||
|
if (pair.Length < 2)
|
||||||
|
{
|
||||||
|
ServiceProvider.GetService<ILoggerService>()
|
||||||
|
.AddEntry(eSeverity.Warning, "Failed to parse prog comments line - {0}", line);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
string key = pair[0].Trim();
|
||||||
|
string value = pair[1].Trim();
|
||||||
|
output[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
66
ICD.Common.Utils/ProgramUtils.Standard.cs
Normal file
66
ICD.Common.Utils/ProgramUtils.Standard.cs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#if !SIMPLSHARP
|
||||||
|
using ICD.Common.Properties;
|
||||||
|
using ICD.Common.Utils.IO;
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace ICD.Common.Utils
|
||||||
|
{
|
||||||
|
public static partial class ProgramUtils
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the program number.
|
||||||
|
/// </summary>
|
||||||
|
[PublicAPI]
|
||||||
|
public static uint ProgramNumber
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the compile date of the program.
|
||||||
|
/// </summary>
|
||||||
|
[PublicAPI]
|
||||||
|
public static string CompiledDate
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return IcdFile.GetLastWriteTime(Assembly.GetEntryAssembly().Location).ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the compiler revision version.
|
||||||
|
/// </summary>
|
||||||
|
[PublicAPI]
|
||||||
|
public static Version CompilerRevision
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Assembly.GetEntryAssembly().GetName().Version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the name of the program dll.
|
||||||
|
/// </summary>
|
||||||
|
[PublicAPI]
|
||||||
|
public static string ProgramFile { get { return IcdPath.GetFileName(Assembly.GetEntryAssembly().Location); } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the name of the application.
|
||||||
|
/// </summary>
|
||||||
|
[PublicAPI]
|
||||||
|
public static string ApplicationName
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Assembly.GetEntryAssembly().GetName().Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -1,112 +1,16 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using ICD.Common.Properties;
|
using ICD.Common.Properties;
|
||||||
using ICD.Common.Services;
|
|
||||||
using ICD.Common.Services.Logging;
|
|
||||||
using ICD.Common.Utils.Extensions;
|
|
||||||
#if SIMPLSHARP
|
|
||||||
using Crestron.SimplSharp;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace ICD.Common.Utils
|
namespace ICD.Common.Utils
|
||||||
{
|
{
|
||||||
public static class ProgramUtils
|
public static partial class ProgramUtils
|
||||||
{
|
{
|
||||||
private const string APPLICATION_NAME_KEY = "Application Name";
|
|
||||||
private const string APPLICATION_NAME_SIMPL_KEY = "System Name";
|
|
||||||
private const string PROGRAM_FILE_KEY = "Program File";
|
|
||||||
|
|
||||||
private const string COMPILED_ON_KEY = "Compiled On";
|
|
||||||
private const string COMPILER_REVISION_KEY = "Compiler Revision";
|
|
||||||
private const string COMPILER_REVISION_SIMPL_KEY = "Compiler Rev";
|
|
||||||
|
|
||||||
private static Dictionary<string, string> s_ProgComments;
|
|
||||||
|
|
||||||
#region Properties
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Lazy-load the prog-comments map.
|
|
||||||
/// </summary>
|
|
||||||
private static Dictionary<string, string> ProgComments
|
|
||||||
{
|
|
||||||
get { return s_ProgComments ?? (s_ProgComments = ParseProgComments()); }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the program number.
|
|
||||||
/// </summary>
|
|
||||||
[PublicAPI]
|
|
||||||
public static uint ProgramNumber
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
#if SIMPLSHARP
|
|
||||||
return InitialParametersClass.ApplicationNumber;
|
|
||||||
#else
|
|
||||||
return 1;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the program number in the format XX, eg slot 1 is 01.
|
/// Gets the program number in the format XX, eg slot 1 is 01.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static string ProgramNumberFormatted { get { return string.Format("{0:D2}", ProgramNumber); } }
|
public static string ProgramNumberFormatted { get { return string.Format("{0:D2}", ProgramNumber); } }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the compile date of the program.
|
|
||||||
/// </summary>
|
|
||||||
[PublicAPI]
|
|
||||||
public static string CompiledDate { get { return ProgComments.GetDefault(COMPILED_ON_KEY, null); } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the compiler revision version.
|
|
||||||
/// </summary>
|
|
||||||
[PublicAPI]
|
|
||||||
public static Version CompilerRevision
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
string output;
|
|
||||||
|
|
||||||
if (ProgComments.TryGetValue(COMPILER_REVISION_KEY, out output))
|
|
||||||
return new Version(output);
|
|
||||||
|
|
||||||
if (ProgComments.TryGetValue(COMPILER_REVISION_SIMPL_KEY, out output))
|
|
||||||
return new Version(output);
|
|
||||||
|
|
||||||
return new Version(0, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the name of the program dll.
|
|
||||||
/// </summary>
|
|
||||||
[PublicAPI]
|
|
||||||
public static string ProgramFile { get { return ProgComments.GetDefault(PROGRAM_FILE_KEY, null); } }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the name of the application.
|
|
||||||
/// </summary>
|
|
||||||
[PublicAPI]
|
|
||||||
public static string ApplicationName
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
string output;
|
|
||||||
|
|
||||||
if (ProgComments.TryGetValue(APPLICATION_NAME_KEY, out output))
|
|
||||||
return output;
|
|
||||||
|
|
||||||
ProgComments.TryGetValue(APPLICATION_NAME_SIMPL_KEY, out output);
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fakes program info, e.g. "Min Firmware Version : 1.009.0029"
|
/// Fakes program info, e.g. "Min Firmware Version : 1.009.0029"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -139,43 +43,5 @@ namespace ICD.Common.Utils
|
|||||||
|
|
||||||
IcdConsole.PrintLine("{0}: {1}", name, value);
|
IcdConsole.PrintLine("{0}: {1}", name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Parses the prog comments and pulls program information.
|
|
||||||
/// </summary>
|
|
||||||
private static Dictionary<string, string> ParseProgComments()
|
|
||||||
{
|
|
||||||
Dictionary<string, string> output = new Dictionary<string, string>();
|
|
||||||
|
|
||||||
string progInfo = string.Empty;
|
|
||||||
string command = string.Format("progcomments:{0}", ProgramNumber);
|
|
||||||
|
|
||||||
if (!IcdConsole.SendControlSystemCommand(command, ref progInfo))
|
|
||||||
{
|
|
||||||
ServiceProvider.GetService<ILoggerService>().AddEntry(eSeverity.Warning, "Failed to parse prog comments");
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (string line in progInfo.Split(new[] {"\n\r", "\r\n", "\n", "\r"}))
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(line))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
string[] pair = line.Split(':', 2).ToArray();
|
|
||||||
|
|
||||||
if (pair.Length < 2)
|
|
||||||
{
|
|
||||||
ServiceProvider.GetService<ILoggerService>()
|
|
||||||
.AddEntry(eSeverity.Warning, "Failed to parse prog comments line - {0}", line);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
string key = pair[0].Trim();
|
|
||||||
string value = pair[1].Trim();
|
|
||||||
output[key] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user