예제 #1
0
 public MessagesReader(MediaBasedReaderParams readerParams, JsonFormatInfo fmt) :
     base(readerParams.Media, fmt.BeginFinder, fmt.EndFinder, fmt.ExtensionsInitData, fmt.TextStreamPositioningParams, readerParams.Flags, readerParams.SettingsAccessor)
 {
     this.formatInfo         = fmt;
     this.threads            = readerParams.Threads;
     this.traceSourceFactory = readerParams.TraceSourceFactory;
 }
예제 #2
0
        static IMessage MakeMessageInternal(TextMessageCapture capture, JsonFormatInfo formatInfo, IRegex bodyRe, ref IMatch bodyReMatch,
                                            MessagesBuilderCallback callback, DateTime sourceTime, ITimeOffsets timeOffsets)
        {
            StringBuilder messageBuf = new StringBuilder();

            messageBuf.Append(capture.HeaderBuffer, capture.HeaderMatch.Index, capture.HeaderMatch.Length);
            if (bodyRe != null)
            {
                if (!bodyRe.Match(capture.BodyBuffer, capture.BodyIndex, capture.BodyLength, ref bodyReMatch))
                {
                    return(null);
                }
                messageBuf.Append(capture.BodyBuffer, bodyReMatch.Index, bodyReMatch.Length);
            }
            else
            {
                messageBuf.Append(capture.BodyBuffer, capture.BodyIndex, capture.BodyLength);
            }

            callback.SetCurrentPosition(capture.BeginPosition, capture.EndPosition);

            string messageStr = messageBuf.ToString();

            var transfromed = JsonTransformer.Transform(
                formatInfo.Transform.DeepClone() as JObject,
                JObject.Parse(messageStr)
                );
            var      d = transfromed.Property("d")?.Value;
            DateTime date;

            if (d != null && d.Type == JTokenType.String)
            {
                date = DateTime.Parse(d.ToString(), null, System.Globalization.DateTimeStyles.RoundtripKind);
            }
            else if (d != null && d.Type == JTokenType.Date)
            {
                date = (DateTime)((JValue)d).Value;
            }
            else
            {
                throw new Exception("Bad time property \"d\"");
            }

            var t = transfromed.Property("t")?.Value?.ToString();

            var m   = transfromed.Property("m")?.Value;
            var msg = "";

            if (m != null)
            {
                msg = m.ToString();
            }

            var s   = transfromed.Property("s")?.Value?.ToString();
            var sev = !string.IsNullOrEmpty(s) ? char.ToLower(s[0]) : 'i';

            IMessage ret = new Content(
                capture.BeginPosition, capture.EndPosition,
                callback.GetThread(new StringSlice(t ?? "")),
                new MessageTimestamp(date),
                new StringSlice(msg),
                sev == 'i' ? SeverityFlag.Info :
                sev == 'e' ? SeverityFlag.Error :
                sev == 'w' ? SeverityFlag.Warning :
                SeverityFlag.Info
                );

            if (formatInfo.ViewOptions.RawViewAllowed)
            {
                ret.SetRawText(StringSlice.Concat(capture.MessageHeaderSlice, capture.MessageBodySlice).Trim());
            }
            if (formatInfo.ViewOptions.WrapLineLength.HasValue)
            {
                ret.WrapsTexts(formatInfo.ViewOptions.WrapLineLength.Value);
            }

            return(ret);
        }