/// <summary>
        /// Reads a config file into a Dictionary of command sets
        /// </summary>
        /// <param name="configFile">The config file to load</param>
        /// <returns>A Dictionary of command sets</returns>
        public static CommandSetList Read(string configFile)
        {
            var commands = new CommandSetList();

            if (File.Exists(configFile))
            {
                string[] lines = File.ReadAllLines(configFile);
                commands = Read(lines);
            }

            return(commands);
        }
        /// <summary>
        /// Initializes a new instance of the CommandCenter class using the specified missile launcher model and HID library implementation.
        /// </summary>
        /// <param name="launcher">missile launcher model you want to control</param>
        /// <param name="device">HID library that will be used</param>
        /// <remarks>This is only for testing - HidLibrary is the default library for production use</remarks>
        internal CommandCenter(ILauncherModel launcher, IHidDevice device)
        {
            if (launcher == null)
            {
                throw new ArgumentException(Resources.LauncherIsNull);
            }

            if (device == null)
            {
                throw new ArgumentException(Resources.DeviceIsNull);
            }

            this.launcher = launcher;
            this.device   = device;
            this.sets     = new CommandSetList();

            device.Initialize(launcher.VendorId, launcher.DeviceId);
        }
        /// <summary>
        /// Reads a config file into a Dictionary of command sets
        /// </summary>
        /// <param name="configFileLines">The config file lines</param>
        /// <returns>A Dictionary of command sets</returns>
        public static CommandSetList Read(string[] configFileLines)
        {
            var commands = new CommandSetList();

            string key = string.Empty;

            foreach (string line in configFileLines)
            {
                if (line.StartsWith("[") && line.EndsWith("]"))
                {
                    key = line.Substring(1, line.Length - 2);
                }
                else if (line.Length > 0 && !line.StartsWith("#")) // ignore empty lines and #comments
                {
                    if (string.IsNullOrEmpty(key))
                    {
                        throw new InvalidOperationException(Resources.FirstLineMustBeCommandSetName);
                    }

                    var items = line.Split(',');

                    if (items.Length != 2)
                    {
                        throw new InvalidOperationException(Resources.LineDoesNotContainTwoItems + line);
                    }

                    int value;

                    if (!int.TryParse(items[1], out value))
                    {
                        throw new InvalidOperationException(Resources.SecondItemMustBeNumeric + line);
                    }

                    commands.Add(key, items[0], value);
                }
            }
            return(commands);
        }
 /// <summary>
 /// Loads a list of command sets from a config file (execute command sets with RunCommandSet)
 /// </summary>
 /// <param name="configFileLines">The lines of the config file (after loading the file with File.ReadAllLines)</param>
 /// <returns>True if at least one command set was loaded</returns>
 public bool LoadCommandSets(string[] configFileLines)
 {
     sets = ConfigReader.Read(configFileLines);
     return(sets.CountSets() > 0);
 }
 /// <summary>
 /// Loads a list of command sets from a config file (execute command sets with RunCommandSet)
 /// </summary>
 /// <param name="pathToConfigFile">Complete path to the config file</param>
 /// <returns>True if at least one command set was loaded</returns>
 public bool LoadCommandSets(string pathToConfigFile)
 {
     sets = ConfigReader.Read(pathToConfigFile);
     return(sets.CountSets() > 0);
 }