protected CycleConfiguration(PhaseTimings construction, IPhaseTimings campaigning, IPhaseTimings voting, IPhaseTimings synchronisation) { CycleDuration = construction.TotalTime + campaigning.TotalTime + voting.TotalTime + synchronisation.TotalTime; TimingsByName = new Dictionary <IPhaseName, IPhaseTimings> { { PhaseName.Construction, construction }, { PhaseName.Campaigning, campaigning }, { PhaseName.Voting, voting }, { PhaseName.Synchronisation, synchronisation } }; }
/// <summary> /// Use this to get a stream of state change events occuring at the time configured by <see cref="timings"/> every <see cref="cycleDuration"/> /// </summary> /// <param name="name">The name of the phase for which you need the state change events.</param> /// <param name="timings">The timing configuration for the phase.</param> /// <param name="cycleDuration">The total duration of a delta production cycle.</param> /// <param name="scheduler">The IScheduler used to synchronise the Timers.</param> /// <returns></returns> public static IObservable <StatefulPhase> GetStatusChangeObservable(IPhaseName name, IPhaseTimings timings, TimeSpan cycleDuration, IScheduler scheduler) { var phaseInProducingStatus = Observable .Timer(timings.Offset, cycleDuration, scheduler) .Select(_ => new StatefulPhase(name, PhaseStatus.Producing)); var phaseInCollectingStatus = Observable .Timer(timings.Offset + timings.ProductionTime, cycleDuration, scheduler) .Select(_ => new StatefulPhase(name, PhaseStatus.Collecting)); var phaseInIdleStatus = Observable .Timer(timings.Offset + timings.TotalTime, cycleDuration, scheduler) .Select(_ => new StatefulPhase(name, PhaseStatus.Idle)); return(phaseInProducingStatus.Merge(phaseInCollectingStatus, scheduler).Merge(phaseInIdleStatus, scheduler)); }