예제 #1
0
        public async Task <TEntity[]> GetByIdsAsync(params TKey[] ids)
        {
            var keys     = ids.Select(BuildKey);
            var entities = await _db.LookupAsync(keys);

            return(entities.Where(x => x != null).Select(BuildDalEntity).ToArray());
        }
예제 #2
0
        private async Task <Entity> GetGameState(GameState item)
        {
            var key    = _keyFactory.CreateKey(Convert.ToInt64(item.PlatformKey));
            var result = await _db.LookupAsync(key);

            return(result);
        }
        public async Task <TEntity> FindAsync(TKey id)
        {
            var key    = BuildKey(id);
            var entity = await _database.LookupAsync(key);

            return(entity != null?BuildDalEntity(entity) : null);
        }
        protected async Task <Entity> GetRootEntity(string persistenceId)
        {
            var rootEntityKey = RootKey(persistenceId);
            var entity        = await _db.LookupAsync(rootEntityKey).ConfigureAwait(false);

            return(entity);
        }
예제 #5
0
        /// <summary>
        /// Get by key
        /// </summary>
        /// <param name="key">The key to look up</param>
        /// <typeparam name="TPoco">The type of class you want to get back</typeparam>
        /// <returns>A hydrated instance of <typeparamref name="TPoco"/> or <c>null</c></returns>
        public virtual async Task <TPoco> GetByKeyOrDefaultAsync <TPoco>(Key key) where TPoco : new()
        {
            var entity = await datastoreDb.LookupAsync(key);

            if (entity != null)
            {
                return(orm.EntityToPoco <TPoco>(entity));
            }

            return(default(TPoco));
        }
예제 #6
0
 private Task <Entity> LookupEntityAsync()
 {
     lock (_cachedEntityLock)
     {
         var now = DateTime.Now;
         if (now > _cachedEntityExpires)
         {
             _cachedEntityExpires = now.AddSeconds(10);
             _cachedEntity        = _datastore.LookupAsync(_key);
         }
         return(_cachedEntity);
     }
 }
예제 #7
0
        public async Task <Fighter> GetFighterByIdAsync(string id)
        {
            var entity = await _db.LookupAsync(_keyFactory.CreateKey(id));

            if (entity == null)
            {
                return(null);
            }

            var fighter = new Fighter
            {
                Id    = id,
                Name  = entity.Properties["name"].StringValue,
                Votes = (int)entity.Properties["vote"].IntegerValue
            };

            var image = await _storage.GetObjectAsync(_bucketName, $"{id}");

            fighter.Image = image.MediaLink;

            return(fighter);
        }
        public async Task <Customer> GetAsync(long id)
        {
            DatastoreDb db = _datastoreManager.GetDatastore();

            var key    = db.CreateKeyFactory(EntityKind).CreateKey(id);
            var entity = await db.LookupAsync(key);

            if (null != entity)
            {
                var customer = MapEntityToCustomer(entity);
                customer.Id = id;
                return(customer);
            }
            return(null);
        }
예제 #9
0
        public async Task LookupAsync()
        {
            string projectId   = _fixture.ProjectId;
            string namespaceId = _fixture.NamespaceId;

            // Snippet: Lookup(*)
            DatastoreDb db         = DatastoreDb.Create(projectId, namespaceId);
            KeyFactory  keyFactory = db.CreateKeyFactory("book");
            Key         key1       = keyFactory.CreateKey("pride_and_prejudice");
            Key         key2       = keyFactory.CreateKey("not_present");

            IReadOnlyList <Entity> entities = await db.LookupAsync(key1, key2);

            Console.WriteLine(entities[0]); // Pride and Prejudice entity
            Console.WriteLine(entities[1]); // Nothing (value is null reference)
            // End snippet

            Entity entity = entities[0];

            Assert.Equal("Jane Austen", (string)entity["author"]);
            Assert.Equal("Pride and Prejudice", (string)entity["title"]);
            Assert.Null(entities[1]);
        }
 public async Task <U> FindByIdAsync(string userId, CancellationToken cancellationToken)
 {
     _logger.LogDebug("FindByIdAsync({0})", userId);
     return(EntityToUser(await _datastore.LookupAsync(KeyFromUserId(userId),
                                                      callSettings: CallSettings.FromCancellationToken(cancellationToken))));
 }
 public async Task <R> FindByIdAsync(string roleId, CancellationToken cancellationToken)
 {
     return(EntityToRole(await _datastore.LookupAsync(KeyFromRoleId(roleId),
                                                      callSettings: CallSettings.FromCancellationToken(cancellationToken))));
 }
예제 #12
0
        public async Task <Spot> Read(long id)
        {
            var result = await _db.LookupAsync(id.ToSpotKey());

            return(result.ToSpot());
        }