Exemplo n.º 1
0
 internal ApplicationUser(string userName, DateTimeOffset timestamp, long sequence)
 {
     m_Packet = new ApplicationUserPacket
     {
         Timestamp = timestamp,
         Sequence  = sequence,
         FullyQualifiedUserName = userName
     };
 }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
 internal ApplicationUser(ApplicationUserPacket packet)
 {
     m_Packet = packet;
 }