예제 #1
0
        public void ShouldThrowExceptionWhenLogIsNull()
        {
            LogParser parser;
            Log       log;

            Column[] columns;

            columns = new Column[] { new Column()
                                     {
                                         Name = "C1"
                                     }, new Column()
                                     {
                                         Name = "C2"
                                     }, new Column()
                                     {
                                         Name = "C3"
                                     }, new Column()
                                     {
                                         Name = "C4"
                                     } };

            parser = new LogParser(columns);
            parser.Add(@"(?<C1>\d)(\|)(?<C2>\d)(\|)(?<C3>\d)(\|)(?<C5>\d$)");             // changed C4 to C5 to simulate missing column

            log = null;

            Assert.ThrowsException <ArgumentNullException>(() => parser.Parse(log));
        }
예제 #2
0
        public void ShouldParseWhenColumnIsMissingInRegexPattern()
        {
            LogParser parser;
            Log       log;
            Event     ev;

            Column[] columns;

            columns = new Column[] { new Column()
                                     {
                                         Name = "C1"
                                     }, new Column()
                                     {
                                         Name = "C2"
                                     }, new Column()
                                     {
                                         Name = "C3"
                                     }, new Column()
                                     {
                                         Name = "C4"
                                     } };

            parser = new LogParser(columns);
            parser.Add(@"(?<C1>\d)(\|)(?<C2>\d)(\|)(?<C3>\d)(\|)(?<C5>\d$)");             // changed C4 to C5 to simulate missing column

            log = new Log();
            log.Lines.Add(new Line()
            {
                Value = log1
            });
            ev = parser.Parse(log);


            Assert.IsNotNull(ev);
            Assert.AreEqual(4, ev.Properties.Count);
            Assert.AreEqual("1", ev["C1"]);
            Assert.AreEqual("2", ev["C2"]);
            Assert.AreEqual("3", ev["C3"]);
            Assert.AreEqual("", ev["C4"]);
        }
예제 #3
0
        public void ShouldParse()
        {
            LogParser parser;
            Log       log;
            Event     ev;

            Column[] columns;

            columns = new Column[] { new Column()
                                     {
                                         Name = "C1"
                                     }, new Column()
                                     {
                                         Name = "C2"
                                     }, new Column()
                                     {
                                         Name = "C3"
                                     }, new Column()
                                     {
                                         Name = "C4"
                                     } };

            parser = new LogParser(columns);
            parser.Add(@"(?<C1>\d)(\|)(?<C2>\d)(\|)(?<C3>\d)(\|)(?<C4>\d$)");

            log = new Log();
            log.Lines.Add(new Line()
            {
                Value = log1
            });
            ev = parser.Parse(log);


            Assert.IsNotNull(ev);
            Assert.AreEqual(4, ev.Properties.Count);
            Assert.AreEqual("1", ev["C1"]);
            Assert.AreEqual("2", ev["C2"]);
            Assert.AreEqual("3", ev["C3"]);
            Assert.AreEqual("4", ev["C4"]);
        }
예제 #4
0
        private async Task Open(string FileName)
        {
            FormatHandlerSelectionWindow window;

            LogFile logFile;
            ILogFileLoaderModule       logFileLoaderModule;
            LoadWindow                 loadWindow;
            IColorProviderModule       colorProviderModule;
            IInlineParserFactoryModule inlineParserBuilderModule;
            IStringReader              stringReader;
            ILineReader                lineReader;
            ILogReader                 logReader;
            LogParser logParser;
            IStringMatcherFactoryModule stringMatcherFactoryModule;
            FileStream        stream;
            IProgressReporter progressReporter;

            FormatHandler[] formatHandlers;
            FormatHandler   formatHandler;

            formatHandlers = formatHandlerLibraryModule.GetFormatHandlers(FileName).ToArray();

            if (formatHandlers.Length == 0)
            {
                ShowError("Cannot find any format handler");
                return;
            }
            else if (formatHandlers.Length < 3)
            {
                formatHandler = formatHandlers[0];
            }
            else
            {
                window = new FormatHandlerSelectionWindow()
                {
                    Owner = this, FormatHandlers = formatHandlers.Take(formatHandlers.Length - 1)
                };
                if (!window.ShowDialog() ?? false)
                {
                    return;
                }
                if (window.SelectedFormatHandler == null)
                {
                    return;
                }
                formatHandler = window.SelectedFormatHandler;
            }

            logFile                   = new LogFile(FileName, formatHandler);
            colorProviderModule       = new ColorProviderModule(logger, logFile.FormatHandler.EventColoringRules);
            inlineParserBuilderModule = new InlineParserFactoryModule(logger, patternLibraryModule, inlineColoringRuleLibraryModule);

            stringMatcherFactoryModule = new StringMatcherFactoryModule(logger, patternLibraryModule);


            try
            {
                stream = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            }
            catch (Exception ex)
            {
                ShowError(ex);
                return;
            }

            using (stream)
            {
                progressReporter = new StreamProgressReporter(stream);
                stringReader     = new LogInspect.BaseLib.Readers.StringReader(new StreamReader(stream));
                lineReader       = new LineReader(stringReader, stringMatcherFactoryModule.CreateStringMatcher(logFile.FormatHandler.NameSpace, logFile.FormatHandler.DiscardLinePatterns));
                logReader        = new LogReader(lineReader,
                                                 stringMatcherFactoryModule.CreateStringMatcher(logFile.FormatHandler.NameSpace, logFile.FormatHandler.LogPrefixPatterns),
                                                 stringMatcherFactoryModule.CreateStringMatcher(logFile.FormatHandler.NameSpace, logFile.FormatHandler.Rules.Where(item => item.Discard).Select(item => item.GetPattern()))
                                                 );
                logParser = new LogParser(logFile.FormatHandler.Columns);
                logParser.Add(patternLibraryModule.Build(logFile.FormatHandler.NameSpace, logFile.FormatHandler.Rules.Where(item => !item.Discard).Select(item => item.GetPattern()), true));

                logFileLoaderModule = new LogFileLoaderModule(logger, logReader, logParser);
                //logFileLoaderModule = new InfiniteLogFileLoaderModule(logger);

                loadWindow = new LoadWindow(logFileLoaderModule, progressReporter, logFile); loadWindow.Owner = this;
                if (loadWindow.Load() ?? false)
                {
                    try
                    {
                        await appViewModel.Open(logFile, inlineParserBuilderModule, colorProviderModule);
                    }
                    catch (Exception ex)
                    {
                        ShowError(ex);
                    }
                }
            }
        }