public void LogMonitorTest() { var monitor = new SharePointLogMonitor(); var path = Path.Combine(dir, file); try { //create monitor var settings = new SharePointLogMonitorSettings() { Directory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dir), Interval = 30 }; monitor.MonitorDirectory = settings.Directory; monitor.Interval = settings.Interval.Value; monitor.Start(); Assert.IsTrue(monitor.MonitorDirectory == settings.Directory); Assert.IsTrue(monitor.Interval == settings.Interval); //create log file and let monitor take initial count File.Copy(SharePointLogFileTests.good_SPTestFile, path); Thread.Sleep(settings.Interval.Value * _intervalMulti); var count1 = monitor.LogSet.Entries.Count; monitor.Stop(); monitor.Start(); using (var append = new StreamReader(File.Open(SharePointLogFileTests.good_SPTestFile, FileMode.Open))) { append.ReadLine(); var entry = append.ReadLine(); File.AppendAllText(path, entry, Encoding.Unicode);//-add 1 entry- } Thread.Sleep(settings.Interval.Value * _intervalMulti); var count2 = monitor.LogSet.Entries.Count; Assert.IsTrue((count1 + 1) == count2);//-check that 1 entry was added- } catch (Exception ex) { if (ex is AssertFailedException) { throw; } } finally { monitor.Stop(); File.Delete(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path)); monitor.Dispose(); } }
private void ToolbarButton_Click(object sender, RoutedEventArgs e) { var command = ((string)((Button)e.Source).CommandParameter).ToUpper(); if (command == "NEW") { var files = ShowSelectFilesDialog(); ProcessLogFiles(files); } else if (command == "SEARCH") { ToggleSearchPanelVisbility(); } else if (command == "METRICS") { if (this.ActiveTab.MetricsWindow != null) { //check if window has been closed if (!this.ActiveTab.MetricsWindow.IsLoaded) { var metrics = new LogSetMetricsHTML(this.ActiveTab.Content.LogSetDataSource); metrics.Owner = this; this.ActiveTab.MetricsWindow = metrics; metrics.Show(); } else { ((LogSetMetricsHTML)this.ActiveTab.MetricsWindow).Refresh(); } } else { var metrics = new LogSetMetricsHTML(this.ActiveTab.Content.LogSetDataSource); metrics.Owner = this; this.ActiveTab.MetricsWindow = metrics; metrics.Show(); } } else if (command == "MONITOR") { //get settings if none exists, exit if user cancels otherwise continue and start monitor if (_spLogMonitorSettings == null) { var settings = GetSPLogMonitorDirectory(out _spLogMonitorSettings); if (!settings) { return; } } //if settings exist already, start monitor if (_spLogMonitorSettings != null) { if (_spLogMonitor == null) { CreateSPLogMonitor(); } if (!_spLogMonitor.IsRunning) { _spLogMonitor.Start(); imgMonitoring.Source = (BitmapImage)FindResource("bmpStop16"); btnMonitoring.ToolTip = "Stop log monitoring."; if (_spLogMonitorWin == null) { _spLogMonitorWin = new SPLogMonitor(_spLogMonitor.LogSet); } _spLogMonitorWin.Show(); } else { _spLogMonitor.Stop(); imgMonitoring.Source = (BitmapImage)FindResource("bmpPlay16"); btnMonitoring.ToolTip = "Start log monitoring..."; } } } }