public void FormatNull() { var formatter = new DataFormatter(); string serialized = formatter.Format(null); Assert.Equal("null", serialized); }
public void FormatExceptionHasNoWhiteSpace() { var formatter = new DataFormatter(); string serialized = formatter.Format(new NullReferenceException("this is null exception")); Assert.False(serialized.Contains('\n')); }
public override void Parse(ParserContext ctx, ResponseMessage resMsg) { var regex = new Regex($@"^45(\d+)-{ctx.Namespace}\[(.+)\]$"); if (regex.IsMatch(resMsg.Text)) { ClearBinary(ctx); var groups = regex.Match(resMsg.Text).Groups; ctx.ReceivedBufferCount = int.Parse(groups[1].Value); string text = groups[2].Value; var formatter = new DataFormatter(); var data = formatter.Format(text); var eventHandlerArg = new ResponseArgs { RawText = resMsg.Text }; string eventName = JsonConvert.DeserializeObject <string>(data[0]); if (data.Count > 1) { eventHandlerArg.Text = data[1]; } if (ctx.EventHandlers.ContainsKey(data[0])) { var handlerBox = ctx.EventHandlers[data[0]]; if (handlerBox.EventHandler != null) { ctx.BinaryEvents.Add(new BinaryEvent { EventHandler = handlerBox.EventHandler, ResponseArgs = eventHandlerArg }); } if (handlerBox.EventHandlers != null) { for (int i = 0; i < handlerBox.EventHandlers.Count; i++) { var arg = new ResponseArgs { RawText = resMsg.Text }; if (i + 2 <= data.Count - 1) { arg.Text = data[i + 2]; } ctx.BinaryEvents.Add(new BinaryEvent { EventHandler = handlerBox.EventHandlers[i], ResponseArgs = arg }); } } } } else if (Next != null) { Next.Parse(ctx, resMsg); } }
/// <summary> /// Gets a hex representation of this buffer. /// </summary> /// <returns>A string representing this buffer's contents in hexadecimal notation.</returns> public override string ToString() { if (_target != null) { return(DataFormatter.Format(_buffer, _target.StartingPosition, Count)); } else { return(DataFormatter.Format(_buffer, 0, Count)); } }
public void Parse(ResponseTextParser rtp) { var regex = new Regex($@"^42{rtp.Namespace}\d*\[(.+)\]$"); if (regex.IsMatch(rtp.Text)) { var groups = regex.Match(rtp.Text).Groups; string text = groups[1].Value; var formatter = new DataFormatter(); var data = formatter.Format(text); var eventHandlerArg = new ResponseArgs { RawText = rtp.Text }; string eventName = JsonConvert.DeserializeObject <string>(data[0]); if (data.Count > 1) { eventHandlerArg.Text = data[1]; } if (rtp.Socket.EventHandlers.ContainsKey(data[0])) { var handlerBox = rtp.Socket.EventHandlers[data[0]]; handlerBox.EventHandler?.Invoke(eventHandlerArg); if (handlerBox.EventHandlers != null) { for (int i = 0; i < handlerBox.EventHandlers.Count; i++) { var arg = new ResponseArgs { RawText = rtp.Text }; if (i + 2 <= data.Count - 1) { arg.Text = data[i + 2]; } handlerBox.EventHandlers[i](arg); } } } else { rtp.UncaughtHandler(eventName, eventHandlerArg); } rtp.ReceiveHandler(eventName, eventHandlerArg); } else { rtp.Parser = new MessageAckParser(); rtp.Parse(); } }
public void Print(List <Profile> data, IPrinter printer, DataFormatter formatter) { if (_options.Verbose) { printer.Print(formatter.Format(data)); } if (_options.Log) { printer = new FilePrinter(); formatter = new ReportFormatter(); printer.Print(formatter.Format(data)); wg.Generate(data); } }
public override void Parse(ParserContext ctx, ResponseMessage resMsg) { var regex = new Regex($@"^42{ctx.Namespace}\d*\[(.+)\]$"); if (regex.IsMatch(resMsg.Text)) { var groups = regex.Match(resMsg.Text).Groups; string text = groups[1].Value; var formatter = new DataFormatter(); var data = formatter.Format(text); var eventHandlerArg = new ResponseArgs { RawText = resMsg.Text }; string eventName = JsonConvert.DeserializeObject <string>(data[0]); if (data.Count > 1) { eventHandlerArg.Text = data[1]; } if (ctx.EventHandlers.ContainsKey(data[0])) { var handlerBox = ctx.EventHandlers[data[0]]; handlerBox.EventHandler?.Invoke(eventHandlerArg); if (handlerBox.EventHandlers != null) { for (int i = 0; i < handlerBox.EventHandlers.Count; i++) { var arg = new ResponseArgs { RawText = resMsg.Text }; if (i + 2 <= data.Count - 1) { arg.Text = data[i + 2]; } handlerBox.EventHandlers[i](arg); } } } else { ctx.UncaughtHandler(eventName, eventHandlerArg); } ctx.ReceiveHandler(eventName, eventHandlerArg); } else if (Next != null) { Next.Parse(ctx, resMsg); } }
/// <summary> /// Gets a hex representation of this buffer. /// </summary> /// <returns>A string representing this buffer's contents in hexadecimal notation.</returns> public override string ToString() { return(DataFormatter.Format(_data, _baseIndex, _baseSize)); }
/// <summary> /// Gets a hex representation of this data. /// </summary> /// <returns>A string representing this buffer's contents in hexadecimal notation.</returns> public override string ToString() { return(DataFormatter.Format(this.UnderlyingBuffer.UnderlyingBuffer, 0, this.Length)); }
/// <inheritdoc/> public override string ToString() { return(DataFormatter.Format(_underlyingBuffer, _bufferStart, _bufferLength)); }