private void Clear() { m_Type = AMDMsgType.eUndefined; m_iSeqNum = 0; m_sMsgSrc = ""; m_abData = null; m_Msg = null; }
/// <summary> /// Sets member data from the msg passed in. /// </summary> /// <param name="i_Msg"></param> /// <returns></returns> public void Set(ISMessaging.ISMsg i_Msg) { try { m_Msg = i_Msg; m_iSeqNum = 0; if (i_Msg.m_Source != null) { m_sMsgSrc = i_Msg.m_Source.m_sMachine; } else { m_sMsgSrc = "AudioMgr"; } switch (i_Msg.GetType().ToString()) { case "ISMessaging.Audio.ISMSpeechStart": m_Type = AMDMsgType.eSpeechStart; break; case "ISMessaging.Audio.ISMSpeechStop": m_Type = AMDMsgType.eSpeechStop; break; case "ISMessaging.Audio.ISMRawData": m_Type = AMDMsgType.eAudioData; m_abData = ((ISMessaging.Audio.ISMRawData)i_Msg).m_abData; break; case "ISMessaging.Session.ISMTransferSession": m_Type = AMDMsgType.eTransferSession; break; case "ISMessaging.Session.ISMTerminateSession": m_Type = AMDMsgType.eTerminateSession; break; case "ISMessaging.Session.ISMTerminateSessionAfterPrompts": m_Type = AMDMsgType.eTerminateSessionAfterPrompts; break; default: m_Type = AMDMsgType.eUndefined; Log(Level.Exception, $"ERROR AudioMgr.AMSockData.Set(): Got unknown msg type '{i_Msg.GetType().ToString()}'."); break; } } catch (Exception e) { Log(Level.Exception, $"ERROR AudioMgr.AMSockData.Set(): Caught exception '{e.ToString()}'."); } return; }
/// <summary> /// Extracts member data from the buffer passed in. /// </summary> /// <param name="i_Data"></param> /// <returns></returns> public void Extract(byte[] i_abData) { try { m_Type = (AMDMsgType)BitConverter.ToInt32(i_abData, m_iIndexes[0]); m_iSeqNum = BitConverter.ToUInt32(i_abData, m_iIndexes[1]); m_sMsgSrc = Encoding.UTF8.GetString(i_abData, m_iIndexes[2], SIZESRC); switch (m_Type) { case AMDMsgType.eAudioData: m_Msg = new ISMessaging.Audio.ISMRawData(); int iDataLen = BitConverter.ToInt32(i_abData, m_iIndexes[3]); m_abData = new byte[iDataLen]; Array.Copy(i_abData, m_iIndexes[4], m_abData, 0, iDataLen); break; case AMDMsgType.eSessionBegin: string sFrom = ""; string sTo = ""; try { sFrom = Encoding.UTF8.GetString(i_abData, m_iIndexes[3], 64).Trim('\0'); sTo = Encoding.UTF8.GetString(i_abData, m_iIndexes[3] + 64, 64).Trim('\0'); } catch (Exception exc) { sFrom = sTo = ""; Log(Level.Exception, $"AMSockData.Extract(): Caught exception extracting From/To: '{exc.ToString()}'"); } m_Msg = new ISMessaging.Session.ISMSessionBegin(sFrom, sTo); // FIX - Should convert C time recorded by UA to C# DateTime. This will be more important with // distributed/redundand configurations. ((ISMessaging.Session.ISMSessionBegin)m_Msg).m_tBegan = DateTime.Now; // FIX - see above. break; case AMDMsgType.eSessionEnd: m_Msg = new ISMessaging.Session.ISMSessionEnd(); // FIX - Should convert C time recorded by UA to C# DateTime. This will be more important with // distributed/redundand configurations. ((ISMessaging.Session.ISMSessionEnd)m_Msg).m_tEnded = DateTime.Now; // FIX - see above. break; case AMDMsgType.eDTMF: m_Msg = new ISMessaging.Audio.ISMDtmf(); ((ISMessaging.Audio.ISMDtmf)m_Msg).m_sDtmf = Encoding.UTF8.GetString(i_abData, m_iIndexes[3], 1); break; default: m_Msg = null; Log(Level.Exception, $"AMSockData.Extract() got unknown type '{m_Type.ToString()}'."); break; } } catch (Exception e) { Log(Level.Exception, $"AMSockData.Extract(): Caught exception: '{e.ToString()}'"); } return; }