public void BasicUnionSerializationTest() { byte[] data = EventsSerializer.SerializeEvent <EngineActionEvent>(new PingEvent()); EngineActionEvent engineEvent = EventsSerializer.DeserializeEvent <EngineActionEvent>(data); Assert.That(engineEvent.GetType(), Is.EqualTo(typeof(PingEvent))); }
protected override EngineActionResponse OnEvent(EngineActionEvent actionEvent) { switch (actionEvent) { case ShutdownEvent: Dispose(); break; case PingEvent: return(new PixelsResponse { Pixels = cefManager.GetPixels() }); case GoForwardEvent: cefManager.GoForward(); break; case GoBackEvent: cefManager.GoBack(); break; case RefreshEvent: cefManager.Refresh(); break; case LoadUrlEvent x: cefManager.LoadUrl(x.Url); break; case LoadHtmlEvent x: cefManager.LoadHtml(x.Html); break; case ExecuteJsEvent x: cefManager.ExecuteJs(x.Js); break; case KeyboardEvent x: cefManager.HandelKeyboardEvent(x); break; case MouseMoveEvent x: cefManager.HandelMouseMoveEvent(x); break; case MouseClickEvent x: cefManager.HandelMouseClickEvent(x); break; case MouseScrollEvent x: cefManager.HandelMouseScrollEvent(x); break; } return(new OkResponse()); }
public void BasicEventDispatcherTest() { const int port = 8732; //Setup test's ZMQ Utils.CreateZmq(ZSocketType.REP, port, true, out ZContext context, out ZSocket socket); //Create the event dispatcher EventDispatcher <EngineActionEvent, EngineActionResponse> eventDispatcher = null; _ = Task.Run(() => { eventDispatcher = new EventDispatcher <EngineActionEvent, EngineActionResponse>(new TimeSpan(0, 0, 0, 4), port); eventDispatcher.DispatchEventsThread().RunSynchronously(); }); SpinWait.SpinUntil(() => eventDispatcher != null); //Send the event bool gotResponse = false; eventDispatcher.QueueEvent(new PingEvent(), responseEventDispatcher => { //We got a response gotResponse = true; Assert.IsNotNull(responseEventDispatcher); Assert.That(responseEventDispatcher.GetType(), Is.EqualTo(typeof(OkResponse))); }); //Get a event from the dispatcher byte[] requestData = socket.Receive(); EngineActionEvent actionEvent = EventsSerializer.DeserializeEvent <EngineActionEvent>(requestData); Assert.IsNotNull(actionEvent); Assert.That(actionEvent.GetType(), Is.EqualTo(typeof(PingEvent))); //Respond EngineActionResponse response = new OkResponse(); byte[] responseData = EventsSerializer.SerializeEvent <EngineActionResponse>(response); socket.Send(responseData); SpinWait.SpinUntil(() => gotResponse); eventDispatcher.Dispose(); socket.Dispose(); context.Dispose(); }
/// <summary> /// Called when an event is received /// </summary> /// <param name="actionEvent"></param> /// <returns></returns> protected abstract EngineActionResponse OnEvent(EngineActionEvent actionEvent);