private void HandleRequest(string data) { ARWObject newObj = ARWObject.Extract(data); ARWEvent currentEvent = ARWEvents.allEvents.Where(a => a.eventName == newObj.GetRequestName()).FirstOrDefault(); if (currentEvent != null) { if (currentEvent.p_handler != null) { currentEvent.p_handler(this, newObj); } else { if (currentEvent.handler != null) { currentEvent.handler(newObj); } } } else { wrongData += data; if (ARWObject.CanBeARWObject(wrongData)) { wrongData += data; HandleRequest(wrongData); wrongData = ""; return; } } }
public static bool CanBeARWObject(string data) { ARWObject newObj = ARWObject.Extract(data); ARWEvent currentEvent = ARWEvents.allEvents.Where(a => a.eventName == newObj.GetRequestName()).FirstOrDefault(); if (currentEvent == null) { return(false); } return(true); }
public static void Init() { PrivateEventHandlers _privateEventHandlers = new PrivateEventHandlers(); allEvents = new List <ARWEvent> (); extensionRequests = new List <ExtensionRequest>(); CONNECTION = new ARWEvent(ARWServer_CMD.Connection_Success); CONNECTION.p_handler = _privateEventHandlers.P_Connection; CONNECTION_LOST = new ARWEvent(ARWServer_CMD.Connection_Lost); CONNECTION_LOST.p_handler = _privateEventHandlers.P_Connection_Lost; DISCONNECTION = new ARWEvent(ARWServer_CMD.Disconnection); DISCONNECTION.p_handler = _privateEventHandlers.P_Disconnection; EXTENSION_REQUEST = new ARWEvent(ARWServer_CMD.Extension_Request); EXTENSION_REQUEST.p_handler = _privateEventHandlers.P_Extension_Handler; LOGIN = new ARWEvent(ARWServer_CMD.Login); LOGIN.p_handler = _privateEventHandlers.P_Login; LOGIN_ERROR = new ARWEvent(ARWServer_CMD.Login_Error); LOGOUT = new ARWEvent(); ROOM_JOIN = new ARWEvent(ARWServer_CMD.Join_Room); ROOM_JOIN.p_handler = _privateEventHandlers.P_Join_Room; ROOM_JOIN_ERROR = new ARWEvent(); USER_ENTER_ROOM = new ARWEvent(ARWServer_CMD.User_Enter_Room); USER_ENTER_ROOM.p_handler = _privateEventHandlers.P_User_Enter_Room; USER_EXIT_ROOM = new ARWEvent(ARWServer_CMD.User_Exit_Room); USER_VARIABLE_UPDATE = new ARWEvent(ARWServer_CMD.User_Variable_Update); USER_VARIABLE_UPDATE.p_handler = _privateEventHandlers.P_User_Variable_Update; allEvents.Add(CONNECTION); allEvents.Add(CONNECTION_LOST); allEvents.Add(LOGIN); allEvents.Add(LOGIN_ERROR); allEvents.Add(ROOM_JOIN); allEvents.Add(USER_ENTER_ROOM); allEvents.Add(USER_EXIT_ROOM); allEvents.Add(DISCONNECTION); allEvents.Add(EXTENSION_REQUEST); }
public void AddEventHandler(ARWEvent evnt, EventHandler handler) { evnt.handler += handler; }