Exemple #1
0
        public async Task SaveUserData(Guid userId, IHasUserData item, UserItemData userData, UserDataSaveReason reason, CancellationToken cancellationToken)
        {
            if (userData == null)
            {
                throw new ArgumentNullException("userData");
            }
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (userId == Guid.Empty)
            {
                throw new ArgumentNullException("userId");
            }

            cancellationToken.ThrowIfCancellationRequested();

            var keys = item.GetUserDataKeys();

            foreach (var key in keys)
            {
                try
                {
                    await Repository.SaveUserData(userId, key, userData, cancellationToken).ConfigureAwait(false);

                    var newValue = userData;

                    lock (_userData)
                    {
                        _userData[GetCacheKey(userId, key)] = newValue;
                    }
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error saving user data", ex);

                    throw;
                }
            }

            EventHelper.FireEventIfNotNull(UserDataSaved, this, new UserDataSaveEventArgs
            {
                Keys = keys,
                UserData = userData,
                SaveReason = reason,
                UserId = userId,
                Item = item

            }, _logger);
        }
Exemple #2
0
        public async Task SaveUserData(Guid userId, IHasUserData item, UserItemData userData, UserDataSaveReason reason, CancellationToken cancellationToken)
        {
            if (userData == null)
            {
                throw new ArgumentNullException("userData");
            }
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (userId == Guid.Empty)
            {
                throw new ArgumentNullException("userId");
            }

            cancellationToken.ThrowIfCancellationRequested();

            var keys = item.GetUserDataKeys();

            foreach (var key in keys)
            {
                try
                {
                    await Repository.SaveUserData(userId, key, userData, cancellationToken).ConfigureAwait(false);

                    var newValue = userData;

                    lock (_userData)
                    {
                        _userData[GetCacheKey(userId, key)] = newValue;
                    }
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error saving user data", ex);

                    throw;
                }
            }

            EventHelper.FireEventIfNotNull(UserDataSaved, this, new UserDataSaveEventArgs
            {
                Keys       = keys,
                UserData   = userData,
                SaveReason = reason,
                UserId     = userId,
                Item       = item
            }, _logger);
        }
Exemple #3
0
        public async Task SaveUserData(Guid userId, IHasUserData item, UserItemData userData, UserDataSaveReason reason, CancellationToken cancellationToken)
        {
            if (userData == null)
            {
                throw new ArgumentNullException("userData");
            }
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (userId == Guid.Empty)
            {
                throw new ArgumentNullException("userId");
            }

            cancellationToken.ThrowIfCancellationRequested();

            var keys = item.GetUserDataKeys();

            foreach (var key in keys)
            {
                await Repository.SaveUserData(userId, key, userData, cancellationToken).ConfigureAwait(false);
            }

            var cacheKey = GetCacheKey(userId, item.Id);
            _userData.AddOrUpdate(cacheKey, userData, (k, v) => userData);

            EventHelper.FireEventIfNotNull(UserDataSaved, this, new UserDataSaveEventArgs
            {
                Keys = keys,
                UserData = userData,
                SaveReason = reason,
                UserId = userId,
                Item = item

            }, _logger);
        }
        public async Task SaveUserData(Guid userId, IHasUserData item, UserItemData userData, UserDataSaveReason reason, CancellationToken cancellationToken)
        {
            if (userData == null)
            {
                throw new ArgumentNullException("userData");
            }
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (userId == Guid.Empty)
            {
                throw new ArgumentNullException("userId");
            }

            cancellationToken.ThrowIfCancellationRequested();

            var keys = item.GetUserDataKeys();

            foreach (var key in keys)
            {
                await Repository.SaveUserData(userId, key, userData, cancellationToken).ConfigureAwait(false);
            }

            var cacheKey = GetCacheKey(userId, item.Id);

            _userData.AddOrUpdate(cacheKey, userData, (k, v) => userData);

            EventHelper.FireEventIfNotNull(UserDataSaved, this, new UserDataSaveEventArgs
            {
                Keys       = keys,
                UserData   = userData,
                SaveReason = reason,
                UserId     = userId,
                Item       = item
            }, _logger);
        }
Exemple #5
0
 public UserItemData GetUserData(Guid userId, IHasUserData item)
 {
     return GetUserData(userId, item.Id, item.GetUserDataKeys());
 }
Exemple #6
0
 public UserItemData GetUserData(Guid userId, IHasUserData item)
 {
     return(GetUserData(userId, item.Id, item.GetUserDataKeys()));
 }