public MessageEventArgs(byte[] msg, string endOfMessage) { try { string beginning = Encoding.UTF8.GetString(msg.Take(5).ToArray()); if (beginning == "<BOF>" && endOfMessage == "<EOF>") { byte[] data = new byte[msg.Length - 10]; Buffer.BlockCopy(msg, 5, data, 0, msg.Length - 10); message = BSON.Deserialize <Message>(data); if (message is RecordMessage) { RecordMessage rc = message as RecordMessage; //Console.WriteLine("Received: " + rc.htmlRecord.Id); //Thread.Sleep(1000); } } else { message = new DestroyedBuffer(); } } catch (Exception ex) { message = new DestroyedBuffer(); throw ex; } }
public void Send(Message message) { if (message is RecordMessage) { RecordMessage rm = message as RecordMessage; StopTrackingJob(rm.htmlRecord.recordid); } byte[] bson = BSON.Serialize <Message>(message); Send(bson); }
public void OnServerConnection(object sender, EventArgs args) { Message readyMessage = new ReadyMessage(ObjectId.Empty); Send(BSON.Serialize <Message>(readyMessage)); }