Exemple #1
0
        public Action Schedule(ModelTimeSpan afterSpan, Action action)
        {
            var multiplier  = GetTimeSpanMultiplier(modelTimeStep: TimeStep, spanStep: afterSpan.StepType);
            var occurOnTime = new ModelTime(afterSpan.Steps * multiplier, TimeStep, CurrentTime.Begin);

            return(Schedule(occurOnTime, action));
        }
Exemple #2
0
 //TODO: onCancellationFailed ?
 private void TryCancelAction(ModelTime actionTime, Action onCancellationSuccess)
 {
     if (actionTime > CurrentTime)
     {
         Console.WriteLine($"Abort modelTimeStep {actionTime} on {CurrentTime}");
         onCancellationSuccess();
     }
 }
Exemple #3
0
        internal void SetTime(ModelTime newTime)
        {
            var selection    = new Func <KeyValuePair <ModelTime, List <Action> >, bool>(pair => pair.Key.TickEqual(newTime));
            var actionGroups = _schedule.Where(selection).ToList();

            for (var i = 0; i < actionGroups.Count; i++)
            {
                var actionGroup = actionGroups[i];
                actionGroup.Value.ForEach(a => a());
            }

            _schedule = _schedule.Except(actionGroups).ToDictionary(p => p.Key, p => p.Value);

            CurrentTime = newTime;
        }
Exemple #4
0
        public Action Schedule(ModelTime onTime, Action action)
        {
            if (_schedule.TryGetValue(onTime, out var actions))
            {
                actions.Add(action);
            }
            else
            {
                actions = new List <Action> {
                    action
                };
                _schedule.Add(onTime, actions);
            }


            return(() => TryCancelAction(onTime, () =>
                                         actions.Remove(action)
                                         ));
        }
Exemple #5
0
 public bool TickEqual(ModelTime right)
 {
     return(Ticks == right.Ticks);
 }
Exemple #6
0
 public ModelTimeScheduler(ModelTimeStep step, DateTimeOffset beginning)
 {
     CurrentTime = new ModelTime(0, step, beginning);
     TimeStep    = step;
 }