Ejemplo n.º 1
0
        private void SetState(string id, params IHardwareParameter[] parameters)
        {
            ThrowIfNoStatesAvailable();
            ThrowIfStateNotSupported(id);

            var oldState = GetState();

            if (AlternativeStateId != null && id == _activeState?.Id)
            {
                id = AlternativeStateId;
            }

            _activeState?.Deactivate(parameters);
            _activeState = _states.First(s => s.Id.Equals(id));
            _activeState.Activate(parameters);

            OnStateChanged(oldState);
        }
Ejemplo n.º 2
0
        public override void SetState(IComponentState id, params IHardwareParameter[] parameters)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            ThrowIfNoStatesAvailable();

            IStateMachineState oldState = _activeState;
            IStateMachineState newState = GetState(id);

            if (newState.Id.Equals(_activeState?.Id))
            {
                if (_turnOffIfStateIsAppliedTwice && GetSupportsState(BinaryStateId.Off) && !GetState().Equals(BinaryStateId.Off))
                {
                    SetState(BinaryStateId.Off, parameters);
                    return;
                }

                if (!parameters.Any(p => p is ForceUpdateStateParameter))
                {
                    return;
                }
            }

            oldState?.Deactivate(parameters);
            newState.Activate(parameters);

            if (parameters.Any(p => p is IsPartOfPartialUpdateParameter))
            {
                return;
            }

            _activeState = newState;
            OnActiveStateChanged(oldState, newState);
        }