Esempio n. 1
0
        User DecorateUser(User user)
        {
            IUserBuilder buildUser = null;

            if (UserMetadata.DeviceName != null)
            {
                if (buildUser is null)
                {
                    buildUser = User.Builder(user);
                }
                buildUser.Custom("device", UserMetadata.DeviceName);
            }
            if (UserMetadata.OSName != null)
            {
                if (buildUser is null)
                {
                    buildUser = User.Builder(user);
                }
                buildUser.Custom("os", UserMetadata.OSName);
            }
            // If you pass in a user with a null or blank key, one will be assigned to them.
            if (String.IsNullOrEmpty(user.Key))
            {
                if (buildUser is null)
                {
                    buildUser = User.Builder(user);
                }
                buildUser.Key(deviceInfo.UniqueDeviceId()).Anonymous(true);
            }
            return(buildUser is null ? user : buildUser.Build());
        }
Esempio n. 2
0
        User UserWithUniqueKey(User user = null)
        {
            string uniqueId = deviceInfo.UniqueDeviceId();

            if (user != null)
            {
                var updatedUser = new User(user)
                {
                    Key       = uniqueId,
                    Anonymous = true
                };

                return(updatedUser);
            }

            return(new User(uniqueId));
        }
 private string GetOrCreateAnonUserKey()
 {
     lock (_anonUserKeyLock)
     {
         if (_cachedAnonUserKey != null)
         {
             return(_cachedAnonUserKey);
         }
         var deviceId = _deviceInfo.UniqueDeviceId();
         if (deviceId is null)
         {
             deviceId = _store?.GetAnonymousUserKey();
             if (deviceId is null)
             {
                 deviceId = Guid.NewGuid().ToString();
                 _store?.SetAnonymousUserKey(deviceId);
             }
         }
         _cachedAnonUserKey = deviceId;
         return(deviceId);
     }
 }