using System; using System.Collections.Generic; using System.Collections.ObjectModel; using RGB.NET.Core; namespace RGB.NET.Devices.Novation { public class NovationDeviceProvider : IRGBDeviceProvider { #region Properties & Fields private static NovationDeviceProvider _instance; /// /// Gets the singleton instance. /// public static NovationDeviceProvider Instance => _instance ?? new NovationDeviceProvider(); /// /// Indicates if the SDK is initialized and ready to use. /// public bool IsInitialized { get; private set; } /// /// Gets whether the application has exclusive access to the SDK or not. /// public bool HasExclusiveAccess => false; /// public IEnumerable Devices { get; private set; } #endregion #region Constructors /// /// Initializes a new instance of the class. /// /// Thrown if this constructor is called even if there is already an instance of this class. private NovationDeviceProvider() { if (_instance != null) throw new InvalidOperationException($"There can be only one instanc of type {nameof(NovationDeviceProvider)}"); _instance = this; } #endregion #region Methods public bool Initialize(bool exclusiveAccessIfPossible = false, bool throwExceptions = false) { IsInitialized = false; try { IList devices = new List(); //TODO DarthAffe 15.08.2017: Get devices // foreach ... try { NovationRGBDevice device = null; device = new NovationLaunchpadRGBDevice(new NovationLaunchpadRGBDeviceInfo("Launchpad S")); device.Initialize(); devices.Add(device); } catch { if (throwExceptions) throw; //else //continue; } Devices = new ReadOnlyCollection(devices); } catch { if (throwExceptions) throw; else return false; } IsInitialized = true; return true; } public void ResetDevices() { //TODO DarthAffe 15.08.2017: Is this possible? } #endregion } }