using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Xml.Linq;
using CUE.NET.Brushes;
using CUE.NET.Devices.Generic;
using CUE.NET.Devices.Generic.Enums;
namespace CUE.NET.Profiles
{
///
/// Represents a mode of a CUE profile.
///
[Obsolete("Only works with CUE 1.")]
internal class CueProfileMode
{
#region Properties & Fields
///
/// Gets the name of the mode.
///
internal string Name { get; }
private Dictionary _colors;
#endregion
#region Brush Conversion
///
/// Converts a to a .
///
/// The profile mode to convert.
public static implicit operator ProfileBrush(CueProfileMode profile)
{
return profile != null ? new ProfileBrush(profile._colors) : null;
}
#endregion
#region Constructors
private CueProfileMode(string name)
{
this.Name = name;
}
#endregion
#region Methods
///
/// Loads a mode of a CUE profile from the given XML-node.
///
/// The node containing the mode.
/// The loaded or null.
internal static CueProfileMode Load(XElement modeRoot)
{
// ReSharper disable PossibleNullReferenceException - Just let it fail - no need to check anything here ...
try
{
if (modeRoot == null) return null;
return new CueProfileMode(modeRoot.Element("name").Value)
{
_colors = modeRoot.Element("lightBackgrounds").Element("keyBgLights").Elements("lightBackground")
.Select(x =>
{
string name = x.Attribute("key").Value;
if (name.Length == 1 && char.IsDigit(name[0])) // Our enum names can't be digit only so we need to map them
name = 'D' + name;
return new
{
key = (CorsairLedId)Enum.Parse(typeof(CorsairLedId), name),
color = (CorsairColor)ColorTranslator.FromHtml(x.Attribute("color").Value)
};
})
.ToDictionary(x => x.key, x => x.color)
};
}
// 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
}
}