Exemple #1
0
        private async Task <UserAuthentication> UserFromDbByEmail(string email)
        {
            var result = await _dynamoDbContext
                         .QueryAsync <UserAuthentication>(email, _defaultOperationConfig)
                         .GetRemainingAsync();

            return(result.FirstOrDefault());
        }
Exemple #2
0
        public Deck Get(string id, string dataType)
        {
            var result = _dbContext.QueryAsync <Deck>(id, QueryOperator.Equal, new List <object>()
            {
                id, dataType
            });

            return(result.GetRemainingAsync().Result.DefaultIfEmpty(null).First());
        }
        public async Task <List <Location> > ListLocation(string pk)
        {
            string[] filter = { "Location" };
            var      items  = await _context.QueryAsync <DaBeerStorageTable>(pk, QueryOperator.BeginsWith, filter).GetRemainingAsync();

            var locations = DaBeerStorageTable.MapToLocations(items);

            return(locations);
        }
        public async Task <IEnumerable <MovieDb> > GetUsersRankedMoviesByMovieTitle(int userId, string movieName)
        {
            var queryConfig = new DynamoDBOperationConfig {
                QueryFilter = new List <ScanCondition>
                {
                    new ScanCondition("MovieName", ScanOperator.BeginsWith, movieName)
                }
            };

            return(await _context.QueryAsync <MovieDb>(userId, queryConfig).GetRemainingAsync());
        }
        public async Task <List <MovieResponse> > GetUsersRankedMoviesByMovieTitle(int userId, string movieName, CancellationToken cancellationToken)
        {
            var config = new DynamoDBOperationConfig
            {
                QueryFilter = new List <ScanCondition>
                {
                    new ScanCondition(propertyName: PropertyName, op: ScanOperator.Contains, movieName),
                    new ScanCondition(PropertyName, ScanOperator.BeginsWith, movieName)
                },
                ConditionalOperator = ConditionalOperatorValues.Or
            };

            return(_mapper.ToMovieContract(await _dynamoDbContext.QueryAsync <MovieDb>(userId, config).GetRemainingAsync(cancellationToken)).ToList());
        }
Exemple #6
0
        public async Task <List <PlayerDTO> > RequestPlayerList(string gameId)
        {
            var search  = _context.QueryAsync <PlayerDTO>(gameId);
            var results = await search.GetRemainingAsync();

            return(results);
        }
        public async Task <List <Registration> > GetRegistrationsAsync(Guid eventId)
        {
            var regs = await GetAllAsync(
                _Context.QueryAsync <RegistrationDto>(eventId)).ConfigureAwait(false);

            return(regs.Select(GetRegistrationFromDto).ToList());
        }
        public IEnumerable <CabUser> ListCabUsers()
        {
            var userList = new List <CabUser>();

            try
            {
                _ddboc.IndexName = "IsActive_IDX";

                var results = _dbContext.QueryAsync <CabUser>(true, _ddboc);

                do
                {
                    var set = results.GetNextSetAsync().Result;

                    if (set != null || set.Any())
                    {
                        userList.AddRange(set);
                    }
                } while (!results.IsDone);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(userList);
        }
Exemple #9
0
        /// <summary>
        /// Queries for replies posted within a specific time period.
        /// </summary>
        /// <param name="context">The DynamoDB context used to perform the query.</param>
        /// <param name="forumName">The name of the ofrum we're interested in.</param>
        /// <param name="threadSubject">Information about the subject we are
        /// interested in.</param>
        public static async Task FindRepliesPostedWithinTimePeriod(
            IDynamoDBContext context,
            string forumName,
            string threadSubject)
        {
            string forumId = forumName + "#" + threadSubject;

            Console.WriteLine("\nReplies posted within time period:");

            DateTime startDate = DateTime.UtcNow - TimeSpan.FromDays(30);
            DateTime endDate   = DateTime.UtcNow - TimeSpan.FromDays(1);

            List <object> times = new List <object>();

            times.Add(startDate);
            times.Add(endDate);

            List <ScanCondition> scs = new List <ScanCondition>();
            var sc = new ScanCondition("LastPostedBy", ScanOperator.Between, times.ToArray());

            scs.Add(sc);

            var cfg = new DynamoDBOperationConfig
            {
                QueryFilter = scs
            };

            AsyncSearch <Reply> response         = context.QueryAsync <Reply>(forumId, cfg);
            IEnumerable <Reply> repliesInAPeriod = await response.GetRemainingAsync();

            foreach (Reply r in repliesInAPeriod)
            {
                Console.WriteLine("{r.Id}\t{r.PostedBy}\t{r.Message}\t{r.ReplyDateTime}");
            }
        }
Exemple #10
0
        /// <summary>
        /// Queries a DynamoDB table to find replies posted within the last 15 days.
        /// </summary>
        /// <param name="context">The DynamoDB context used to perform the query.</param>
        /// <param name="forumName">The name of the forum we're interested in.</param>
        /// <param name="threadSubject">The thread object containing the query parameters.</param>
        public static async Task FindRepliesInLast15Days(
            IDynamoDBContext context,
            string forumName,
            string threadSubject)
        {
            string   replyId         = $"{forumName} #{threadSubject}";
            DateTime twoWeeksAgoDate = DateTime.UtcNow - TimeSpan.FromDays(15);

            List <object> times = new List <object>();

            times.Add(twoWeeksAgoDate);

            List <ScanCondition> scs = new List <ScanCondition>();
            var sc = new ScanCondition("LastPostedBy", ScanOperator.GreaterThan, times.ToArray());

            scs.Add(sc);

            var cfg = new DynamoDBOperationConfig
            {
                QueryFilter = scs,
            };

            AsyncSearch <Reply> response      = context.QueryAsync <Reply>(replyId, cfg);
            IEnumerable <Reply> latestReplies = await response.GetRemainingAsync();

            Console.WriteLine("\nReplies in last 15 days:");

            foreach (Reply r in latestReplies)
            {
                Console.WriteLine($"{r.Id}\t{r.PostedBy}\t{r.Message}\t{r.ReplyDateTime}");
            }
        }
        public async Task <List <ContactDetails> > GetContactDetailsByTargetId(ContactQueryParameter query)
        {
            _logger.LogDebug($"Calling IDynamoDBContext.QueryAsync for targetId {query.TargetId.Value}");

            List <ContactDetailsEntity> contactDetailsEntities = new List <ContactDetailsEntity>();
            DynamoDBOperationConfig     dbOperationConfig      = null;

            if (!query.IncludeHistoric)
            {
                List <ScanCondition> scanConditions = new List <ScanCondition>
                {
                    new ScanCondition(nameof(ContactDetailsEntity.IsActive), ScanOperator.Equal, true)
                };
                dbOperationConfig = new DynamoDBOperationConfig()
                {
                    QueryFilter = scanConditions
                };
            }

            var queryResult = _dynamoDbContext.QueryAsync <ContactDetailsEntity>(query.TargetId.Value, dbOperationConfig);

            while (!queryResult.IsDone)
            {
                contactDetailsEntities.AddRange(await queryResult.GetNextSetAsync().ConfigureAwait(false));
            }

            return(contactDetailsEntities.ToDomain());
        }
Exemple #12
0
        public async Task <ActionResult <List <Work> > > Get()
        {
            var response = _dynamoDbContext.QueryAsync <Work>("1");

            //var response = _dynamoDbContext.ScanAsync<Work>(
            //    new[] { new ScanCondition("ConsumerId", ScanOperator.Equal, "1") });

            return(await response.GetRemainingAsync());
        }
        public async Task <IEnumerable <RoomData> > GetRoomDataByIdAndUnixDateAsync(string roomId, double fromUnixDateTime, double toUnixDateTime)
        {
            var latestReplies =
                await _dynamoContext.QueryAsync <RoomData>(roomId,
                                                           QueryOperator.Between,
                                                           new object[] { fromUnixDateTime, toUnixDateTime }
                                                           ).GetRemainingAsync();

            return(latestReplies);
        }
        protected async Task <bool> CheckMovieByMovieIdAsync(Guid movieId, CancellationToken token = default)
        {
            DynamoDBOperationConfig operationConfig = new DynamoDBOperationConfig
            {
                IndexName = Constants.MoiveTableMovieIdGsi,
            };

            List <MovieEntity> result = await DynamoDbContext.QueryAsync <MovieEntity>(movieId, operationConfig)
                                        .GetRemainingAsync(token);

            return(result.Any(b => b.MovieId == movieId));
        }
        public async Task AddConnectionToGroupAsync(string connectionId, string groupName, CancellationToken cancellationToken = default(CancellationToken))
        {
            var connection = (await _context.QueryAsync <SocketConnection>(connectionId).GetRemainingAsync()).SingleOrDefault();

            if (connection == null)
            {
                throw new NullReferenceException($"Could not add connectionId: {connectionId} to group: {groupName}. Socket Connection not found");
            }

            if (connection.GroupIds == null)
            {
                connection.GroupIds = new List <string>();
            }

            if (!connection.GroupIds.Contains(groupName))
            {
                connection.GroupIds.Add(groupName);
                await _context.SaveAsync(connection, cancellationToken);
            }

            return;
        }
Exemple #16
0
        async Task <IEnumerable <Family> > IDataRepository.GetFamilies(string churchId)
        {
            var query = _ddbContext.QueryAsync <Family>(churchId);

            var families = await query.GetNextSetAsync();

            while (!query.IsDone)
            {
                var rem = await query.GetRemainingAsync();

                families.AddRange(rem);
            }
            return(families);
        }
        private static async Task <List <V2EventStoreModel> > GetEventsAsync(this IDynamoDBContext context, Guid correlationId, DynamoDbEventStoreOptions options)
        {
            var events = new List <V2EventStoreModel>();
            var query  = context.QueryAsync <V2EventStoreModel>(correlationId.ToString(), new DynamoDBOperationConfig {
                OverrideTableName = options.StoreName
            });

            do
            {
                events.AddRange(await query.GetNextSetAsync());
            }while(query.IsDone is false);

            return(events);
        }
        public async Task <IReadOnlyCollection <OpenLibraryVersion> > FindArchiveEntries(
            DateTime searchStart,
            DateTime searchEnd,
            OpenLibraryArchiveType archiveType,
            CancellationToken ct)
        {
            if (searchEnd <= searchStart)
            {
                throw new ArgumentException($"Search start ({searchStart:O}) must come before search end ({searchEnd:O})");
            }

            var range   = new object[] { searchStart, searchEnd };
            var query   = _pocoClient.QueryAsync <OpenLibraryVersion>(archiveType.GetKey(), QueryOperator.Between, range);
            var results = await query.GetNextSetAsync(ct);

            return(results);
        }
        public string Retrieve(string userId, string firstName)
        {
            try
            {
                using (IDynamoDBContext context = Factory.DynamoDBContext)
                {
                    WeighInUser user;
                    if (string.IsNullOrEmpty(firstName))
                    {
                        List <WeighInUser> users = context.QueryAsync <WeighInUser>(userId).GetRemainingAsync().Result.ToList();
                        if (!users.Any())
                        {
                            user = null;
                        }
                        else
                        {
                            user = users.OrderByDescending(W => W.LastUseDateTime).FirstOrDefault();
                        }
                    }
                    else
                    {
                        user = context.LoadAsync <WeighInUser>(userId, firstName).Result;
                    }

                    if (user == null)
                    {
                        user = new WeighInUser()
                        {
                            UserId    = userId,
                            FirstName = firstName
                        };
                    }
                    return(JsonConvert.SerializeObject(user));
                }
            }
            catch (Exception ex)
            {
                Factory.Logger.Log($"Error getting WeighInUser with userId=\"{userId}\" and firstName=\"{firstName}\"");
                Factory.Logger.Log(ex.Message);
                Factory.Logger.Log(ex.StackTrace);
                throw new WeighInException(ex.Message);
            }
        }
Exemple #20
0
        public APIDataUserFlow GetAPIDataByNameAndEnvironmentAsync(string apiName, string environment)
        {
            try
            {
                var queryResult = _dynamoDbContext.QueryAsync <APIDataUserFlowDbEntity>(apiName, QueryOperator.Equal, new object[] { environment });

                var results = queryResult.GetRemainingAsync().Result;

                if (results.Count == 0)
                {
                    LambdaLogger.Log($"API with name {apiName} for environment {environment} does not exist in DynamoDB");
                    throw new APIEntryNotFoundException();
                }

                return(results[0]?.ToDomain());
            }
            catch (Exception ex)
            {
                LambdaLogger.Log($"An error occurred retrieving data from DynamoDb while querying for {apiName} in {environment} environment. Message: {ex.Message}");
                throw;
            }
        }
        public async Task <List <ContactDetails> > GetContactDetailsByTargetId(ContactQueryParameter query)
        {
            _logger.LogDebug($"Calling IDynamoDBContext.QueryAsync for targetId {query.TargetId.Value}");

            List <ContactDetailsEntity> contactDetailsEntities = new List <ContactDetailsEntity>();
            DynamoDBOperationConfig     dbOperationConfig      = null;

            if (!query.IncludeHistoric)
            {
                dbOperationConfig = CreateConfigForOnlyActiveContactDetails();
            }

            var search = _dynamoDbContext.QueryAsync <ContactDetailsEntity>(query.TargetId.Value, dbOperationConfig);

            do
            {
                var newResults = await search.GetNextSetAsync().ConfigureAwait(false);

                contactDetailsEntities.AddRange(newResults);
            } while (!search.IsDone);

            return(contactDetailsEntities.ToDomain());
        }
        /// <inheritdoc />.
        public async Task <ICollection <TEntity> > QueryAsync(TKey key, DynamoDBOperationConfig config)
        {
            var query = _context.QueryAsync <TEntity>(key, config);

            return(await query.GetRemainingAsync());
        }
Exemple #23
0
        protected void LoadProgress(string userId, string firstName, ProgressBase progress)
        {
            try
            {
                using (IDynamoDBContext context = Factory.DynamoDBContext)
                {
                    Factory.Logger.Log("Loading User");

                    progress.User = context.LoadAsync <WeighInUser>(userId, firstName).Result;

                    if (progress.User == null)
                    {
                        Factory.Logger.Log("User not found");
                        throw new WeighInException($"User \"{userId},{firstName}\" not found");
                    }

                    Factory.Logger.Log("User loaded");

                    DateTime             week1Start = DateTime.Today.AddDays(-6);
                    DateTime             week1End   = DateTime.Today;
                    IEnumerable <object> week1      = (new List <object>()
                    {
                        week1Start, week1End
                    });

                    DateTime             week2Start = week1Start.AddDays(-7);
                    DateTime             week2End   = week1End.AddDays(-7);
                    IEnumerable <object> week2      = (new List <object>()
                    {
                        week2Start, week2End
                    });

                    DateTime             week3Start = week2Start.AddDays(-7);
                    DateTime             week3End   = week2End.AddDays(-7);
                    IEnumerable <object> week3      = (new List <object>()
                    {
                        week3Start, week3End
                    });

                    DateTime             week4Start = week3Start.AddDays(-7);
                    DateTime             week4End   = week3End.AddDays(-7);
                    IEnumerable <object> week4      = (new List <object>()
                    {
                        week4Start, week4End
                    });

                    Factory.Logger.Log("Loading Weights Week 1");

                    progress.WeightsLastWeek = context.QueryAsync <WeighInWeight>(progress.User.UserKey, QueryOperator.Between, week1).GetRemainingAsync().Result.Select(W => W.Weight).ToList();

                    Factory.Logger.Log("Loading Weights Week 2");

                    progress.Weights2WeeksAgo = context.QueryAsync <WeighInWeight>(progress.User.UserKey, QueryOperator.Between, week2).GetRemainingAsync().Result.Select(W => W.Weight).ToList();

                    Factory.Logger.Log("Loading Weights Week 3");

                    progress.Weights3WeeksAgo = context.QueryAsync <WeighInWeight>(progress.User.UserKey, QueryOperator.Between, week3).GetRemainingAsync().Result.Select(W => W.Weight).ToList();

                    Factory.Logger.Log("Loading Weights Week 4");

                    progress.Weights4WeeksAgo = context.QueryAsync <WeighInWeight>(progress.User.UserKey, QueryOperator.Between, week4).GetRemainingAsync().Result.Select(W => W.Weight).ToList();

                    Factory.Logger.Log("4 weeks loaded");
                }
            }
            catch (Exception ex)
            {
                Factory.Logger.Log($"Error getting Progress with userId=\"{userId}\" and firstName=\"{firstName}\"");
                Factory.Logger.Log(ex.Message);
                Factory.Logger.Log(ex.StackTrace);
                throw new WeighInException(ex.Message);
            }
        }
            public async Task <T[]> All(object hashKey)
            {
                var search = Db.QueryAsync <T>(hashKey, Config);

                return((await search.GetRemainingAsync())?.ToArray() ?? new T[0]);
            }