Exemplo n.º 1
0
        IEventSlot IEventScheduler.FireOnce(TimeSpan delay, Action action)
        {
            Validate.NotNull(action);

            var now = DateTime.UtcNow;

            var info = new EventInfo
                {
                    NextShot = now + delay,
                    Count = 1,
                    Action = action
                };

            var slot = register_event(info);

            return slot;
        }
Exemplo n.º 2
0
        IEventSlot IEventScheduler.Idle(Action action)
        {
            Validate.NotNull(action);

            var info = new EventInfo
                {
                    RepeatAfter = 1.Milliseconds(),
                    Count = int.MaxValue,
                    Action = action
                };

            var slot = register_event(info);

            return slot;
        }
Exemplo n.º 3
0
 private void schedule_next_shot(EventInfo info)
 {
     DateTime now = DateTime.UtcNow;
     info.NextShot = now + info.RepeatAfter;
 }
Exemplo n.º 4
0
        private IEventSlot register_event(EventInfo info)
        {
            var slot = EventSlot.New(this);
            _repo.Add(info);

            _hasNewTriger.Set();

            return slot;
        }
Exemplo n.º 5
0
        private bool remove_if_done(EventInfo info)
        {
            if (info.Count > 0)
                return false;

            _repo.Remove(info);
            return true;
        }
Exemplo n.º 6
0
        IEventSlot IEventScheduler.Schedule(EventInfo info, Action action)
        {
            Validate.NotNull(action);

            info.Action = action;

            var slot = register_event(info);

            return slot;
        }
Exemplo n.º 7
0
        private void invoke_event(EventInfo info)
        {
            try
            {
                info.Action();
                info.Invoked++;
            }
            catch (Exception ex)
            {
                info.Failed++;
                info.LastFailure = ex;
                _log.Error(ex);
            }

            info.Count--;
        }
Exemplo n.º 8
0
        IEventSlot IEventScheduler.Repeat(TimeSpan period, Action action)
        {
            Validate.NotNull(action);
            Validate.That(period > TimeSpan.Zero, "Repeat with zero interval is not allowed");

            var now = DateTime.UtcNow;

            var info = new EventInfo
                {
                    NextShot = now + period,
                    RepeatAfter = period,
                    Count = int.MaxValue,
                    Action = action
                };

            var slot = register_event(info);

            return slot;
        }
Exemplo n.º 9
0
 void ISchedulerRepo.Remove(EventInfo info)
 {
     _events.Remove(info);
 }
Exemplo n.º 10
0
 void ISchedulerRepo.Add(EventInfo info)
 {
     _events.AddLast(info);
 }
Exemplo n.º 11
0
 void ISchedulerRepo.Remove(EventInfo info)
 {
     lock(_mutex) _impl.Remove(info);
 }
Exemplo n.º 12
0
 void ISchedulerRepo.Add(EventInfo info)
 {
     lock(_mutex) _impl.Add(info);
 }