@@ -15,69 +15,68 @@ class OnlineExampleDataProvider : Analogy.LogViewer.Template.OnlineDataProvider
1515 public override string ? OptionalTitle { get ; set ; }
1616 public override Guid Id { get ; set ; }
1717
18- public override async Task < bool > CanStartReceiving ( ) => await Task . FromResult ( true ) ;
18+ public override Task < bool > CanStartReceiving ( ) => Task . FromResult ( true ) ;
1919
20- private readonly Timer SimulateOnlineMessages ;
21- private int messageCount = 0 ;
20+ private readonly Timer _simulateOnlineMessages ;
21+ private long _messageCount ;
2222 readonly Random _random = new Random ( ) ;
2323 readonly Array _values = Enum . GetValues ( typeof ( AnalogyLogLevel ) ) ;
24- private readonly List < string > processes = Process . GetProcesses ( ) . Select ( p => p . ProcessName ) . ToList ( ) ;
25- private readonly string prefixMessage ;
26- private readonly Random rnd = new Random ( ) ;
24+ private readonly List < string > _processes = Process . GetProcesses ( ) . Select ( p => p . ProcessName ) . ToList ( ) ;
25+ private readonly string _prefixMessage ;
26+ private readonly Random _rnd = new Random ( ) ;
2727
2828 public override IEnumerable < ( string originalHeader , string replacementHeader ) > GetReplacementHeaders ( )
2929 {
3030 yield return ( "Category" , "Test" ) ;
3131 }
3232
3333 public override ( Color backgroundColor , Color foregroundColor ) GetColorForMessage ( IAnalogyLogMessage logMessage )
34- => logMessage . Level == AnalogyLogLevel . Unknown ? ( Color . FromArgb ( rnd . Next ( 256 ) , rnd . Next ( 256 ) , rnd . Next ( 256 ) ) , Color . FromArgb ( rnd . Next ( 256 ) , rnd . Next ( 256 ) , rnd . Next ( 256 ) ) ) : ( Color . Empty , Color . Empty ) ;
34+ => logMessage . Level == AnalogyLogLevel . Unknown ? ( Color . FromArgb ( _rnd . Next ( 256 ) , _rnd . Next ( 256 ) , _rnd . Next ( 256 ) ) , Color . FromArgb ( _rnd . Next ( 256 ) , _rnd . Next ( 256 ) , _rnd . Next ( 256 ) ) ) : ( Color . Empty , Color . Empty ) ;
3535 public OnlineExampleDataProvider ( string prefix , Guid guid )
3636 {
37- prefixMessage = prefix ;
37+ _prefixMessage = prefix ;
3838 Id = guid ;
3939 OptionalTitle = $ "Analogy Example: Real time Data Provider { prefix } ";
40- SimulateOnlineMessages = new Timer ( 100 ) ;
40+ _simulateOnlineMessages = new Timer ( 100 ) ;
4141
4242 }
4343 public override async Task InitializeDataProviderAsync ( IAnalogyLogger logger )
4444 {
4545 await base . InitializeDataProviderAsync ( logger ) ;
4646
47- SimulateOnlineMessages . Elapsed += ( s , e ) =>
47+ _simulateOnlineMessages . Elapsed += ( s , e ) =>
4848 {
49- unchecked
49+
50+ AnalogyLogLevel randomLevel = ( AnalogyLogLevel ) _values . GetValue ( _random . Next ( _values . Length ) ) ! ;
51+ string randomProcess = _processes [ _random . Next ( _processes . Count ) ] ;
52+ AnalogyLogMessage m = new AnalogyLogMessage
5053 {
51- AnalogyLogLevel randomLevel = ( AnalogyLogLevel ) _values . GetValue ( _random . Next ( _values . Length ) ) ! ;
52- string randomProcess = processes [ _random . Next ( processes . Count ) ] ;
53- AnalogyLogMessage m = new AnalogyLogMessage
54- {
55- Text = $ "{ prefixMessage } : Generated message #{ messageCount ++ } " + string . Join ( Environment . NewLine , Enumerable . Range ( 0 , _random . Next ( 1 , 5 ) ) . Select ( i => $ "row { i } ") ) ,
56- Level = randomLevel ,
57- Class = AnalogyLogClass . General ,
58- Source = "Example" ,
59- User = Environment . UserName ,
60- Module = randomProcess ,
61- MachineName = Environment . MachineName ,
62- ThreadId = Thread . CurrentThread . ManagedThreadId ,
63- AdditionalInformation = new Dictionary < string , string > ( ) { { "Random Column" , _random . Next ( 0 , 10 ) . ToString ( ) } , { "Random Column 2" , _random . Next ( 0 , 10 ) . ToString ( ) } }
54+ Text = $ "{ _prefixMessage } : Generated message #{ _messageCount ++ } " + string . Join ( Environment . NewLine , Enumerable . Range ( 0 , _random . Next ( 1 , 5 ) ) . Select ( i => $ "row { i } ") ) ,
55+ Level = randomLevel ,
56+ Class = AnalogyLogClass . General ,
57+ Source = "Example" ,
58+ User = Environment . UserName ,
59+ Module = randomProcess ,
60+ MachineName = Environment . MachineName ,
61+ ThreadId = Thread . CurrentThread . ManagedThreadId ,
62+ AdditionalInformation = new Dictionary < string , string > { { "Random Column" , _random . Next ( 0 , 10 ) . ToString ( ) } , { "Random Column 2" , _random . Next ( 0 , 10 ) . ToString ( ) } }
63+
64+ } ;
6465
65- } ;
66+ MessageReady ( this , new AnalogyLogMessageArgs ( m , Environment . MachineName , "Example" , Id ) ) ;
6667
67- MessageReady ( this , new AnalogyLogMessageArgs ( m , Environment . MachineName , "Example" , Id ) ) ;
68- }
6968 } ;
7069 }
7170
7271 public override Task StartReceiving ( )
7372 {
74- SimulateOnlineMessages . Start ( ) ;
73+ _simulateOnlineMessages . Start ( ) ;
7574 return Task . CompletedTask ;
7675 }
7776
7877 public override Task StopReceiving ( )
7978 {
80- SimulateOnlineMessages ? . Stop ( ) ;
79+ _simulateOnlineMessages ? . Stop ( ) ;
8180 Disconnected ( this , new AnalogyDataSourceDisconnectedArgs ( "user disconnected" , Environment . MachineName , Id ) ) ;
8281 return Task . CompletedTask ;
8382 }
0 commit comments