internal void RegisterApplicationUserProvider(IApplicationUserProvider resolver) { lock (m_ConfigLock) { m_ApplicationUserProvider = resolver; } }
private void ResolveApplicationUser(IApplicationUserProvider resolver, IUserPacket packet) { var userName = packet.Principal?.Identity?.Name; //if we don't have a user name at all then there's nothing to do if (string.IsNullOrEmpty(userName)) { return; } if (m_ApplicationUsers.TryFindUserName(userName, out var applicationUser) == false) { //prevent infinite recursion if (t_ThreadMustNotResolveApplicationUser) { return; } //since we have a miss we want to give our resolver a shot.. try { t_ThreadMustNotResolveApplicationUser = true; //we use lazy initialization to avoid the expense of stamping, etc. if they //aren't going to use it. Even better would be to lazy this object too. var lazyApplicationUser = new Lazy <ApplicationUser>(delegate { var userPacket = new ApplicationUserPacket { FullyQualifiedUserName = userName }; StampPacket(userPacket, DateTimeOffset.Now); return(new ApplicationUser(userPacket)); }, true); if (resolver.TryGetApplicationUser(packet.Principal, lazyApplicationUser) && lazyApplicationUser.IsValueCreated) { //cache this so we don't keep going after it. applicationUser = m_ApplicationUsers.TrySetValue(lazyApplicationUser.Value); } } catch (Exception ex) { //we can't log this because that would create an infinite loop (ignoring our protection for same) GC.KeepAlive(ex); } finally { t_ThreadMustNotResolveApplicationUser = false; } } if (applicationUser != null) { packet.UserPacket = applicationUser.Packet; } }
/// <summary> /// Create a new publisher /// </summary> /// <remarks>The publisher is a very central class; generally there should be only one per process. /// More specifically, there should be a one to one relationship between publisher, packet cache, and /// messengers to ensure integrity of the message output.</remarks> internal Publisher(string sessionName, AgentConfiguration configuration, SessionSummary sessionSummary, IPrincipalResolver principalResolver, IApplicationUserProvider userProvider) { if (string.IsNullOrEmpty(sessionName)) { throw new ArgumentNullException(nameof(sessionName)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if (sessionSummary == null) { throw new ArgumentNullException(nameof(sessionSummary)); } //store off all our input m_SessionName = sessionName; m_SessionSummary = sessionSummary; m_Configuration = configuration; var serverConfig = Log.Configuration.Server; if (serverConfig.AutoSendOnError && serverConfig.AutoSendSessions && serverConfig.Enabled) { m_AutoSendOnError = true; } //create our queue, cache, and messenger objects m_MessageQueue = new Queue <PacketEnvelope>(50); //a more or less arbitrary initial queue size. m_MessageOverflowQueue = new Queue <PacketEnvelope>(50); //a more or less arbitrary initial queue size. m_CachedTypes = new PacketDefinitionList(); m_PacketCache = new PacketCache(); m_Messengers = new List <IMessenger>(); m_Filters = new List <ILoupeFilter>(); m_MessageQueueMaxLength = Math.Max(configuration.Publisher.MaxQueueLength, 1); //make sure there's no way to get it below 1. m_PrincipalResolver = principalResolver; m_ApplicationUserProvider = userProvider; //create the thread we use for dispatching messages CreateMessageDispatchThread(); }