private static void DuplicateTestWith6Entries( int nbEntries1, int nbEntries2, bool gzip = false ) { var folder = String.Format( "{0}\\ReadDuplicates", TestHelper.TestFolder ); TestHelper.CleanupFolder( folder ); string config = String.Format( @" <GrandOutputConfiguration> <Channel> <Add Type=""BinaryFile"" Name=""All-1"" MaxCountPerFile=""{1}"" Path=""{0}"" UseGzipCompression=""{3}"" /> <Add Type=""BinaryFile"" Name=""All-2"" MaxCountPerFile=""{2}"" Path=""{0}"" UseGzipCompression=""{3}"" /> </Channel> </GrandOutputConfiguration> ", folder, nbEntries1, nbEntries2, gzip ); using( var o = new GrandOutput() ) { GrandOutputConfiguration c = new GrandOutputConfiguration(); Assert.That( c.Load( XDocument.Parse( config ).Root, TestHelper.ConsoleMonitor ), Is.True ); Assert.That( o.SetConfiguration( c, TestHelper.ConsoleMonitor ), Is.True ); var m = new ActivityMonitor(); o.Register( m ); var direct = m.Output.RegisterClient( new CKMonWriterClient( folder, Math.Min( nbEntries1, nbEntries2 ), LogFilter.Debug, gzip ) ); // 6 traces that go to the GrandOutput but also to the direct CKMonWriterClient. m.Trace().Send( "Trace 1" ); m.OpenTrace().Send( "OpenTrace 1" ); m.Trace().Send( "Trace 1.1" ); m.Trace().Send( "Trace 1.2" ); m.CloseGroup(); m.Trace().Send( "Trace 2" ); System.Threading.Thread.Sleep( 100 ); m.Output.UnregisterClient( direct ); } var files = TestHelper.WaitForCkmonFilesInDirectory( folder, 3 ); for( int pageReadLength = 1; pageReadLength < 10; ++pageReadLength ) { MultiLogReader reader = new MultiLogReader(); reader.Add( files ); var map = reader.GetActivityMap(); Assert.That( map.ValidFiles.All( rawFile => rawFile.IsValidFile ), Is.True, "All files are correctly closed with the final 0 byte and no exception occurred while reading them." ); var readMonitor = map.Monitors.Single(); List<ParentedLogEntry> allEntries = new List<ParentedLogEntry>(); using( var pageReader = readMonitor.ReadFirstPage( pageReadLength ) ) { do { allEntries.AddRange( pageReader.Entries ); } while( pageReader.ForwardPage() > 0 ); } CollectionAssert.AreEqual( new[] { "Trace 1", "OpenTrace 1", "Trace 1.1", "Trace 1.2", null, "Trace 2" }, allEntries.Select( e => e.Entry.Text ).ToArray(), StringComparer.Ordinal ); } }
public void FilteringBySource() { TestHelper.CleanupFolder( SystemActivityMonitor.RootLogPath + "FilteringBySource" ); using( GrandOutput g = new GrandOutput() ) { GrandOutputConfiguration config = new GrandOutputConfiguration(); config.Load( XDocument.Parse( @" <GrandOutputConfiguration> <Channel MinimalFilter=""Debug""> <Add Type=""BinaryFile"" Name=""All"" Path=""FilteringBySource"" /> <Channel Name=""HiddenTopic"" MinimalFilter=""Off"" TopicRegex=""(hidden\s+topic|hide\s+this\s+topic)"" MatchOptions=""CultureInvariant, ExplicitCapture, Compiled, Multiline"" /> </Channel> <SourceOverrideFilter> <Add File=""SourceFile-Debug.cs"" Filter=""Debug"" /> <Add File=""SourceFile-Off.cs"" Filter=""Off"" /> <Add File=""SourceFile-Strange.cs"" Filter=""{Trace,Fatal}"" /> </SourceOverrideFilter> </GrandOutputConfiguration>", LoadOptions.SetLineInfo ).Root, TestHelper.ConsoleMonitor ); Assert.That( g.SetConfiguration( config, TestHelper.ConsoleMonitor ) ); var m = new ActivityMonitor( false ); g.Register( m ); m.Fatal( fileName: "SourceFile-Off.cs" ).Send( "NOSHOW" ); m.SetTopic( "This is a hidden topic..." ); m.Trace( 0, "SourceFile-Debug.cs" ).Send( "Trace-1" ); m.Trace().Send( "NOSHOW" ); m.SetTopic( "Please, hide this topic!" ); m.Trace( fileName: "SourceFile-Strange.cs" ).Send( "NOSHOW" ); using( m.OpenTrace( fileName: "SourceFile-Strange.cs" ).Send( "Trace-2" ) ) { m.Trace( fileName: "SourceFile-Strange.cs" ).Send( "NOSHOW" ); m.Fatal( fileName: "SourceFile-Strange.cs" ).Send( "Fatal-1" ); m.Fatal( fileName: "SourceFile-Off.cs" ).Send( "NOSHOW" ); } m.SetTopic( null ); m.Trace( fileName: "SourceFile-Strange.cs" ).Send( "NOSHOW" ); m.Fatal( fileName: "SourceFile-Off.cs" ).Send( "NOSHOW" ); m.Trace().Send( "Trace-3" ); } List<StupidStringClient> logs = TestHelper.ReadAllLogs( new DirectoryInfo( SystemActivityMonitor.RootLogPath + "FilteringBySource" ), false ); Assert.That( logs.Count, Is.EqualTo( 1 ) ); Assert.That( logs[0].ToString(), Does.Not.Contain( "NOSHOW" ) ); var texts = logs[0].Entries.Select( e => e.Text ).ToArray(); CollectionAssert.AreEqual( new string[] { "Trace-1", "Trace-2", "Fatal-1", ActivityMonitor.SetTopicPrefix, "Trace-3", }, texts, StringComparer.Ordinal ); }
/// <summary> /// Creates a new instance of this ViewModel. /// </summary> /// <param name="loadDefaultState">True if the default XML state should be loaded, false to start on an empty state.</param> public MainWindowViewModel( bool loadDefaultState = false ) { _recentFiles = new CKObservableSortedArrayList<RecentFile>( ( a, b ) => DateTime.Compare( b.AccessTime, a.AccessTime ) ); // Lab objects, live objects and static infos are managed in the LabStateManager. _labStateManager = new LabStateManager(); _engine = _labStateManager.Engine; _labStateManager.Engine.PropertyChanged += Engine_PropertyChanged; _labStateManager.ServiceInfos.CollectionChanged += ServiceInfos_CollectionChanged; _labStateManager.PluginInfos.CollectionChanged += PluginInfos_CollectionChanged; _labStateManager.RunningPlugins.CollectionChanged += RunningPlugins_CollectionChanged; _engine.Configuration.Layers.CollectionChanged += Layers_CollectionChanged; _activityMonitor = new ActivityMonitor(); _activityMonitor.OpenTrace().Send( "Hello world" ); _graph = new YodiiGraph( _engine.Configuration, _labStateManager ); _removeSelectedVertexCommand = new RelayCommand( RemoveSelectedVertexExecute, CanEditSelectedVertex ); _toggleEngineCommand = new RelayCommand( ToggleEngineExecute ); _openFileCommand = new RelayCommand( OpenFileExecute ); _saveAsFileCommand = new RelayCommand( SaveAsFileExecute ); _saveCommand = new RelayCommand( SaveExecute ); // Save is always available.e _reorderGraphLayoutCommand = new RelayCommand( ReorderGraphLayoutExecute ); _createPluginCommand = new RelayCommand( CreatePluginExecute, CanEditItems ); _createServiceCommand = new RelayCommand( CreateServiceExecute, CanEditItems ); _openConfigurationEditorCommand = new RelayCommand( OpenConfigurationEditorExecute ); _newFileCommand = new RelayCommand( NewFileExecute ); _revokeAllCommandsCommand = new RelayCommand( RevokeAllCommandsExecute, CanRevokeAllCommands ); _autoPositionCommand = new RelayCommand( AutoPositionExecute ); LoadRecentFiles(); // Appication is only available on WPF context. if( Application.Current != null ) { _autosaveTimer = new DispatcherTimer( DispatcherPriority.Background, Application.Current.Dispatcher ); } else { _autosaveTimer = new DispatcherTimer( DispatcherPriority.Background, Dispatcher.CurrentDispatcher ); } _autosaveTimer.Interval = new TimeSpan( 0, 0, 5 ); _autosaveTimer.Tick += AutosaveTick; // Autosave timer is started from outside, using StartAutosaveTimer(). if( loadDefaultState ) LoadDefaultState(); }
static void DumpSampleLogs2( Random r, GrandOutput g ) { var m = new ActivityMonitor( false ); g.Register( m ); m.Fatal().Send( ThrowExceptionWithInner( false ), "An error occured" ); m.SetTopic( "This is a topic..." ); m.Trace().Send( "a trace" ); m.Trace().Send( "another one" ); m.SetTopic( "Please, show this topic!" ); m.Trace().Send( "Anotther trace." ); using( m.OpenTrace().Send( "A group trace." ) ) { m.Trace().Send( "A trace in group." ); m.Info().Send( "An info..." ); using( m.OpenInfo().Send( @"A group information... with a multi -line message. This MUST be correctly indented!" ) ) { m.Info().Send( "Info in info group." ); m.Info().Send( "Another info in info group." ); m.Error().Send( ThrowExceptionWithInner( true ), "An error." ); m.Warn().Send( "A warning." ); m.Trace().Send( "Something must be said." ); m.CloseGroup( "Everything is in place." ); } } m.SetTopic( null ); using( m.OpenTrace().Send( "A group with multiple conclusions." ) ) { using( m.OpenTrace().Send( "A group with no conclusion." ) ) { m.Trace().Send( "Something must be said." ); } m.CloseGroup( new[] { new ActivityLogGroupConclusion( "My very first conclusion." ), new ActivityLogGroupConclusion( "My second conclusion." ), new ActivityLogGroupConclusion( @"My very last conclusion is a multi line one. and this is fine!" ) } ); } m.Trace().Send( "This is the final trace." ); }
static void DumpSampleLogs1( Random r, GrandOutput g ) { var m = new ActivityMonitor( false ); g.Register( m ); m.SetTopic( "First Activity..." ); if( r.Next( 3 ) == 0 ) System.Threading.Thread.Sleep( 100 + r.Next( 2500 ) ); using( m.OpenTrace().Send( "Opening trace" ) ) { if( r.Next( 3 ) == 0 ) System.Threading.Thread.Sleep( 100 + r.Next( 2500 ) ); m.Trace().Send( "A trace in group." ); if( r.Next( 3 ) == 0 ) System.Threading.Thread.Sleep( 100 + r.Next( 2500 ) ); m.Info().Send( "An info in group." ); if( r.Next( 3 ) == 0 ) System.Threading.Thread.Sleep( 100 + r.Next( 2500 ) ); m.Warn().Send( "A warning in group." ); if( r.Next( 3 ) == 0 ) System.Threading.Thread.Sleep( 100 + r.Next( 2500 ) ); m.Error().Send( "An error in group." ); if( r.Next( 3 ) == 0 ) System.Threading.Thread.Sleep( 100 + r.Next( 2500 ) ); m.Fatal().Send( "A fatal in group." ); } if( r.Next( 3 ) == 0 ) System.Threading.Thread.Sleep( 100 + r.Next( 2500 ) ); m.Trace().Send( "End of first activity." ); }