// ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedAutoPropertyAccessor.Global // ReSharper disable UnusedMember.Global using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Xml.Linq; using CUE.NET.Brushes; namespace CUE.NET.Profiles { /// /// Represents a CUE profile. /// [Obsolete("Only works with CUE 1.")] public class CueProfile { #region Properties & Fields private Dictionary _devices; /// /// Gets the Id of the profile. /// public string Id { get; } /// /// Gets the Name of the profile. /// public string Name { get; } /// /// Returns a list of strings containing the name of all modes available. /// public IEnumerable Modes { get { string device = _devices.Keys.FirstOrDefault(); CueProfileDevice cpd; return (device != null && _devices.TryGetValue(device, out cpd)) ? cpd.Modes : new string[0]; } } /// /// Returns the for the given mode. /// /// The mode to select. /// The of the given mode. public ProfileBrush this[string mode] { get { string device = CueSDK.KeyboardSDK?.KeyboardDeviceInfo?.Model; CueProfileDevice cpd; return (device != null && _devices.TryGetValue(device, out cpd)) ? cpd[mode] : null; } } #endregion #region Constructors private CueProfile(string id, string name) { this.Id = id; this.Name = name; } #endregion #region Methods /// /// Loads a CUE profile from the given file. /// /// The profile-file. /// The loaded or null. internal static CueProfile Load(string file) { // ReSharper disable PossibleNullReferenceException - Just let it fail - no need to check anything here ... try { if (!File.Exists(file)) return null; XElement profileRoot = XDocument.Load(file).Root; return new CueProfile(profileRoot.Element("id").Value, profileRoot.Element("name").Value) { _devices = profileRoot.Element("devices").Elements("device") .Select(CueProfileDevice.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 } }