Esempio n. 1
0
            public async Task Read(
                IYieldAsync <Message[]> yieldAsync,
                Func <Stream> getStream, Action <Stream> releaseStream,
                CancellationToken cancellation,
                Action <double> progressHandler,
                ITextLogParser textLogParser)
            {
                var inputStream = getStream();

                try
                {
                    await textLogParser.ParseStream(
                        inputStream,
                        textLogParser.CreateRegexHeaderMatcher(logMessageRegex),
                        async messagesInfo =>
                    {
                        var outMessages = new Message[messagesInfo.Count];
                        for (int i = 0; i < messagesInfo.Count; ++i)
                        {
                            var mi          = messagesInfo[i];
                            var headerMatch = ((IRegexHeaderMatch)mi.HeaderMatch).Match;
                            var body        = mi.MessageBoby;
                            outMessages[i]  = new Message(
                                mi.MessageIndex,
                                mi.StreamPosition,
                                TimeUtils.UnixTimestampMillisToDateTime(
                                    long.Parse(headerMatch.Groups["d"].Value, CultureInfo.InvariantCulture) * 1000 +
                                    long.Parse(headerMatch.Groups["ms"].Value, CultureInfo.InvariantCulture)
                                    ).ToUnspecifiedTime(),
                                headerMatch.Groups["mils"].Value[0],
                                new StringSlice(mi.Buffer, headerMatch.Groups["sev"]),
                                body
                                );
                        }

                        if (cancellation.IsCancellationRequested)
                        {
                            return(false);
                        }

                        return(await yieldAsync.YieldAsync(outMessages.ToArray()));
                    }, new TextLogParserOptions(progressHandler));
                }
                finally
                {
                    releaseStream(inputStream);
                }
            }
Esempio n. 2
0
            public async Task Read(
                IYieldAsync <Message[]> yieldAsync,
                Func <Stream> getStream, Action <Stream> releaseStream,
                string fileNameHint,
                CancellationToken cancellation,
                Action <double> progressHandler)
            {
                var inputStream = getStream();

                try
                {
                    await TextLogParser.ParseStream(
                        inputStream,
                        new RegexHeaderMatcher(logMessageRegex),
                        async messagesInfo =>
                    {
                        var outMessages = new Message[messagesInfo.Count];
                        for (int i = 0; i < messagesInfo.Count; ++i)
                        {
                            var mi          = messagesInfo[i];
                            var headerMatch = ((RegexHeaderMatch)mi.HeaderMatch).Match;
                            var body        = mi.MessageBoby;
                            outMessages[i]  = new Message(
                                mi.MessageIndex,
                                mi.StreamPosition,
                                DateTime.ParseExact(headerMatch.Groups["time"].Value, "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFF", CultureInfo.InvariantCulture),
                                new StringSlice(mi.Buffer, headerMatch.Groups["rootType"]),
                                new StringSlice(mi.Buffer, headerMatch.Groups["rootId"]),
                                new StringSlice(mi.Buffer, headerMatch.Groups["objId"]),
                                new StringSlice(mi.Buffer, headerMatch.Groups["propName"]),
                                new StringSlice(mi.Buffer, headerMatch.Groups["propVal"]),
                                new StringSlice(mi.Buffer, headerMatch.Groups["text"])
                                );
                        }

                        if (cancellation.IsCancellationRequested)
                        {
                            return(false);
                        }

                        return(await yieldAsync.YieldAsync(outMessages.ToArray()));
                    }, progressHandler);
                }
                finally
                {
                    releaseStream(inputStream);
                }
            }
Esempio n. 3
0
            public async Task Read(
                IYieldAsync <Message[]> yieldAsync,
                Func <Stream> getStream, Action <Stream> releaseStream,
                CancellationToken cancellation,
                Action <double> progressHandler,
                ITextLogParser textLogParser)
            {
                var inputStream = getStream();

                try
                {
                    await textLogParser.ParseStream(
                        inputStream,
                        textLogParser.CreateRegexHeaderMatcher(logMessageRegex),
                        async messagesInfo =>
                    {
                        var outMessages = new Message[messagesInfo.Count];
                        for (int i = 0; i < messagesInfo.Count; ++i)
                        {
                            var mi          = messagesInfo[i];
                            var headerMatch = ((IRegexHeaderMatch)mi.HeaderMatch).Match;
                            var body        = mi.MessageBoby;
                            outMessages[i]  = new Message(
                                mi.MessageIndex,
                                mi.StreamPosition,
                                new StringSlice(mi.Buffer, headerMatch.Groups["pid"]),
                                new StringSlice(mi.Buffer, headerMatch.Groups["tid"]),
                                DateTime.ParseExact(headerMatch.Groups["time"].Value, "MMdd/HHmmss.FFFFFF", CultureInfo.InvariantCulture),
                                new StringSlice(mi.Buffer, headerMatch.Groups["sev"]),
                                new StringSlice(mi.Buffer, headerMatch.Groups["file"]),
                                new StringSlice(mi.Buffer, headerMatch.Groups["line"]),
                                body
                                );
                        }

                        if (cancellation.IsCancellationRequested)
                        {
                            return(false);
                        }

                        return(await yieldAsync.YieldAsync(outMessages.ToArray()));
                    }, new TextLogParserOptions(progressHandler));
                }
                finally
                {
                    releaseStream(inputStream);
                }
            }
            public async Task Read(
                IYieldAsync <Message[]> yieldAsync,
                Func <Stream> getStream, Action <Stream> releaseStream,
                CancellationToken cancellation,
                Action <double> progressHandler,
                ITextLogParser textLogParser)
            {
                var inputStream = getStream();

                try
                {
                    await textLogParser.ParseStream(
                        inputStream,
                        textLogParser.CreateRegexHeaderMatcher(logMessageRegex),
                        async messagesInfo =>
                    {
                        var outMessages = new Message[messagesInfo.Count];
                        for (int i = 0; i < messagesInfo.Count; ++i)
                        {
                            var mi          = messagesInfo[i];
                            var headerMatch = ((IRegexHeaderMatch)mi.HeaderMatch).Match;
                            var body        = mi.MessageBoby;
                            outMessages[i]  = MakeMessage(
                                mi.MessageIndex,
                                mi.StreamPosition,
                                headerMatch,
                                mi.Buffer,
                                body
                                );
                        }

                        if (cancellation.IsCancellationRequested)
                        {
                            return(false);
                        }

                        return(await yieldAsync.YieldAsync(outMessages.ToArray()));
                    }, new TextLogParserOptions(progressHandler));
                }
                finally
                {
                    releaseStream(inputStream);
                }
            }
Esempio n. 5
0
            public async Task Read(
                IYieldAsync <Message[]> yieldAsync,
                Func <Stream> getStream, Action <Stream> releaseStream,
                CancellationToken cancellation,
                Action <double> progressHandler,
                ITextLogParser textLogParser)
            {
                var inputStream = getStream();

                try
                {
                    await textLogParser.ParseStream(
                        inputStream,
                        textLogParser.CreateRegexHeaderMatcher(logMessageRegex),
                        async messagesInfo =>
                    {
                        var outMessages = new List <Message>();
                        for (int i = 0; i < messagesInfo.Count; ++i)
                        {
                            var mi     = messagesInfo[i];
                            var xmlStr = $"{mi.HeaderMatch.ToString()}{mi.MessageBoby}";
                            using (var textReader = new StringReader(xmlStr))
                                using (var xmlReader = XmlReader.Create(textReader, new XmlReaderSettings()
                                {
                                    ConformanceLevel = ConformanceLevel.Fragment
                                }))
                                {
                                    if (xmlReader.MoveToContent() != XmlNodeType.Element)
                                    {
                                        continue;
                                    }
                                    var packetElement  = (XElement)XElement.ReadFrom(xmlReader);
                                    DateTime?timestamp = null;
                                    long?frameNumber   = null;
                                    var protos         = ImmutableDictionary.CreateBuilder <string, Message.Proto>();
                                    int protoIndex     = 0;
                                    foreach (var protoElement in packetElement.Elements("proto"))
                                    {
                                        var nameAttr = protoElement.Attribute("name");
                                        if (nameAttr == null)
                                        {
                                            continue;
                                        }
                                        if (nameAttr.Value == "geninfo")
                                        {
                                            var tsAttrValue = protoElement.Elements("field").Where(f => f.AttributeValue("name") == "timestamp").Select(f => f.AttributeValue("value")).FirstOrDefault();
                                            if (tsAttrValue != null && double.TryParse(tsAttrValue, out var tsParsed))
                                            {
                                                timestamp = Utils.UnixTimestampMillisToDateTime(tsParsed * 1000);
                                            }
                                            var frameNumberAttrValue = protoElement.Elements("field").Where(f => f.AttributeValue("name") == "num").Select(f => f.AttributeValue("value")).FirstOrDefault();
                                            if (frameNumberAttrValue != null && long.TryParse(frameNumberAttrValue, NumberStyles.HexNumber, null, out var frameNumberParsed))
                                            {
                                                frameNumber = frameNumberParsed;
                                            }
                                        }
                                        else
                                        {
                                            var fields = ImmutableDictionary.CreateBuilder <string, Message.Field>();
                                            foreach (var kv in protoElement
                                                     .Descendants("field")
                                                     .Select(fieldElement => new KeyValuePair <string, Message.Field>(fieldElement.AttributeValue("name"),
                                                                                                                      new Message.Field(fieldElement.AttributeValue("show", null), fieldElement.AttributeValue("value", null))))
                                                     .Where(kv => !string.IsNullOrEmpty(kv.Key) && (kv.Value.Show != null || kv.Value.Value != null)))
                                            {
                                                fields[kv.Key] = kv.Value;
                                            }
                                            protos[nameAttr.Value] = new Message.Proto(
                                                protoElement.AttributeValue("showname"),
                                                protoIndex++,
                                                fields.ToImmutable()
                                                );
                                        }
                                    }
                                    if (timestamp == null || frameNumber == null)
                                    {
                                        continue;
                                    }
                                    outMessages.Add(new Message(
                                                        mi.MessageIndex,
                                                        mi.StreamPosition,
                                                        timestamp.Value,
                                                        frameNumber.Value,
                                                        protos.ToImmutable()
                                                        ));
                                }
                        }

                        if (cancellation.IsCancellationRequested)
                        {
                            return(false);
                        }

                        return(await yieldAsync.YieldAsync(outMessages.ToArray()));
                    }, new TextLogParserOptions(progressHandler)
                    {
                        RawBufferSize = 16 * 1024 * 1024
                    });
                }
                finally
                {
                    releaseStream(inputStream);
                }
            }