private void HandleMessage(HandleType type, MessageID msgID, params object[] msgParams) { NetMessageBase msgBase = Factory_CreateMessage.Instance.CreateNetMessage(msgID); if (msgBase == null) { Console.WriteLine("MessageID Error: " + msgID + "\t"); return; } msgBase.SetMessageParams(msgParams); HandleMessage(type, msgBase); if (msgBase.isFree) { return; } NetMessageInfo info = new NetMessageInfo(); info.handleType = type; info.msgBase = msgBase; AddMessage(msgID, info); }
public void OnRelease() { if (dic_HandleNetMessages == null || dic_HandleNetMessages.Count <= 0) { return; } foreach (KeyValuePair <MessageID, List <NetMessageInfo> > keyValue in dic_HandleNetMessages) { List <NetMessageInfo> netMessageList = keyValue.Value; if (netMessageList == null || netMessageList.Count <= 0) { continue; } for (int i = 0; i < netMessageList.Count; i++) { NetMessageBase netBase = netMessageList[i].msgBase; if (netBase == null) { continue; } netBase.OnDestroy(); } netMessageList.Clear(); } dic_HandleNetMessages.Clear(); }
private void HandleMessage(HandleType type, NetMessageBase msgBase) { switch (type) { case HandleType.Send: ((SendNetMessageBase)msgBase).SendMessage(); break; case HandleType.Handle: ((HandleNetMessageBase)msgBase).HandleMessage(); break; default: break; } }
public void Send(NetMessageBase netMessage) { writeNetBuff.Reset(); netMessage.Write(writeNetBuff); if (isUDP) { tcpSocket.SendTo(writeNetBuff.DataBuffer, serverEndPoint); } else { SocketAsyncEventArgs args = new SocketAsyncEventArgs(); var buffer = writeNetBuff.DataBuffer; args.SetBuffer(buffer, 0, buffer.Length); tcpSocket.SendAsync(args); } }
/// <summary> /// This gets called when a message is received from the Crew Server /// Based on the type of message, it can be just simply logged, or handled specifically based on the application needs. /// </summary> /// <param name="msg"></param> public void OnMessageFromIdms(NetMessageBase idmsMsg) { Console.Out.WriteLine("Received message " + idmsMsg.GetType()); if (idmsMsg.GetType() == typeof(AckNackV1)) { AckNackV1 ack = (AckNackV1)idmsMsg; if (ack.IsAck) { Console.Out.WriteLine("Ack for message " + ack.MessageSequence); // log the Ack message } else { Console.Out.WriteLine("NoAck for message " + ack.MessageSequence); } } else if (idmsMsg.GetType() == typeof(IncidentUpdateWfmV1)) { IncidentUpdateWfmV1 iu = (IncidentUpdateWfmV1)idmsMsg; Console.Out.WriteLine("Incident Id=" + iu.IncidentId + ", update type = " + ((eUpdateType)iu.UpdateType).ToString()); // save the incident details for later reference if (!incidentMsgList.ContainsKey(iu.IncidentId)) { incidentMsgList.Add(iu.IncidentId, iu); } else { incidentMsgList[iu.IncidentId] = iu; } SendAckMessage(iu); // Send Ack message SendIncidentStatusMessage(iu); // Send incident status message } else if (idmsMsg.GetType() == typeof(CrewUpdateWfmV1)) { CrewUpdateWfmV1 ca = (CrewUpdateWfmV1)idmsMsg; Console.Out.WriteLine("Incident Id=" + ca.IncidentId + ", crew Id = " + ca.CrewId + ", update type = " + ((eUpdateType)ca.UpdateType).ToString()); SendAckMessage(ca); // Send Ack message SendCrewEnrouteMessage(ca); // Send Crew Enrount status message SendCrewOnsiteMessage(ca); // Send Crew Onsite status message SendVehicleLocationMessage(ca); // send Vehicle location update message } }
public void ProcessMessage(NetMessageBase msg) { switch (msg.MessageType) { case EmNetMessageType.SC_SELF_INFO: OnReceivePlayerInfo(msg as NetSCSelfInfoMsg); break; case EmNetMessageType.SC_SYNCHRONIZATE: OnReceiveSyncData(msg as NetSCSynchronizateMsg); break; case EmNetMessageType.SC_PLAYER_LIST: OnReceivePlayerList(msg as NetSCPlayerListMsg); break; case EmNetMessageType.SC_SYNCHRONIZATE_START: OnReceiveSyncStart(msg as NetSCSynchronizateStartMsg); break; } }
private static void SendMsg(NetBuff buffer, NetMessageBase msg) { buffer.Reset(); msg.Write(buffer); for (int i = 0; i < playerList.Count; i++) { var info = playerList[i]; if (!info.IsDisconnected) { try { info.Socket.Send(buffer.DataBuffer); } catch (Exception e) { info.IsDisconnected = true; throw; } } } }
public void OnUpdate() { if (dic_HandleNetMessages == null || dic_HandleNetMessages.Count <= 0) { return; } foreach (KeyValuePair <MessageID, List <NetMessageInfo> > keyValue in dic_HandleNetMessages) { List <NetMessageInfo> netMessageList = keyValue.Value; if (netMessageList == null || netMessageList.Count <= 0) { continue; } for (int i = 0; i < netMessageList.Count; i++) { NetMessageBase netBase = netMessageList[i].msgBase; HandleType type = netMessageList[i].handleType; if (netBase == null) { netMessageList.Remove(netMessageList[i]); i--; continue; } HandleMessage(type, netBase); if (!netBase.isFree) { continue; } netMessageList.Remove(netMessageList[i]); i--; } } }
/// <summary> /// For sample this just logs the message to Console /// </summary> /// <param name="msg"></param> /// <param name="text"></param> public void LogMessageToConsole(NetMessageBase msg, string text) { MessageBaseV1 msgBase = (MessageBaseV1)msg; Console.Out.WriteLine(text + " with sequence = " + msgBase.Sequence); }
/// <summary> /// This gets called when a message is received from the Call Server /// Based on the type of message, it can be just simply logged, or handled specifically based on the application needs. /// </summary> /// <param name="msg"></param> public void OnMessageFromIdms(NetMessageBase msg) { Console.Out.WriteLine("Received message " + msg.GetType()); MessageCount++; if (msg is HelloResponseV1) { chkHelloDateTime = DateTime.Now; HelloResponseV1 r = msg as HelloResponseV1; if (r.MySystemId != MessageBaseV1.CALL_SERVER) { Console.WriteLine("We are connecting to {0}, not the right server. Disconnecting.", r.MySystemId); callConnector.CloseConnection(); } else if (MessageCount == 10) { callConnector.CloseConnection(); } } else if (msg is AckNackV1) { AckNackV1 ack = (AckNackV1)msg; if (ack.IsAck) { Console.Out.WriteLine("Ack for message " + ack.MessageSequence); } } else if (msg is MeterEventQueryAmiV1) { createTestLogFile("MeterEventQueryAmiV1 request from call server"); MeterEventQueryAmiV1 timestmp = (MeterEventQueryAmiV1)msg; DateTime time = DateTime.Now; totime = time.ToString("yyyyMMddHHmmss"); fromtime = Convert.ToDateTime(timestmp.FromTimeStamp).ToString("yyyyMMddHHmmss"); GetMeterEventResponse(); } else if (msg is MeterPingRequestAmiV1) { createTestLogFile("MeterPingRequestAmiV1 request from call server"); // process MeterEventQueryAmiV1 here MeterPingRequestAmiV1 png = (MeterPingRequestAmiV1)msg; List <MeterIdType> MeterIds = png.MeterIds; createTestLogFile("MeterPingRequestAmiV1 - Total meter requests " + MeterIds.Count); if (MeterIds.Count > 0) { MeterPingQuery(MeterIds); } } else if (msg is MeterVoltPingReqAmiV1) { createTestLogFile("MeterVoltPingReqAmiV1 request from call server"); // process MeterVoltPingAmiV1 here MeterVoltPingReqAmiV1 vlt = (MeterVoltPingReqAmiV1)msg; List <MeterIdType> MeterIds = vlt.MeterIds; createTestLogFile("MeterVoltPingReqAmiV1 - Total meter requests " + MeterIds.Count); if (MeterIds.Count > 0) { MeterVoltEventQuery(MeterIds); } } //section 2 IVR Events else if (msg is CallQueryCivV1) { SendCallQueryResponse(); } //else if (msg is CustomerCorrectionCivV1) //{ // // process MeterEventQueryAmiV1 here //} //else if (msg is CaseNoteQueryCivV1) //{ // // process MeterEventQueryAmiV1 here //} else { } }
/// <summary> /// For sample this just logs the message to Console /// </summary> /// <param name="msg"></param> /// <param name="text"></param> public void LogMessageToConsole(NetMessageBase msg, string text) { Console.Out.WriteLine(text); }