private void OnMsgArrivedEvent(object msg) { AlertBase alert = (AlertBase)msg; this.alert = alert; alert.ProcessMessage(); try { if (LevelStatusEvent != null) { LevelStatusEvent(alert.BatteryLevel, alert.SignalLevel); } } catch (Exception ex) { Console.WriteLine("LevelStatusEvent:" + Environment.NewLine + ex.ToString()); } try { if (MsgArrivedEvent != null) { MsgArrivedEvent(alert); } } catch (Exception ex) { Console.WriteLine("MsgArrivedEvent:" + Environment.NewLine + ex.ToString()); } }
void OnMsgArrivedEvent(object msg, EventArgs e) { try { AlertBase alert = (AlertBase)msg; //DisplayItemType type = alert.ItemType; string data = msg.ToString(); } catch (Exception ex) { Console.WriteLine("BlackBerry_MsgArrivedEvent:" + Environment.NewLine + ex.ToString()); } }
void OnMsgArrivedEvent(object msg, EventArgs e) { try { AlertBase alert = (AlertBase)msg; DisplayItemType type = alert.ItemType; switch (type) { case DisplayItemType.STATUS: { //processStatusAlert(new StatusAlert(data)); break; } case DisplayItemType.CONTACTS: { string data = msg.ToString(); ContactAlert contactAlert = new ContactAlert(data); this.downloadBtn.Text = "Download: " + contactAlert.Index + " left"; this.downloadBtn.Invalidate(); if (int.Parse(contactAlert.Index) % 10 == 0) { Display(); } if (int.Parse(contactAlert.Index) == 1) { this.downloadBtn.Text = "Download"; this.downloading = false; this.downloadBtn.Invalidate(); Display(); } break; } } } catch (Exception ex) { Console.WriteLine("BlackBerry_MsgArrivedEvent:" + Environment.NewLine + ex.ToString()); } }
private void OnBluetoothDisconnectEvent() { DisconnectAlert alert = new DisconnectAlert(); this.alert = alert; alert.ProcessMessage(); try { if (MsgArrivedEvent != null) { MsgArrivedEvent(alert); } } catch (Exception ex) { Console.WriteLine("MsgArrivedEvent:" + Environment.NewLine + ex.ToString()); } if (BluetoothDisconnectEvent != null) { BluetoothDisconnectEvent(); } }
void OnMsgArrivedEvent(object msg, EventArgs e) { try { AlertBase alert = (AlertBase)msg; DisplayItemType type = alert.ItemType; string data = msg.ToString(); switch (type) { case DisplayItemType.UNKNOWN: { break; } case DisplayItemType.STATUS: { //processStatusAlert(new StatusAlert(data)); break; } case DisplayItemType.CONNECT: { //processConnectAlert(new ConnectAlert(data)); break; } case DisplayItemType.EMAIL: { //processEmailAlert(new EmailAlert(data)); break; } case DisplayItemType.CALL: { processCallAlert(new CallAlert(data)); break; } case DisplayItemType.LOCK: { //processLockAlert(new LockAlert(data)); break; } case DisplayItemType.SMS: { //processSMSAlert(new SMSAlert(data)); break; } case DisplayItemType.SCREEN: { //processScreenCaptureAlert(new ScreenCaptureAlert(data)); break; } case DisplayItemType.CONTACTS: { //processContactAlert(new ContactAlert(data)); break; } case DisplayItemType.CLIPBOARD: { //processClipboardAlert(new ClipboardAlert(data)); break; } case DisplayItemType.DISCONNECT: { //processDisconnectAlert(new DisconnectAlert(data)); break; } case DisplayItemType.LEVEL: { //processLevelAlertAlert(new LevelAlert(data)); break; } case DisplayItemType.MACRO: { //processMacroAlertAlert(new MacroAlert(data)); break; } case DisplayItemType.PIN_MSG: { //processPINMsgAlert(new PINMsgAlert(data)); break; } } } catch (Exception ex) { Console.WriteLine("BlackBerry_MsgArrivedEvent:" + Environment.NewLine + ex.ToString()); } }
/* * Message Structure: * First two bytes = 0xFF (Message marker) * Next four bytes is the JSON payload size * Next four bytes is the binary payload size * Followed by JSON payload then binary payload * * Minimum message size 10 bytes * * */ public void OnDataReceived(int numberOfBytesRead) { m_dataCount++; Console.WriteLine(String.Format("OnDataReceived: {0} bytes recieved", numberOfBytesRead)); Boolean debugLogging = false; if (Directory.Exists(ApplicationSettings.Instance.LocalDataPath + @"\debug\raw")) { debugLogging = true; } try { lock (m_threadLock) { try { if (debugLogging) { FileStream stream = new FileStream(ApplicationSettings.Instance.LocalDataPath + @"\debug\raw\data.bin", FileMode.OpenOrCreate); BinaryWriter w = new BinaryWriter(stream); w.Seek((int)stream.Length, SeekOrigin.Begin); w.Write(m_dataBuffer, 0, numberOfBytesRead); w.Close(); FileStream stream2 = new FileStream(ApplicationSettings.Instance.LocalDataPath + @"\debug\raw\packet" + m_dataCount + ".bin", FileMode.OpenOrCreate); BinaryWriter w2 = new BinaryWriter(stream2); w2.Seek((int)stream2.Length, SeekOrigin.Begin); w2.Write(m_dataBuffer, 0, numberOfBytesRead); w2.Close(); } } catch (Exception e) { Console.WriteLine(e.ToString()); } int bufferIndex = 0; // loop until m_dataBuffer is empty do { if (m_msgCount == 200) { Console.WriteLine("break"); } if (m_state == State.eHeader) { // Read Message Header if (m_msgIndex < MessageHeaderSize) { if (m_msgIndex == 0) { m_headerBuffer = new byte[MessageHeaderSize]; } int copyLen = Math.Min(numberOfBytesRead - bufferIndex, MessageHeaderSize - m_msgIndex); Buffer.BlockCopy(m_dataBuffer, bufferIndex, m_headerBuffer, m_msgIndex, copyLen); try { if (debugLogging) { FileStream stream2 = new FileStream(ApplicationSettings.Instance.LocalDataPath + @"\debug\raw\msg" + m_msgCount + ".bin", FileMode.OpenOrCreate); BinaryWriter w2 = new BinaryWriter(stream2); w2.Seek((int)stream2.Length, SeekOrigin.Begin); w2.Write(m_headerBuffer, 0, copyLen); w2.Close(); } } catch (Exception e) { Console.WriteLine(e.ToString()); } m_msgIndex += copyLen; bufferIndex += copyLen; } // Have complete header, now decode the header and allocate arrays for JSON/Binary payloads if (m_msgIndex == MessageHeaderSize) { if (DecodeHeader(m_headerBuffer)) { m_textMsgBuffer = new byte[m_textMessageSize]; m_binaryMsgBuffer = new byte[m_binaryMessageSize]; m_textBytesReceived = 0; m_binaryBytesReceived = 0; m_state = State.eTextMsg; Console.WriteLine(String.Format("m_textMessageSize: {0} bytes", m_textMessageSize)); Console.WriteLine(String.Format("m_binaryMessageSize: {0} bytes", m_binaryMessageSize)); } else { // bad header, flush buffer to next header marker m_state = State.eFlushBuffer; } } } if (m_state == State.eFlushBuffer) { // flush buffer till we found the first header marker while (bufferIndex < numberOfBytesRead && m_state != State.eMarker1) { if (m_dataBuffer[bufferIndex] == 0xFF) { m_state = State.eMarker1; } bufferIndex++; } } if (m_state == State.eMarker1) { if (bufferIndex < numberOfBytesRead) { if (m_dataBuffer[bufferIndex] == 0xFF) { bufferIndex++; m_msgIndex = 2; m_headerBuffer = new byte[MessageHeaderSize]; m_headerBuffer[0] = 0xFF; m_headerBuffer[1] = 0xFF; m_textMsgBuffer = null; m_binaryMsgBuffer = null; m_textBytesReceived = 0; m_binaryBytesReceived = 0; m_textMessageSize = 0; m_binaryMessageSize = 0; m_state = State.eHeader; } else { m_state = State.eFlushBuffer; } } // now look for second header marker } if (m_state == State.eTextMsg) { if (m_textMessageSize > 0) { int copyLen = Math.Min(numberOfBytesRead - bufferIndex, m_textMessageSize - m_textBytesReceived); Buffer.BlockCopy(m_dataBuffer, bufferIndex, m_textMsgBuffer, m_textBytesReceived, copyLen); try { if (debugLogging) { FileStream stream2 = new FileStream(ApplicationSettings.Instance.LocalDataPath + @"\debug\raw\msg" + m_msgCount + ".bin", FileMode.OpenOrCreate); BinaryWriter w2 = new BinaryWriter(stream2); w2.Seek(MessageHeaderSize, SeekOrigin.Begin); w2.Write(m_textMsgBuffer, 0, copyLen + m_textBytesReceived); w2.Close(); } } catch (Exception e) { Console.WriteLine(e.ToString()); } m_textBytesReceived += copyLen; bufferIndex += copyLen; Console.WriteLine(String.Format("TextMsg BlockCopy: {0}, {1}, {2}", bufferIndex, m_textBytesReceived, copyLen)); } if (m_textBytesReceived == m_textMessageSize) { m_state = State.eBinaryMsg; } } if (m_state == State.eBinaryMsg) { if (m_binaryMessageSize > 0) { int copyLen = Math.Min(numberOfBytesRead - bufferIndex, m_binaryMessageSize - m_binaryBytesReceived); Buffer.BlockCopy(m_dataBuffer, bufferIndex, m_binaryMsgBuffer, m_binaryBytesReceived, copyLen); try { if (debugLogging) { FileStream stream2 = new FileStream(ApplicationSettings.Instance.LocalDataPath + @"\debug\raw\msg" + m_msgCount + ".bin", FileMode.OpenOrCreate); BinaryWriter w2 = new BinaryWriter(stream2); w2.Seek(MessageHeaderSize + m_textBytesReceived, SeekOrigin.Begin); w2.Write(m_binaryMsgBuffer, 0, copyLen + m_binaryBytesReceived); w2.Close(); } } catch (Exception e) { Console.WriteLine(e.ToString()); } m_binaryBytesReceived += copyLen; bufferIndex += copyLen; Console.WriteLine(String.Format("BinaryMsg BlockCopy: {0}, {1}, {2}", bufferIndex, m_binaryBytesReceived, copyLen)); } if (m_binaryBytesReceived == m_binaryMessageSize) { m_state = State.ePostMsg; } } if (m_state == State.ePostMsg) { try { if (MsgArrivedEvent != null) { string data = Encoding.UTF8.GetString(m_textMsgBuffer, 0, m_textMsgBuffer.Length); AlertBase msg = AlertBase.CreateAlert(data); if (m_binaryMessageSize > 0) { string fileName = ApplicationSettings.Instance.LocalDataPath + "\\" + Path.GetFileNameWithoutExtension(Path.GetTempFileName()) + ".dat"; FileStream fs = File.OpenWrite(fileName); fs.Write(m_binaryMsgBuffer, 0, m_binaryMsgBuffer.Length); fs.Close(); msg.ImageFile = fileName; } MsgArrivedEvent(msg); Console.WriteLine("MsgArrivedEvent fired"); } } catch (Exception ex) { Console.WriteLine("OnDataReceived MsgArrivedEvent:" + Environment.NewLine + ex.ToString()); } m_msgIndex = 0; m_headerBuffer = null; m_textMsgBuffer = null; m_binaryMsgBuffer = null; m_textBytesReceived = 0; m_binaryBytesReceived = 0; m_textMessageSize = 0; m_binaryMessageSize = 0; m_state = State.eHeader; m_msgCount++; } } while (bufferIndex < numberOfBytesRead); } } catch (Exception ex) { Console.WriteLine("OnDataReceived Error:" + Environment.NewLine + ex.ToString()); } }
static public AlertBase CreateAlert(string data) { AlertBase retVal = null; try { AlertBase msg = new AlertBase(data); DisplayItemType type = msg.ItemType; switch (type) { case DisplayItemType.UNKNOWN: { break; } case DisplayItemType.STATUS: { retVal = new StatusAlert(data); break; } case DisplayItemType.CONNECT: { retVal = new ConnectAlert(data); break; } case DisplayItemType.EMAIL: { retVal = new EmailAlert(data); break; } case DisplayItemType.CALL: { retVal = new CallAlert(data); break; } case DisplayItemType.LOCK: { retVal = new LockAlert(data); break; } case DisplayItemType.SMS: { retVal = new SMSAlert(data); break; } case DisplayItemType.SCREEN: { retVal = new ScreenCaptureAlert(data); break; } case DisplayItemType.CONTACTS: { retVal = new ContactAlert(data); break; } case DisplayItemType.CLIPBOARD: { retVal = new ClipboardAlert(data); break; } case DisplayItemType.DISCONNECT: { retVal = new DisconnectAlert(data); break; } case DisplayItemType.LEVEL: { retVal = new LevelAlert(data); break; } case DisplayItemType.MACRO: { retVal = new MacroAlert(data); break; } case DisplayItemType.PIN_MSG: { retVal = new PINMsgAlert(data); break; } case DisplayItemType.INPUT_MSG: { retVal = new InputAlert(data); break; } case DisplayItemType.READFILE: { retVal = new ReadFileAlert(data); break; } } } catch (Exception ex) { Console.WriteLine("process Message Error:" + Environment.NewLine + ex.ToString()); retVal = null; } return(retVal); }