public void ShouldReportCorrectProgress() { StreamProgressReporter streamProgressReporter; MemoryStream stream; byte[] buffer; stream = new MemoryStream(new byte[10]); streamProgressReporter = new StreamProgressReporter(stream); buffer = new byte[1]; for (int t = 0; t < 10; t++) { Assert.AreEqual(t, streamProgressReporter.Position); Assert.AreEqual(10, streamProgressReporter.Length); stream.Read(buffer, 0, 1); } }
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); } } } }