Пример #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;
        }
Пример #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;
        }
Пример #3
0
 private void schedule_next_shot(EventInfo info)
 {
     DateTime now = DateTime.UtcNow;
     info.NextShot = now + info.RepeatAfter;
 }
Пример #4
0
        private IEventSlot register_event(EventInfo info)
        {
            var slot = EventSlot.New(this);
            _repo.Add(info);

            _hasNewTriger.Set();

            return slot;
        }
Пример #5
0
        private bool remove_if_done(EventInfo info)
        {
            if (info.Count > 0)
                return false;

            _repo.Remove(info);
            return true;
        }
Пример #6
0
        IEventSlot IEventScheduler.Schedule(EventInfo info, Action action)
        {
            Validate.NotNull(action);

            info.Action = action;

            var slot = register_event(info);

            return slot;
        }
Пример #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--;
        }
Пример #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;
        }
Пример #9
0
 void ISchedulerRepo.Remove(EventInfo info)
 {
     _events.Remove(info);
 }
Пример #10
0
 void ISchedulerRepo.Add(EventInfo info)
 {
     _events.AddLast(info);
 }
Пример #11
0
 void ISchedulerRepo.Remove(EventInfo info)
 {
     lock(_mutex) _impl.Remove(info);
 }
Пример #12
0
 void ISchedulerRepo.Add(EventInfo info)
 {
     lock(_mutex) _impl.Add(info);
 }