Example #1
0
        private async Task UpdateDatastoreFromLocalCountersAsync(
            Dictionary <string, long> localCountersSnapshot,
            CancellationToken cancellationToken)
        {
            List <Entity> entities = new List <Entity>();
            var           now      = DateTime.UtcNow;

            foreach (var keyValue in _localCounters)
            {
                long count = keyValue.Value.Count;
                if (count != localCountersSnapshot
                    .GetValueOrDefault(keyValue.Key))
                {
                    localCountersSnapshot[keyValue.Key] = count;
                    var entity = new Entity()
                    {
                        Key         = _keyFactory.CreateKey($"{keyValue.Key}:{_shard}"),
                        [COUNT]     = count,
                        [TIMESTAMP] = now
                    };
                    entity[COUNT].ExcludeFromIndexes = true;
                    entities.Add(entity);
                }
            }
            if (entities.Count > 0)
            {
                await _datastore.UpsertAsync(entities, CallSettings
                                             .FromCancellationToken(cancellationToken));
            }
        }
Example #2
0
        public async Task AddFinishedProps(Guid gameId, string oddsJson)
        {
            try
            {
                string gameIdString = gameId.ToString();

                await AsyncRetryPolicy.ExecuteAsync(async() =>
                {
                    Entity entity = new Entity
                    {
                        Key       = _finishedOddsKeyFactory.CreateKey(gameIdString),
                        ["props"] = new Value
                        {
                            StringValue        = oddsJson,
                            ExcludeFromIndexes = true
                        },
                        ["comp_id"] = gameIdString
                    };

                    Key key = await DatastoreDb.UpsertAsync(entity);
                });
            }
            catch (Exception e)
            {
                Logger.Info(e);
            }
        }
Example #3
0
        public Task SetDumbExpiresAsync(DateTime when)
        {
            Entity entity = new Entity()
            {
                Key            = _key,
                [DUMB_EXPIRES] = when
            };

            lock (_cachedEntityLock)
            {
                _cachedEntity        = Task.FromResult(entity);
                _cachedEntityExpires = DateTime.Now.AddSeconds(10);
            }
            return(_datastore.UpsertAsync(entity));
        }
        public async Task <IdentityResult> UpdateAsync(U user,
                                                       CancellationToken cancellationToken)
        {
            _logger.LogDebug("UpdateAsync({0})", user.NormalizedEmail);
            // Was the NormalizedUserName modified?
            UserAddendum addendum = s_userAddendums.GetOrCreateValue(user);

            if (user.NormalizedUserName == addendum.NormalizedUserName)
            {
                // NormalizedUserName was not modified.  The common and efficient case.
                return(await Rpc.TranslateExceptionsAsync(() =>
                                                          _datastore.UpsertAsync(UserToEntity(user),
                                                                                 CallSettings.FromCancellationToken(cancellationToken))));
            }
            Entity entity      = UserToEntity(user);
            Entity indexEntity = new Entity()
            {
                Key        = _nnindexKeyFactory.CreateKey(user.NormalizedUserName),
                [USER_KEY] = entity.Key
            };
            var result = await InTransactionAsync(cancellationToken,
                                                  async (transaction, callSettings) =>
            {
                // NormalizedUserName was modified.  Have to update the
                // index too.
                if (!string.IsNullOrEmpty(addendum.NormalizedUserName))
                {
                    transaction.Delete(_nnindexKeyFactory
                                       .CreateKey(addendum.NormalizedUserName));
                }
                indexEntity[USER_KEY].ExcludeFromIndexes = true;
                transaction.Upsert(entity);
                transaction.Upsert(indexEntity);
                await transaction.CommitAsync(callSettings);
            });

            if (result.Succeeded)
            {
                addendum.NormalizedUserName = user.NormalizedUserName;
            }
            return(result);
        }
 public virtual Task UpsertAsync <TPoco>(TPoco poco, string kind) where TPoco : new()
 {
     return(datastoreDb.UpsertAsync(orm.PocoToEntity(poco, kind)));
 }
 public async Task <IdentityResult> UpdateAsync(R role, CancellationToken cancellationToken)
 {
     return(await Rpc.TranslateExceptionsAsync(() =>
                                               _datastore.UpsertAsync(RoleToEntity(role), CallSettings.FromCancellationToken(cancellationToken))));
 }