using ICD.Common.Utils.Services; using ICD.Common.Utils.Services.Logging; #if SIMPLSHARP using Crestron.SimplSharp; using ICD.Common.Properties; 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 s_ProgComments; /// /// Lazy-load the prog-comments map. /// private static Dictionary ProgComments { get { return s_ProgComments ?? (s_ProgComments = ParseProgComments()); } } /// /// Gets the program number. /// [PublicAPI] public static uint ProgramNumber { get { return InitialParametersClass.ApplicationNumber; } } /// /// Gets the compile date of the program. /// [PublicAPI] public static string CompiledDate { get { return ProgComments.GetDefault(COMPILED_ON_KEY, null); } } /// /// Gets the compiler revision version. /// [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); } } /// /// Gets the name of the program dll. /// [PublicAPI] public static string ProgramFile { get { return ProgComments.GetDefault(PROGRAM_FILE_KEY, null); } } /// /// Gets the name of the application. /// [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; } } /// /// Parses the prog comments and pulls program information. /// private static Dictionary ParseProgComments() { Dictionary output = new Dictionary(); string progInfo = string.Empty; string command = string.Format("progcomments:{0}", ProgramNumber); if (!IcdConsole.SendControlSystemCommand(command, ref progInfo)) { ServiceProvider.GetService().AddEntry(eSeverity.Warning, "Failed to parse prog comments"); return output; } foreach (string line in progInfo.Split(new[] {'\r', '\n'})) { if (string.IsNullOrEmpty(line)) continue; string[] pair = line.Split(':', 2).ToArray(); if (pair.Length < 2) { ServiceProvider.GetService() .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