using System; using System.Collections.Generic; using System.Linq; using System.Text; using Crestron.SimplSharp; using Serilog.Events; //using PepperDash.Core; namespace PepperDash.Core.JsonToSimpl { /// /// The global class to manage all the instances of JsonToSimplMaster /// public class J2SGlobal { static List Masters = new List(); /// /// Adds a file master. If the master's key or filename is equivalent to any existing /// master, this will fail /// /// New master to add /// public static void AddMaster(JsonToSimplMaster master) { if (master == null) throw new ArgumentNullException("master"); if (string.IsNullOrEmpty(master.UniqueID)) throw new InvalidOperationException("JSON Master cannot be added with a null UniqueId"); Debug.LogMessage(LogEventLevel.Debug, "JSON Global adding master {0}", master.UniqueID); if (Masters.Contains(master)) return; var existing = Masters.FirstOrDefault(m => m.UniqueID.Equals(master.UniqueID, StringComparison.OrdinalIgnoreCase)); if (existing == null) { Masters.Add(master); } else { var msg = string.Format("Cannot add JSON Master with unique ID '{0}'.\rID is already in use on another master.", master.UniqueID); CrestronConsole.PrintLine(msg); ErrorLog.Warn(msg); } } /// /// Gets a master by its key. Case-insensitive /// public static JsonToSimplMaster GetMasterByFile(string file) { return Masters.FirstOrDefault(m => m.UniqueID.Equals(file, StringComparison.OrdinalIgnoreCase)); } } }