Пример #1
0
        /// <summary>Starts this Agent instance.</summary>
        public void Start()
        {
            Log.StartSession(_agentConfiguration);
            foreach (var listener in _serviceProvider.GetServices <ILoupeDiagnosticListener>())
            {
                _diagnosticListener.Add(listener);
            }
            _diagnosticListener.Subscribe();

            foreach (var monitor in _serviceProvider.GetServices <ILoupeMonitor>())
            {
                Monitor.Subscribe(monitor);
            }

            foreach (var filter in _serviceProvider.GetServices <ILoupeFilter>())
            {
                Gibraltar.Monitor.Log.RegisterFilter(filter);
            }

            var principalResolver = _serviceProvider.GetService <IPrincipalResolver>();

            if (principalResolver != null)
            {
                Log.PrincipalResolver = principalResolver;
            }

            var userResolver = _serviceProvider.GetService <IApplicationUserProvider>();

            if (userResolver != null)
            {
                Log.ApplicationUserProvider = userResolver;
            }
        }
        public void ApplicationUserAssignJustOnce()
        {
            try
            {
                //the first message is done with wait for commit so we know we've written everything through the publisher before we connect up our event handler.
                Log.Write(LogMessageSeverity.Information, "Loupe", null, null, null,
                          LogWriteMode.WaitForCommit, null, "LogTests.ApplicationUser.Assign Just Once", "Flushing message queue prior to doing resolve once test",
                          "We should get no resolution as we shouldn't have the resolver bound yet.");

                var principal = new GenericPrincipal(new GenericIdentity(Guid.NewGuid().ToString()), null); //we want a unique, but consistent, principal.

                var justOnceProvider = new ResolveUserJustOnceProvider();
                Log.ApplicationUserProvider = justOnceProvider;

                Log.Write(LogMessageSeverity.Information, "Loupe", null, principal, null,
                          LogWriteMode.WaitForCommit, null, "LogTests.ApplicationUser.Assign Just Once",
                          "This message should be attributed to ApplicationUserAssignJustOnce",
                          "And we should get the resolution event following it.");
                Assert.AreEqual(1, justOnceProvider.ResolutionRequests, "We didn't get exactly one resolution after the first message");

                Log.Write(LogMessageSeverity.Information, "Loupe", null, principal, null,
                          LogWriteMode.WaitForCommit, null, "LogTests.ApplicationUser.Assign Just Once",
                          "This message should be attributed to ApplicationUserAssignJustOnce",
                          "And we should NOT get the resolution event following it.");
                Assert.AreEqual(1, justOnceProvider.ResolutionRequests, "We got an additional ResolveApplicationUser event after our initial attempt.");
            }
            finally
            {
                Log.ApplicationUserProvider = null;
            }
        }
        public void Can_Use_Lambda_For_Application_User_Provider()
        {
            try
            {
                //the first message is done with wait for commit so we know we've written everything through the publisher before we connect up our resolvers.
                Log.Write(LogMessageSeverity.Information, "Loupe", null, null, null,
                          LogWriteMode.WaitForCommit, null, "LogTests.ApplicationUser.Lambda Application User Provider",
                          "Flushing message queue prior to doing test",
                          "We should get no resolution as we shouldn't have the resolver bound yet.");

                Log.PrincipalResolver       = new RandomPrincipalResolver();
                Log.ApplicationUserProvider = new DelegateApplicationUserProvider((principal, lazy) =>
                {
                    var user     = lazy.Value;
                    user.Caption = "Can_Use_Lambda_For_Application_User_Provider";
                    return(true);
                });

                Log.Write(LogMessageSeverity.Information, "Loupe", null, null, null,
                          LogWriteMode.WaitForCommit, null, "LogTests.ApplicationUser.Lambda Application User Provider",
                          "This message should be attributed to user caption Can_Use_Lambda_For_Application_User_Provider",
                          "And we should get the resolution event following it.");
            }
            finally
            {
                Log.PrincipalResolver       = null;
                Log.ApplicationUserProvider = null;
            }
        }
        public void Specified_IPrincipal_Overrides_Resolved_IPrincipal()
        {
            try
            {
                //the first message is done with wait for commit so we know we've written everything through the publisher before we connect up our resolvers.
                Log.Write(LogMessageSeverity.Information, "Loupe", null, null, null,
                          LogWriteMode.WaitForCommit, null, "LogTests.ApplicationUser.Override IPrincipal",
                          "Flushing message queue prior to doing test",
                          "We should get no resolution as we shouldn't have the resolver bound yet.");

                //Test scenario: Have a principal resolver, but specify something *else* manually to the API.
                var principal =
                    new GenericPrincipal(
                        new GenericIdentity("Specified_IPrincipal_Overrides_Resolved_IPrincipal-" + Guid.NewGuid()),
                        null);

                Log.PrincipalResolver = new RandomPrincipalResolver();
                var userProvider = new CapturePrincipalUserProvider();
                Log.ApplicationUserProvider = userProvider;

                Log.Write(LogMessageSeverity.Information, "Loupe", null, principal, null,
                          LogWriteMode.WaitForCommit, null, "LogTests.ApplicationUser.Override IPrincipal",
                          "This message should be attributed to user caption Specified_IPrincipal_Overrides_Resolved_IPrincipal",
                          "And we should get the resolution event following it.");

                Assert.That(userProvider.LastPrincipal, Is.Not.Null);
                Assert.That(userProvider.LastPrincipal, Is.SameAs(principal), "The user principal was not the object we expected");
            }
            finally
            {
                Log.PrincipalResolver       = null;
                Log.ApplicationUserProvider = null;
            }
        }
        public void Can_Use_Lambda_For_Principal_Resolver()
        {
            try
            {
                //the first message is done with wait for commit so we know we've written everything through the publisher before we connect up our event handler.
                Log.Write(LogMessageSeverity.Information, "Loupe", null, null, null,
                          LogWriteMode.WaitForCommit, null, "LogTests.ApplicationUser.Lambda Principal Resolver", "Flushing message queue prior to doing resolve once test",
                          "We should get no resolution as we shouldn't have the resolver bound yet.");

                Log.PrincipalResolver = new DelegatePrincipalResolver(() => new GenericPrincipal(new GenericIdentity("Can_Use_Lambda_For_Principal_Resolver"), null));
                var justOnceProvider = new ResolveUserJustOnceProvider();
                Log.ApplicationUserProvider = justOnceProvider;

                Log.Write(LogMessageSeverity.Information, "Loupe", null, null, null,
                          LogWriteMode.WaitForCommit, null, "LogTests.ApplicationUser.Lambda Principal Resolver",
                          "This message should be attributed to user Can_Use_Lambda_For_Principal_Resolver",
                          "And we should get the resolution event following it.");
                Assert.AreEqual(1, justOnceProvider.ResolutionRequests, "We didn't get exactly one resolution after the first message");

                Log.Write(LogMessageSeverity.Information, "Loupe", null, null, null,
                          LogWriteMode.WaitForCommit, null, "LogTests.ApplicationUser.Lambda Principal Resolver",
                          "This message should be attributed to user Can_Use_Lambda_For_Principal_Resolver",
                          "And we should NOT get the resolution event following it.");
                Assert.AreEqual(1, justOnceProvider.ResolutionRequests, "We got an additional ResolveApplicationUser event after our initial attempt.");
            }
            finally
            {
                Log.PrincipalResolver       = null;
                Log.ApplicationUserProvider = null;
            }
        }
        public void Log_While_Resolving_Application_User_Does_Not_Deadlock()
        {
            try
            {
                //the first message is done with wait for commit so we know we've written everything through the publisher before we connect up our event handler.
                Log.Write(LogMessageSeverity.Information, "Loupe", null, null, null,
                          LogWriteMode.WaitForCommit, null, "LogTests.ApplicationUser.Logging Doesn't Deadlock",
                          "Flushing message queue prior to doing deadlock test",
                          null);

                var userProvider = new LoggingUserResolver();
                Log.PrincipalResolver       = new RandomPrincipalResolver();
                Log.ApplicationUserProvider = userProvider;

                Log.Write(LogMessageSeverity.Information, "Loupe", null, null, null,
                          LogWriteMode.WaitForCommit, null, "LogTests.ApplicationUser.Logging Doesn't Deadlock",
                          "This message should be attributed to ApplicationUserAssignJustOnce",
                          "And we should get the resolution event following it.");
            }
            finally
            {
                Log.PrincipalResolver       = null;
                Log.ApplicationUserProvider = null;
            }
        }
            public bool TryResolveCurrentPrincipal(out IPrincipal principal)
            {
                principal = new GenericPrincipal(new GenericIdentity(DateTime.UtcNow.ToLongTimeString()), null);
                Interlocked.Increment(ref m_ResolutionRequests);

                Log.Write(LogMessageSeverity.Information, "Loupe", null, null, null,
                          LogWriteMode.WaitForCommit, null, "LogTests.ApplicationUser.Logging Principal",
                          "This message was logged during an IPrincipal Resolve method",
                          "It should not have a user principal and should not prompt resolution of a user principal.");

                return(true);
            }
            public bool TryGetApplicationUser(IPrincipal principal, Lazy <ApplicationUser> applicationUser)
            {
                Interlocked.Increment(ref m_ResolutionRequests);

                Log.Write(LogMessageSeverity.Information, "Loupe", null, null, null,
                          LogWriteMode.WaitForCommit, null, "LogTests.ApplicationUser.Logging User",
                          "This message was logged during an IApplicationUserProvider Resolve method",
                          "It should not have an application user.");

                var user = applicationUser.Value;

                return(true);
            }
 public void ApplicationUserAssignForCurrentPrincipal()
 {
     Log.PrincipalResolver       = new DefaultPrincipalResolver();
     Log.ApplicationUserProvider = new ResolveUserForCurrentPrincipal();
     try
     {
         Log.Write(LogMessageSeverity.Information, "Loupe", null, null, null,
                   LogWriteMode.WaitForCommit, null, "LogTests.ApplicationUser.Assign For Current Principal", "This message should be attributed to the current user",
                   "And we should get the resolution event following it.");
     }
     finally
     {
         Log.PrincipalResolver       = null;
         Log.ApplicationUserProvider = null;
     }
 }
Пример #10
0
 /// <summary>Stops this Agent instance.</summary>
 /// <param name="status">The session status.</param>
 /// <param name="reason">The reason.</param>
 public void End(SessionStatus status, string reason)
 {
     Log.EndSession(status, reason);
 }