using System; using System.Collections.Generic; using System.Linq; using System.Text; using Crestron.SimplSharp; using PepperDash.Core; using Serilog.Events; namespace PepperDash.Essentials.Core.Fusion { /// /// When created, runs progcomments on every slot and stores the program names in a list /// public class ProcessorProgReg { //public static Dictionary Programs { get; private set; } public static Dictionary GetProcessorProgReg() { var programs = new Dictionary(); for (int i = 1; i <= Global.ControlSystem.NumProgramsSupported; i++) { string response = null; var success = CrestronConsole.SendControlSystemCommand("progcomments:" + i, ref response); var item = new ProcessorProgramItem(); if (!success) item.Name = "Error: PROGCOMMENTS failed"; else { if (response.ToLower().Contains("bad or incomplete")) item.Name = ""; else { var startPos = response.IndexOf("Program File"); var colonPos = response.IndexOf(":", startPos) + 1; var endPos = response.IndexOf(CrestronEnvironment.NewLine, colonPos); item.Name = response.Substring(colonPos, endPos - colonPos).Trim(); item.Exists = true; if (item.Name.Contains(".dll")) { startPos = response.IndexOf("Compiler Revision"); colonPos = response.IndexOf(":", startPos) + 1; endPos = response.IndexOf(CrestronEnvironment.NewLine, colonPos); item.Name = item.Name + "_v" + response.Substring(colonPos, endPos - colonPos).Trim(); } } } programs[i] = item; Debug.LogMessage(LogEventLevel.Debug, "Program {0}: {1}", i, item.Name); } return programs; } } /// /// Used in ProcessorProgReg /// public class ProcessorProgramItem { public bool Exists { get; set; } public string Name { get; set; } } }