//点击Extract按钮后会触发,整个函数运行完则获取到所有数据并显示 private async Task <long> StartReadAndExtract() { Stopwatch watch = new Stopwatch(); watch.Start(); ILogReader logReader = new LogSubstringReader(this.logFileName); //主要耗时部分 var Passes = await logReader.ReadAndExtractPasses(new Progress <ReadProgress>(p => this.UpdateReadProgress(p))); this.listPasses = Passes.ToList(); this.DisplayPasses(this.listPasses); watch.Stop(); return(watch.ElapsedMilliseconds); }
public void TestWriteNonEmptyLinesExactlySame() { string tempFile1 = Path.GetTempFileName(); File.WriteAllText(tempFile1, onePassTextWith2Tests); var readProgress = new Progress <ReadProgress>(); var reader1 = new LogSubstringReader(tempFile1); var task1 = reader1.ReadAndExtractPasses(readProgress); IList <Pass> passes1 = task1.Result; string tempFile2 = Path.GetTempFileName(); var writer = new LogWriter(tempFile2); var tw = Task.Run(() => writer.SavePasses(passes1)); Task.WaitAll(tw); string[] lines1 = File.ReadAllLines(tempFile1); string[] lines2 = File.ReadAllLines(tempFile2); File.Delete(tempFile1); File.Delete(tempFile2); string[] nonEmptyLines1 = lines1.Where(x => !string.IsNullOrWhiteSpace(x)).ToArray(); string[] nonEmptyLines2 = lines2.Where(x => !string.IsNullOrWhiteSpace(x)).ToArray(); Assert.IsTrue(nonEmptyLines1.Length > 0); Assert.AreEqual <int>(nonEmptyLines1.Length, nonEmptyLines2.Length); for (int i = 0; i < nonEmptyLines1.Length; i++) { Assert.AreEqual <string>(nonEmptyLines1[i], nonEmptyLines2[i]); } int minLinesCount = lines1.Length <= lines2.Length ? lines1.Length : lines2.Length; for (int i = 0; i < minLinesCount; i++) { Assert.AreEqual <string>(lines1[i], lines1[i]); } }
public void TestWriteKeepData() { string tempFile1 = Path.GetTempFileName(); File.WriteAllText(tempFile1, onePassTextWith2Tests); var readProgress = new Progress <ReadProgress>(); var reader1 = new LogSubstringReader(tempFile1); var task1 = reader1.ReadAndExtractPasses(readProgress); IList <Pass> passes1 = task1.Result; File.Delete(tempFile1); string tempFile2 = Path.GetTempFileName(); var writer = new LogWriter(tempFile2); var tw = Task.Run(() => writer.SavePasses(passes1)); Task.WaitAll(tw); var reader2 = new LogSubstringReader(tempFile2); var task2 = reader2.ReadAndExtractPasses(readProgress); IList <Pass> passes2 = task2.Result; File.Delete(tempFile2); Assert.AreEqual(passes1.Count, passes2.Count); for (int i = 0; i < passes1.Count; i++) { Assert.AreEqual(passes1[i].StartDateString, passes2[i].StartDateString); Assert.AreEqual(passes1[i].EndDate, passes2[i].EndDate); Assert.AreEqual(passes1[i].listTests.Count, passes2[i].listTests.Count); for (int j = 0; j < passes1[i].listTests.Count; j++) { Assert.AreEqual(passes1[i].listTests[j].Date, passes2[i].listTests[j].Date); Assert.AreEqual(passes1[i].listTests[j].SN, passes2[i].listTests[j].SN); Assert.AreEqual(passes1[i].listTests[j].Status, passes2[i].listTests[j].Status); } } }
//点击Extract按钮后会触发,整个函数运行完则获取到所有数据并显示 private async Task <long> StartReadAndExtract() { Stopwatch watch = new Stopwatch(); watch.Start(); ILogReader logReader = new LogSubstringReader(this.LogFileName); //主要耗时部分 var Passes = await logReader.ReadAndExtractPasses(new Progress <ReadProgress>(p => this.UpdateReadProgress(p))); //WPF显示的需要,把List<Pass>转化为ObservableCollection<PassViewModel> this.ObsPasses = new ObservableCollection <PassViewModel>( Passes //.OrderBy(x => x.StartDate)//不改变写时顺序 .Select(x => new PassViewModel(x))); this.RaisePropertyChanged(() => this.PassesCntMsg); watch.Stop(); return(watch.ElapsedMilliseconds); }