Inheritance: IActivityMonitorClient
Exemplo n.º 1
0
        public void parsing_dependent_token_and_start_and_create_messages_with_time_collision()
        {
            ActivityMonitor m = new ActivityMonitor(false);

            m.Output.CreateBridgeTo(TestHelper.ConsoleMonitor.Output.BridgeTarget);
            StupidStringClient cLaunch = m.Output.RegisterClient(new StupidStringClient());

            // Generates a token with time collision.
            int loopNeeded = 0;

            ActivityMonitor.DependentToken token;
            while ((token = m.DependentActivity().CreateTokenWithTopic("Test...")).CreationDate.Uniquifier == 0)
            {
                ++loopNeeded;
            }
            Assert.That(token.Topic, Is.EqualTo("Test..."));
            m.Trace().Send("Generating time collision required {0} loops.", loopNeeded);

            string launchMessage = cLaunch.Entries[loopNeeded].Text;
            {
                bool   launched;
                bool   launchWithTopic;
                string launchDependentTopic;
                Assert.That(ActivityMonitor.DependentToken.TryParseLaunchOrCreateMessage(launchMessage, out launched, out launchWithTopic, out launchDependentTopic));
                Assert.That(!launched, "We used CreateToken.");
                Assert.That(launchWithTopic);
                Assert.That(launchDependentTopic, Is.EqualTo("Test..."));
            }

            string tokenToString = token.ToString();

            {
                ActivityMonitor.DependentToken t2 = ActivityMonitor.DependentToken.Parse(tokenToString);
                Assert.That(t2.OriginatorId, Is.EqualTo(((IUniqueId)m).UniqueId));
                Assert.That(t2.CreationDate, Is.EqualTo(cLaunch.Entries[loopNeeded].LogTime));
                Assert.That(t2.Topic, Is.EqualTo("Test..."));
            }

            StupidStringClient.Entry[] logs = RunDependentActivity(token);
            {
                Assert.That(logs[0].Text, Is.EqualTo(ActivityMonitor.SetTopicPrefix + "Test..."));
                Guid          id;
                DateTimeStamp time;
                Assert.That(ActivityMonitor.DependentToken.TryParseStartMessage(logs[1].Text, out id, out time));
                Assert.That(id, Is.EqualTo(((IUniqueId)m).UniqueId));
                Assert.That(time, Is.EqualTo(cLaunch.Entries[loopNeeded].LogTime));
            }
        }
Exemplo n.º 2
0
        public void automatic_configuration_of_monitors_just_uses_ActivityMonitor_AutoConfiguration_delegate()
        {
            StupidStringClient c = new StupidStringClient();

            ActivityMonitor.AutoConfiguration = null;
            ActivityMonitor.AutoConfiguration += m => m.Output.RegisterClient( c );
            int i = 0;
            ActivityMonitor.AutoConfiguration += m => m.Trace().Send( "This monitors has been created at {0:O}, n°{1}", DateTime.UtcNow, ++i );

            ActivityMonitor monitor1 = new ActivityMonitor();
            ActivityMonitor monitor2 = new ActivityMonitor();

            Assert.That( c.ToString(), Does.Contain( "This monitors has been created at" ) );
            Assert.That( c.ToString(), Does.Contain( "n°1" ) );
            Assert.That( c.ToString(), Does.Contain( "n°2" ) );

            ActivityMonitor.AutoConfiguration = null;
        }
Exemplo n.º 3
0
        private static StupidStringClient.Entry[] RunDependentActivity(ActivityMonitor.DependentToken token)
        {
            string depMonitorTopic = null;

            StupidStringClient.Entry[] dependentLogs = null;
            var task = Task.Factory.StartNew(t =>
            {
                StupidStringClient cStarted = new StupidStringClient();
                using (var depMonitor = token.CreateDependentMonitor(mD => mD.Output.RegisterClient(cStarted)))
                {
                    depMonitorTopic = depMonitor.Topic;
                    depMonitor.Trace().Send("Hello!");
                }
                dependentLogs = cStarted.Entries.ToArray();
            }, token);

            task.Wait();
            Assert.That(depMonitorTopic, Is.EqualTo(token.Topic));
            return(dependentLogs);
        }
Exemplo n.º 4
0
        public void parsing_start_and_create_messages()
        {
            ActivityMonitor    m       = new ActivityMonitor(false);
            StupidStringClient cLaunch = m.Output.RegisterClient(new StupidStringClient());

            StupidStringClient.Entry[] dependentLogs = null;

            string dependentTopic = "A topic 'with' quotes '-\"..." + Environment.NewLine + " and multi-line";

            dependentLogs = LaunchAndRunDependentActivityWithTopic(m, dependentTopic);

            string launchMessage   = cLaunch.Entries[0].Text;
            string topicSetMessage = dependentLogs[0].Text;
            string startMessage    = dependentLogs[1].Text;

            Assert.That(topicSetMessage, Is.EqualTo(ActivityMonitor.SetTopicPrefix + dependentTopic));
            Assert.That(dependentLogs[2].Text, Is.EqualTo("Hello!"));

            Assert.That(launchMessage, Does.StartWith("Launching dependent activity"));
            bool   launched;
            bool   launchWithTopic;
            string launchDependentTopic;

            Assert.That(ActivityMonitor.DependentToken.TryParseLaunchOrCreateMessage(launchMessage, out launched, out launchWithTopic, out launchDependentTopic));
            Assert.That(launched);
            Assert.That(launchWithTopic);
            Assert.That(launchDependentTopic, Is.EqualTo(dependentTopic));

            Assert.That(startMessage, Does.StartWith("Starting dependent activity"));
            Guid          id;
            DateTimeStamp time;

            Assert.That(ActivityMonitor.DependentToken.TryParseStartMessage(startMessage, out id, out time));
            Assert.That(id, Is.EqualTo(((IUniqueId)m).UniqueId));
            Assert.That(time, Is.EqualTo(cLaunch.Entries[0].LogTime));
        }
Exemplo n.º 5
0
 private static StupidStringClient.Entry[] RunDependentActivity( ActivityMonitor.DependentToken token )
 {
     string depMonitorTopic = null;
     StupidStringClient.Entry[] dependentLogs = null;
     var task = Task.Factory.StartNew( t =>
     {
         StupidStringClient cStarted = new StupidStringClient();
         using( var depMonitor = token.CreateDependentMonitor( mD => mD.Output.RegisterClient( cStarted ) ) )
         {
             depMonitorTopic = depMonitor.Topic;
             depMonitor.Trace().Send( "Hello!" );
         }
         dependentLogs = cStarted.Entries.ToArray();
     }, token );
     task.Wait();
     Assert.That( depMonitorTopic, Is.EqualTo( token.Topic ) );
     return dependentLogs;
 }
Exemplo n.º 6
0
        public void DumpException()
        {
            IActivityMonitor l = new ActivityMonitor( applyAutoConfigurations: false );
            var wLogLovely = new StringBuilder();
            var rawLog = new StupidStringClient();
            l.Output.RegisterClient( rawLog );
            using( l.Output.CreateBridgeTo( TestHelper.ConsoleMonitor.Output.BridgeTarget ) )
            {
                var logLovely = new ActivityMonitorTextWriterClient( ( s ) => wLogLovely.Append( s ) );
                l.Output.RegisterClient( logLovely );

                l.Error().Send( new Exception( "EXERROR-1" ) );
                using( l.OpenFatal().Send( new Exception( "EXERROR-2" ), "EXERROR-TEXT2" ) )
                {
                    try
                    {
                        throw new Exception( "EXERROR-3" );
                    }
                    catch( Exception ex )
                    {
                        l.Trace().Send( ex, "EXERROR-TEXT3" );
                    }
                }
            }
            Assert.That( rawLog.ToString(), Does.Contain( "EXERROR-1" ) );
            Assert.That( rawLog.ToString(), Does.Contain( "EXERROR-2" ).And.Contain( "EXERROR-TEXT2" ) );
            Assert.That( rawLog.ToString(), Does.Contain( "EXERROR-3" ).And.Contain( "EXERROR-TEXT3" ) );

            string text = wLogLovely.ToString();
            Assert.That( text, Does.Contain( "EXERROR-1" ) );
            Assert.That( text, Does.Contain( "EXERROR-2" ).And.Contain( "EXERROR-TEXT2" ) );
            Assert.That( text, Does.Contain( "EXERROR-3" ).And.Contain( "EXERROR-TEXT3" ) );
            Assert.That( text, Does.Contain( "Stack:" ) );
        }