예제 #1
0
        public void FormatNull()
        {
            var    formatter  = new DataFormatter();
            string serialized = formatter.Format(null);

            Assert.Equal("null", serialized);
        }
예제 #2
0
        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);
            }
        }
예제 #4
0
 /// <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));
     }
 }
예제 #5
0
        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();
            }
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
        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);
            }
        }
예제 #8
0
 /// <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));
 }
예제 #9
0
 /// <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));
 }
예제 #10
0
 /// <inheritdoc/>
 public override string ToString()
 {
     return(DataFormatter.Format(_underlyingBuffer, _bufferStart, _bufferLength));
 }