/// <summary> /// Queue a message to be dispatched at a later time. This method will modify the QueueTime and DispatchTime /// properties of the MessageBase object you pass it. /// </summary> /// <param name="message">The message to be sent, encapsulating message type and sender reference.</param> /// <param name="delayTime">The amount of time in milliseconds to delay the message.</param> public void EnqueueMessage(Message message, uint delayTime) { if (this.HasSubscribers(message.MessageType)) { message.QueueTime = this.currentTime; message.DispatchTime = message.QueueTime + delayTime; messageQueue.Add(message); } }
/// <summary> /// Send a message of a particular type, specifying the object of origin, and event arguments. /// </summary> /// <param name="message">The message to send, encapsulating message type and sender reference.</param> /// <returns>True if there are subscribers to the message type.</returns> public bool DispatchMessage(Message message) { MessageTypeList.TryGetValue(message.MessageType, out tempMessageHandler); if (tempMessageHandler != null) { tempMessageHandler(message); return true; } return false; }
/// <summary> /// Send a message of a particular type, without having to instantiate a new MessageBase object. /// </summary> /// <param name="messageType">The message type to generate and send.</param> /// <returns>True if there are subscribers to the message type.</returns> public bool DispatchMessage(string messageType) { MessageTypeList.TryGetValue(messageType, out tempMessageHandler); if (tempMessageHandler != null) { Message tempMessage = new Message(null, messageType); tempMessageHandler(tempMessage); return true; } return false; }
/// <summary> /// Removes the specified MessageBase object from the cue if it is there /// </summary> /// <param name="message">MessageBase object to dequeue</param> /// <returns>True if an object was found and dequeued</returns> public bool DeQueueMessage(Message message) { if (messageQueue.Count > 0) { for (int i = 0; i < messageQueue.Count; i++) { if (messageQueue[i] == message) { messageQueue.RemoveAt(i); return true; } } } return false; }