public PreprocessingManagerExtension(
     IStepsFactory preprocessingStepsFactory,
     ILogProviderFactory chromeDriverLogsFactory,
     ITextLogParser textLogParser)
 {
     this.preprocessingStepsFactory = preprocessingStepsFactory;
     this.chromeDriverLogsFactory   = chromeDriverLogsFactory;
     this.textLogParser             = textLogParser;
 }
Example #2
0
 internal TimeFixerPreprocessingStep(
     IStepsFactory preprocessingStepsFactory,
     ILogProviderFactory chromeDriverLogsFactory,
     PreprocessingStepParams srcFile,
     ITextLogParser textLogParser
     )
 {
     this.preprocessingStepsFactory = preprocessingStepsFactory;
     this.sourceFile = srcFile;
     this.chromeDriverLogsFactory = chromeDriverLogsFactory;
     this.textLogParser           = textLogParser;
 }
Example #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,
                                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);
                }
            }
Example #4
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);
                }
            }
Example #6
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);
                }
            }
Example #7
0
 public Reader(ITextLogParser textLogParser, CancellationToken cancellation)
 {
     this.textLogParser = textLogParser;
     this.cancellation  = cancellation;
 }
Example #8
0
 public Reader(ITextLogParser textLogParser) : this(CancellationToken.None, textLogParser)
 {
 }
Example #9
0
 public Reader(CancellationToken cancellation, ITextLogParser textLogParser)
 {
     this.cancellation  = cancellation;
     this.textLogParser = textLogParser;
 }