protected InvariantsNotMetException(DateTime ts, LaundryMachineStateCode stateCode, [NotNull] string invariantDescription,
                                     [CanBeNull] Exception inner) : base(string.Empty, inner)
 {
     _message             = new LocklessLazyWriteOnce <string>(CreateMessage);
     TimeStamp            = ts;
     StateCode            = stateCode;
     InvariantDescription = invariantDescription ?? throw new ArgumentNullException(nameof(invariantDescription));
 }
 public RobotActedEventArgs(DateTime ts, [NotNull] string actionDescription, [NotNull] ILaundryRobot robot)
 {
     TimeStamp         = ts;
     RobotName         = (robot ?? throw new ArgumentNullException(nameof(robot))).RobotName;
     RobotId           = robot.RobotId;
     ActionDescription = actionDescription ?? throw new ArgumentNullException(nameof(actionDescription));
     _stringRep        = new LocklessLazyWriteOnce <string>(GetStringRep);
 }
 public StateChangedEventArgs(TStateCode oldState, TStateCode newState, ulong stateChangeCount, DateTime?ts = null)
 {
     TimeStamp        = ts ?? TimeStampSource.Now;
     OldState         = oldState;
     NewState         = newState;
     StateChangeCount = stateChangeCount;
     _stringRep       = new LocklessLazyWriteOnce <string>(() =>
                                                           $"At [{TimeStamp:O}], the state (change# {StateChangeCount}) changed from [{OldState.ToString()}] to [{NewState.ToString()}].");
 }
 private TransitionPredicateTrueEventArgs(TStateCode origin, int priority, [NotNull] string name, [NotNull] string predText,
                                          ImmutableArray <TStateCode> destinations)
 {
     _timeStamp         = TimeStampSource.Now;
     _priority          = priority;
     _originState       = origin;
     _predicateText     = predText ?? throw new ArgumentNullException(nameof(predText));
     _destinationStates = destinations;
     _transitionName    = name ?? throw new ArgumentNullException(nameof(predText));
     _stringRep         = new LocklessLazyWriteOnce <string>(GetStringRep);
 }
Beispiel #5
0
 protected LaundryStressSimulation(TimeSpan addOneDamp, TimeSpan removeOneDirt, TimeSpan removeOneDamp, uint dirtyArticles)
 {
     AddOneDampTime       = addOneDamp;
     RemoveOneDirtTime    = removeOneDirt;
     RemoveOneDampTime    = removeOneDamp;
     _laundryMachines     = new LocklessWriteOnce <ImmutableList <IPublishLaundryMachineEvents> >();
     _wrappers            = new LocklessWriteOnce <ImmutableList <LaundryMachineVault> >();
     _loaderRobots        = new LocklessLazyWriteOnce <ImmutableList <ILaundryRobot> >(InitLoaderRobots);
     _unloaderRobots      = new LocklessLazyWriteOnce <ImmutableList <ILaundryRobot> >(InitUnloaderRobots);
     _initialLaundryItems = new LocklessLazyWriteOnce <ImmutableSortedDictionary <Guid, LaundryItems> >(InitLaundryItems);
     _dirtyArticles       = dirtyArticles;
 }
Beispiel #6
0
        protected LaundryMachineTaskBasedStateBase(LaundryMachineStateCode code,
                                                   CommandIds commandIds, [NotNull] IEventRaiser raiser,
                                                   [NotNull] BasicVault <LaundryMachineStateCode> stateVault, [NotNull] LaundryVault vault,
                                                   [NotNull] ILaundryMachineTaskExecutionContext <TaskResult> executionContext,
                                                   ImmutableArray <LaundryMachineStateCode> nextStatesOnCompletion, TimeSpan addOneUnitDamp, TimeSpan removeOneUnitDirt, TimeSpan removeOneUnitDamp) : base(
                StateMachineStateType.WaitForTaskComplete, code, vault, stateVault, raiser, executionContext, addOneUnitDamp, removeOneUnitDirt, removeOneUnitDamp)
        {
            if (stateVault == null)
            {
                throw new ArgumentNullException(nameof(stateVault));
            }
            if (nextStatesOnCompletion.IsDefault || nextStatesOnCompletion.IsEmpty ||
                nextStatesOnCompletion.Contains(code))
            {
                throw new ArgumentException(
                          $@"Parameter must not be default, empty or contain the value passed by the {nameof(code)} parameter.",
                          nameof(nextStatesOnCompletion));
            }
            if (executionContext == null)
            {
                throw new ArgumentNullException(nameof(executionContext));
            }
            if (!executionContext.IsActive || executionContext.IsDisposed)
            {
                throw new ArgumentException(@"The execution context is not in a useable state.",
                                            nameof(executionContext));
            }
            if (code.GetStateTaskType() == TaskType.NullTask)
            {
                throw new ArgumentException("This state must be a task-based state.");
            }

            CommandId = commandIds;
            _taskEndedTransProcedure           = new LocklessLazyWriteOnce <LTransProcedure>(InitTaskEndedTransProcedure);
            _taskEndedAdditionalTransProcedure =
                new LocklessLazyWriteOnce <LTransAdditionalProcedure>(InitTaskEndedAdditionalTransProc);
            _taskEndedTransition =
                new LocklessLazyWriteOnce <LaundryMachineStateTransition>(() =>
                                                                          InitTaskEndedTransition(nextStatesOnCompletion));
            _cancellationTransition =
                new LocklessLazyWriteOnce <LaundryMachineStateTransition>(() =>
                                                                          InitCancellationTransition(code, commandIds));
        }
Beispiel #7
0
 protected StateMachineStateBase(TStateCode code, [NotNull] TFlagVault flagVault,
                                 [NotNull] IEventRaiser raiser)
 {
     if (!code.IsValueDefined())
     {
         throw new ArgumentException($"The enum value [{code}] is not defined.", nameof(code));
     }
     if (raiser == null)
     {
         throw new ArgumentNullException(nameof(raiser));
     }
     if (!raiser.ThreadActive || raiser.IsDisposed)
     {
         throw new ArgumentException("The event raiser is disposed or faulted.", nameof(raiser));
     }
     _raiser          = raiser;
     _transitionTable = new LocklessLazyWriteOnce <ImmutableSortedSet <TStateTransition> >(InitTransitionTable);
     FlagVault        = flagVault ?? throw new ArgumentNullException(nameof(flagVault));
     _concreteType    = new LocklessConcreteType(this);
     StateCode        = code;
 }