Exemplo n.º 1
0
 private void FireEvent(DLEventType evetType, object data)
 {
     if (OnEventFired != null)
     {
         OnEventFired.Invoke(this, new DLEventArgs(evetType, data));
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Processes the queue and fires events.
        /// </summary>
        private void QueueProcessing()
        {
            TimeSpan waitForNewTimeOut = TimeSpan.Zero;

            while (!_cancellationToken.IsCancellationRequested)
            {
                lock (_eventsAvailableLock) {
                    // wait until we're flagged that there are events available.
                    Monitor.Wait(_eventsAvailableLock, waitForNewTimeOut > TimeSpan.Zero ? waitForNewTimeOut : Scheduler._defaultProcessWaitTime);

                    // reset time to wait.
                    waitForNewTimeOut = TimeSpan.Zero;

                    lock (_queueLock) {
                        if (_priorityQueue.First == null)
                        {
                            // no more items on the queue, go to wait.
                            Console.WriteLine($"{nameof(Scheduler)}: Queue empty.");
                            continue;
                        }

                        // store a single 'current' time for processing of all items in the queue
                        // TODO: use 'current' time from Game.Instance
                        var currentTimeInMilliseconds = GetMillisecondsAfterReferenceTime(DateTime.Now);

                        // check the current queue and fire any events that are due.
                        while (_priorityQueue.Count > 0)
                        {
                            // the first item always points to the next-in-time event available.
                            var nextEvent = _priorityQueue.First;

                            // check if this event has been cancelled.
                            if (_cancelledEvents.Contains(nextEvent.EventId))
                            {
                                // dequeue, clean and move next.
                                _priorityQueue.Dequeue();
                                CleanAllAttributedTo(nextEvent.EventId, nextEvent.RequestorId);
                                continue;
                            }

                            // check if the event is due
                            if (nextEvent.Priority <= currentTimeInMilliseconds)
                            {
                                // actually dequeue this item.
                                _priorityQueue.Dequeue();

                                OnEventFired?.Invoke(this, new EventFiredEventArgs(nextEvent));
                                continue;
                            }

                            // else the next item is in the future, so figure out how long to wait, update and break.
                            waitForNewTimeOut = TimeSpan.FromMilliseconds(nextEvent.Priority < currentTimeInMilliseconds ? 0 : nextEvent.Priority - currentTimeInMilliseconds);
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
    public static void RemoveListener <T>(OnEventFired <T> callback) where T : EventBusData
    {
        var map = GetMap(typeof(T));

        map.RemoveAll(m => ((RegisteredListener <T>)m).Callback == callback);
    }
Exemplo n.º 4
0
    public static void RegisterListener <T>(OnEventFired <T> callback) where T : EventBusData
    {
        var map = GetMap(typeof(T));

        map.Add(new RegisteredListener <T>(callback));
    }
Exemplo n.º 5
0
 public RegisteredListener(OnEventFired <T> callback)
 {
     Callback = callback;
 }
 public void Subscribe(string eventName, OnEventFired onEventFired)
 {
     AmeisenBotLogger.Instance.Log($"[{WowActionExecutor.ProcessId.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}]\tSubscribed to \"{eventName}\"");
     WowActionExecutor.LuaDoString($"abFrame:RegisterEvent(\"{eventName}\");");
     EventDictionary.Add(eventName, onEventFired);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Subscribe to an event
 /// </summary>
 /// <param name="eventName">event name</param>
 /// <param name="onEventFired">method to fire when the event appered in WoW</param>
 public void Subscribe(string eventName, OnEventFired onEventFired)
 {
     AmeisenCore.LuaDoString($"abFrame:RegisterEvent(\"{eventName}\");");
     EventDictionary.Add(eventName, onEventFired);
 }