Ejemplo n.º 1
0
        private void EventAdded(ulong guildId, ScheduledEvent se)
        {
            lock (_sync)
            {
                try
                {
                    DateTime earliest = se.ActualPingDates.First();

                    // If ping is not present - create
                    // Else if ping is present:
                    //   If ping is later than event earliest date - recreate ping with added event
                    //   If ping date is the same with event earliest date - add/update event in ping
                    if (_nextPing == null || earliest < _nextPing.Date)
                    {
                        _nextPing = new ScheduledPing(earliest);
                        _nextPing.SetEvent(guildId, se);
                        RecycleTimer();
                    }
                    else if (_nextPing != null && earliest == _nextPing.Date)
                    {
                        _nextPing.SetEvent(guildId, se);
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, ex.Message);
                }
            }
        }
Ejemplo n.º 2
0
 private void FullUpdate()
 {
     try
     {
         // Build full timeline out of active events
         var timeline       = new Dictionary <DateTime, Dictionary <ulong, Dictionary <int, ScheduledEvent> > >();
         var activeEventMap = _eventStorage.FindAllEvents(null, EventState.Pending);
         foreach (var kv in activeEventMap)
         {
             ulong            guildId = kv.Key;
             ScheduledEvent[] events  = kv.Value;
             foreach (ScheduledEvent se in events)
             {
                 if (!VerifyEvent(guildId, se))
                 {
                     continue;
                 }
                 foreach (DateTime date in se.ActualPingDates)
                 {
                     Dictionary <ulong, Dictionary <int, ScheduledEvent> > guildEventMap;
                     if (!timeline.TryGetValue(date, out guildEventMap))
                     {
                         guildEventMap  = new Dictionary <ulong, Dictionary <int, ScheduledEvent> >();
                         timeline[date] = guildEventMap;
                     }
                     Dictionary <int, ScheduledEvent> eventMap;
                     if (!guildEventMap.TryGetValue(guildId, out eventMap))
                     {
                         eventMap = new Dictionary <int, ScheduledEvent>();
                         guildEventMap[guildId] = eventMap;
                     }
                     eventMap[se.Id] = se;
                 }
             }
         }
         //
         if (timeline.Any())
         {
             var      earliest = timeline.OrderBy(kv => kv.Key).First();
             DateTime date     = earliest.Key;
             Dictionary <ulong, Dictionary <int, ScheduledEvent> > events = earliest.Value;
             _nextPing = new ScheduledPing(date, events);
         }
         else
         {
             _nextPing = null;
         }
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, ex.Message);
         _nextPing = null;
     }
     RecycleTimer();
 }
Ejemplo n.º 3
0
        private void EventChanged(ulong guildId, ScheduledEvent se)
        {
            lock (_sync)
            {
                try
                {
                    DateTime earliest = se.ActualPingDates.First();

                    // If ping is not present - create
                    // Else if ping is present:
                    //   If ping is later than event earliest date - recreate ping with updated event
                    //   If ping date is the same with event earliest date - add/update event in ping
                    //   If ping contains event and event earliest date is later - remove it from ping
                    if (_nextPing == null || earliest < _nextPing.Date)
                    {
                        _nextPing = new ScheduledPing(earliest);
                        _nextPing.SetEvent(guildId, se);
                        RecycleTimer();
                    }
                    else if (_nextPing != null)
                    {
                        if (earliest == _nextPing.Date)
                        {
                            _nextPing.SetEvent(guildId, se);
                        }
                        else if (_nextPing.HasEvent(guildId, se) && earliest > _nextPing.Date)
                        {
                            _nextPing.RemoveEvent(guildId, se);
                            if (_nextPing.IsEmpty)
                            {
                                FullUpdate();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, ex.Message);
                }
            }
        }