Ejemplo n.º 1
0
        public bool IsValidStateChangeTo(ModuleState anotherModuleState)
        {
            if (!RecoveriesLeft.HasValue && anotherModuleState.RecoveriesLeft.HasValue ||
                RecoveriesLeft.HasValue && !anotherModuleState.RecoveriesLeft.HasValue)
            {
                throw new ArgumentException(
                          "Cannot compare states with infinite and finite recovery numbers.",
                          nameof(anotherModuleState));
            }

            var infiniteRecoveryPossible = RecoveriesLeft == null;

            if (IsWorking != anotherModuleState.IsWorking && infiniteRecoveryPossible)
            {
                return(true);
            }

            if (IsWorking && !anotherModuleState.IsWorking && RecoveriesLeft == anotherModuleState.RecoveriesLeft)
            {
                return(true);
            }

            if (!IsWorking && anotherModuleState.IsWorking && RecoveriesLeft == anotherModuleState.RecoveriesLeft + 1)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
 public OneStateTransition(ModuleState from, ModuleState to)
 {
     From = from;
     To   = to;
 }