Exemplo n.º 1
0
        /// <summary>
        /// Adds the specified switch to the specified actuator.
        /// Notifies the actuator about the switch.  Also adds the
        /// switch to the settings file and saves the settings file
        /// </summary>
        /// <param name="actuator">atuator to add to</param>
        /// <param name="switchSetting">switch to add</param>
        /// <returns>true on success</returns>
        public bool AddSwitch(IActuator actuator, SwitchSetting switchSetting)
        {
            var actuatorSetting = Config.Find(actuator.Descriptor.Id);

            if (actuatorSetting == null)
            {
                return(false);
            }

            var sw = actuatorSetting.Find(switchSetting.Name);

            if (sw != null)
            {
                return(true);
            }

            bool retVal = actuator.Load(new List <SwitchSetting>()
            {
                switchSetting
            });

            if (retVal)
            {
                actuatorSetting.SwitchSettings.Add(switchSetting);
                Config.Save();
            }

            return(retVal);
        }