public StatfulClient(IClientConfiguration configurationGateway, IMessageBuffer buffer, ITimestamp timestamp, ILuckyCoin luckyCoin) { this.buffer = buffer ?? throw new ArgumentNullException("buffer", "Buffer message cannot be null!"); this.timestamp = timestamp ?? throw new ArgumentNullException("timestamp", "Timestamp calculator cannot be null!"); this.luckyCoin = luckyCoin ?? throw new ArgumentNullException("luckyCoin", "Lucky coin cannot be null!"); this.configurationGateway = configurationGateway ?? throw new ArgumentNullException("configurationGateway", "Configuration gateway cannot be null!"); this.logger = configurationGateway.Logger; }
public void WriteBooleansTest() { // WHEN I write a boolean array to the writer writer.Write(new bool[] { true, true, false, false, true, false, true, false, true }); // AND I convert the writer to a Buffer IMessageBuffer buffer = writer.ToBuffer(); // THEN the buffer is as expected AssertExtensions.AreEqualAndNotShorter(new byte[] { 0, 0, 0, 9, 0b11001010, 0b10000000 }, buffer.Buffer);
internal static DarkRiftReader Create(IMessageBuffer buffer) { DarkRiftReader reader = ObjectCache.GetReader(); reader.isCurrentlyLoungingInAPool = false; reader.buffer = buffer; reader.Encoding = Encoding.Unicode; // TODO DR3 Default to UTF-8 reader.Position = 0; return(reader); }
private bool SendMessage(IMessageBuffer message) { if (_connectionState == ConnectionState.Disconnected) { message.Dispose(); return(false); } _webSocketSession.Send(message.Buffer, 0, message.Count); message.Dispose(); return(true); }
public void WriteDoubleTest() { // WHEN I write a double to the writer writer.Write(0.75d); // AND I convert the writer to a Buffer IMessageBuffer buffer = writer.ToBuffer(); // THEN the buffer is as expected AssertExtensions.AreEqualAndNotShorter(new byte[] { 0x3f, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, buffer.Buffer); Assert.AreEqual(0, buffer.Offset); Assert.AreEqual(8, buffer.Count); // AND the writer has advanced its pointers Assert.AreEqual(8, writer.Position); Assert.AreEqual(8, writer.Length); }
public void WriteBooleanTest() { // WHEN I write a boolean to the writer writer.Write(true); // AND I convert the writer to a Buffer IMessageBuffer buffer = writer.ToBuffer(); // THEN the buffer is as expected AssertExtensions.AreEqualAndNotShorter(new byte[] { 1 }, buffer.Buffer); Assert.AreEqual(0, buffer.Offset); Assert.AreEqual(1, buffer.Count); // AND the writer has advanced its pointers Assert.AreEqual(1, writer.Position); Assert.AreEqual(1, writer.Length); }
public void WriteCharTest() { // WHEN I write a char to the writer writer.Write('A'); // AND I convert the writer to a Buffer IMessageBuffer buffer = writer.ToBuffer(); // THEN the buffer is as expected AssertExtensions.AreEqualAndNotShorter(new byte[] { 0, 0, 0, 2, 65, 0 }, buffer.Buffer); Assert.AreEqual(0, buffer.Offset); Assert.AreEqual(6, buffer.Count); // AND the writer has advanced its pointers Assert.AreEqual(6, writer.Position); Assert.AreEqual(6, writer.Length); }
public void WriteUInt64Test() { // WHEN I write a ulong to the writer writer.Write((ulong)5895742365555578888); // AND I convert the writer to a Buffer IMessageBuffer buffer = writer.ToBuffer(); // THEN the buffer is as expected AssertExtensions.AreEqualAndNotShorter(new byte[] { 0x51, 0xD1, 0xE2, 0x71, 0xCA, 0x29, 0x58, 0x08 }, buffer.Buffer); Assert.AreEqual(0, buffer.Offset); Assert.AreEqual(8, buffer.Count); // AND the writer has advanced its pointers Assert.AreEqual(8, writer.Position); Assert.AreEqual(8, writer.Length); }
public void WriteUInt32Test() { // WHEN I write a uint to the writer writer.Write((uint)589574236); // AND I convert the writer to a Buffer IMessageBuffer buffer = writer.ToBuffer(); // THEN the buffer is as expected AssertExtensions.AreEqualAndNotShorter(new byte[] { 0x23, 0x24, 0x30, 0x5C }, buffer.Buffer); Assert.AreEqual(0, buffer.Offset); Assert.AreEqual(4, buffer.Count); // AND the writer has advanced its pointers Assert.AreEqual(4, writer.Position); Assert.AreEqual(4, writer.Length); }
public void WriteUInt16Test() { // WHEN I write a ushort to the writer writer.Write((ushort)59554); // AND I convert the writer to a Buffer IMessageBuffer buffer = writer.ToBuffer(); // THEN the buffer is as expected AssertExtensions.AreEqualAndNotShorter(new byte[] { 0xE8, 0xA2 }, buffer.Buffer); Assert.AreEqual(0, buffer.Offset); Assert.AreEqual(2, buffer.Count); // AND the writer has advanced its pointers Assert.AreEqual(2, writer.Position); Assert.AreEqual(2, writer.Length); }
public SmartEndpointPublishObserver(IMessageBuffer messageBuffer) { _messageBuffer = messageBuffer; }
static void Copy(string sourceFile, string sourceFormat, string destinationFile, string destinationFormat) { if (String.IsNullOrEmpty(sourceFile)) { throw new ArgumentException(_("sourceFile must not be empty.")); } IMessageBuffer sourceBuffer = null, destinationBuffer = null; try { var sourceBufferType = ParseMessageBufferType(sourceFile, sourceFormat); sourceBuffer = CreateMessageBuffer(sourceFile, sourceBufferType); if (!String.IsNullOrEmpty(destinationFile)) { var destinationBufferType = ParseMessageBufferType(destinationFile, destinationFormat); destinationBuffer = CreateMessageBuffer(destinationFile, destinationBufferType); if (destinationBuffer.Count > 0) { throw new InvalidOperationException( String.Format( _("Destination database {0} must be empty!"), destinationFile ) ); } } if (destinationBuffer == null) { // JSON pipe Console.WriteLine("["); var msgCount = sourceBuffer.Count; var i = 0; foreach (var msg in sourceBuffer) { var dto = new MessageDtoModelV1(msg); var json = JsonSerializer.SerializeToString(dto); if (i++ < msgCount - 1) { Console.WriteLine("{0},", json); } else { Console.WriteLine(json); } } if (destinationBuffer == null) { Console.WriteLine("]"); } } else { foreach (var msg in sourceBuffer) { destinationBuffer.Add(msg); } destinationBuffer.Flush(); } } finally { if (sourceBuffer != null) { sourceBuffer.Dispose(); } if (destinationBuffer != null) { destinationBuffer.Dispose(); } } }
public SmartEndpointConsumeObserver(IMessageBuffer messageBuffer) { _messageBuffer = messageBuffer; }
static void Copy(string[] sourceFiles, string sourceFormat, string destinationFile, string destinationFormat) { if (sourceFiles == null || sourceFiles.Length == 0) { throw new ArgumentException(_("sourceFiles must not be empty.")); } var sourceBuffers = new List <IMessageBuffer>(); IMessageBuffer destinationBuffer = null; try { foreach (var sourceFile in sourceFiles) { var sourceBufferType = ParseMessageBufferType(sourceFile, sourceFormat); var sourceBuffer = CreateMessageBuffer(sourceFile, sourceBufferType); sourceBuffers.Add(sourceBuffer); } if (!String.IsNullOrEmpty(destinationFile)) { var destinationBufferType = ParseMessageBufferType(destinationFile, destinationFormat); destinationBuffer = CreateMessageBuffer(destinationFile, destinationBufferType); if (destinationBuffer.Count > 0) { throw new InvalidOperationException( String.Format( _("Destination database {0} must be empty!"), destinationFile ) ); } } // append all messages of all source buffers together in a lazy way IEnumerable <MessageModel> concatenatedMessages = new List <MessageModel>(0); sourceBuffers.ForEach(x => concatenatedMessages = concatenatedMessages.Concat(x) ); if (destinationBuffer == null) { // JSON pipe WriteMessagesToJson(concatenatedMessages, Console.Out); } else { foreach (var msg in concatenatedMessages) { destinationBuffer.Add(msg); } destinationBuffer.Flush(); } } finally { foreach (var sourceBuffer in sourceBuffers) { sourceBuffer.Dispose(); } if (destinationBuffer != null) { destinationBuffer.Dispose(); } } }
public SmartEndpointSendObserver(IMessageBuffer messageBuffer) { _messageBuffer = messageBuffer; }