/// <summary> /// Tells the controller to "dispatch" all Events, /// causing added listenes to be fired approriately /// </summary> public void Flush() { // Signal events to be sent -------------- outgoingEvents.Put("send-signal"); // Trigger new events -------------------- var events = incomingEvents.GetAll(typeof(string), typeof(int), typeof(string)); foreach (var eventTuple in events) { // Decode the event var typeIdentifier = (string)eventTuple.Fields[0]; var sender = (uint)(int)eventTuple.Fields[1]; var jsonData = (string)eventTuple.Fields[2]; var e = CreateEvent(typeIdentifier, jsonData); e.Sender = sender; e.Receiver = Connection.LocalPlayer.Id; // Fire the event Type type = e.GetType(); if (listenerMap.ContainsKey(type)) { foreach (var listener in listenerMap[type]) { if (listener(e)) { break; } } } } }
public void CreateSequentialSpaceWithSequentialSpaceNameGeneratorTest() { using (var spaceRepo = new SpaceRepository()) { string uri = "tcp://127.0.0.1:5005"; string testName = NameHashingTool.GenerateUniqueSequentialSpaceName("ThisNameDoesNotActuallyMatter"); ISpace testSpace = new SequentialSpace(); spaceRepo.AddSpace(testName, testSpace); spaceRepo.AddGate(uri + "?CONN"); var testElement = "This string is a test"; testSpace.Put(testElement); testSpace.Get(testElement); Debug.Assert(!testSpace.GetAll().Any()); // putting and getting the element should leave us with an empty space } }
private void SendEvents() { while (true) { // Wait for send signal outgoingEvents.Get("send-signal"); // Get the batch of events to send var eventTuples = outgoingEvents.GetAll(typeof(string), typeof(int), typeof(string)); foreach (var eventTuple in eventTuples) { Connection.Lobby.Space.Put("event", (string)eventTuple[0], // Event type identifier (int)Connection.LocalPlayer.Id, // Sender (local id) (int)eventTuple[1], // Receiver (string)eventTuple[2] // JSON data ); } } }