using System; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; using CUE.NET.Brushes; namespace CUE.NET.Profiles { /// /// Represents a device of a CUE profile. /// [Obsolete("Only works with CUE 1.")] internal class CueProfileDevice { #region Properties & Fields /// /// The name of the device. /// internal string Name { get; } /// /// Returns a list of strings containing the name of all modes available for this device. /// internal IEnumerable Modes => _modes.Keys.ToList(); private Dictionary _modes; #endregion #region Brush Conversion /// /// Returns the for the given mode. /// /// The mode to select. /// The of the given mode. internal ProfileBrush this[string mode] { get { if (mode == null) mode = _modes.Keys.FirstOrDefault(); CueProfileMode cpm; return (mode != null && _modes.TryGetValue(mode, out cpm)) ? cpm : null; } } #endregion #region Constructors private CueProfileDevice(string name) { this.Name = name; } #endregion #region Methods /// /// Loads a device of a CUE profile from the given XML-node. /// /// The node containing the device. /// The loaded or null. internal static CueProfileDevice Load(XElement deviceRoot) { // ReSharper disable PossibleNullReferenceException - Just let it fail - no need to check anything here ... try { if (deviceRoot == null) return null; return new CueProfileDevice(deviceRoot.Element("modelName").Value) { _modes = deviceRoot.Element("modes").Elements("mode") .Select(CueProfileMode.Load) .Where(x => x != null) .ToDictionary(x => x.Name) }; } // ReSharper disable once CatchAllClause - I have no idea how the factory pattern should handle such a case - time to read :p catch { return null; } // ReSharper restore PossibleNullReferenceException } #endregion } }