示例#1
0
        protected LaundryRobot([NotNull] string name, [NotNull][ItemNotNull] IEnumerable <LaundryMachineVault> laundryMachines, [NotNull][ItemNotNull] IEnumerable <ILaundryRepository> laundryRepositories)
        {
            if (laundryMachines == null)
            {
                throw new ArgumentNullException(nameof(laundryMachines));
            }
            if (laundryRepositories == null)
            {
                throw new ArgumentNullException(nameof(laundryRepositories));
            }

            var tempRep = laundryRepositories.ToArray();
            var tempArr = laundryMachines.ToArray();

            if (tempArr.Any(itm => itm == null))
            {
                throw new ArgumentException(@"One or more laundry machines was null.", nameof(laundryMachines));
            }
            if (tempRep.Any(itm => itm == null))
            {
                throw new ArgumentException(@"One or more laundry repositories was null.", nameof(laundryRepositories));
            }
            Repositories        = tempRep.ToImmutableArray();
            Machines            = tempArr.ToImmutableArray();
            _robotName          = name ?? throw new ArgumentNullException(nameof(name));
            RobotId             = Guid.NewGuid();
            _concreteType       = new LocklessConcreteType(this);
            _eventRaisingThread = EventRaisingThread.CreateEventRaiser($"RobotEvent{name}");
            _robotThread        = new Thread(RobotThread)
            {
                Name = name, IsBackground = true, Priority = ThreadPriority.Lowest
            };
        }
示例#2
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;
 }