Exemple #1
0
        public static ScoreDetail Create(DynamoDbScore score, Dictionary <string, string> hashSet)
        {
            if (score.Type != DynamoDbScoreTypes.Main)
            {
                throw new ArgumentException(nameof(score));
            }

            var data = ScoreData.Create(score.Data);

            return(new ScoreDetail()
            {
                CreateAt = ScoreDatabaseUtils.ConvertFromUnixTimeMilli(score.CreateAt),
                UpdateAt = ScoreDatabaseUtils.ConvertFromUnixTimeMilli(score.UpdateAt),
                DataHash = score.DataHash,
                Data = data,
                Access = ScoreDatabaseUtils.ConvertToScoreAccess(score.Access),
                HashSet = hashSet.ToDictionary(x => x.Key, x => x.Value),
            });
        }
Exemple #2
0
            static async Task <ScoreSnapshotSummary[]> GetAsync(IAmazonDynamoDB client, string tableName, Guid ownerId, Guid scoreId)
            {
                var partitionKey = ScoreDatabaseUtils.ConvertToPartitionKey(ownerId);
                var score        = ScoreDatabaseUtils.ConvertToBase64(scoreId);

                var request = new QueryRequest()
                {
                    TableName = tableName,
                    ExpressionAttributeNames = new Dictionary <string, string>()
                    {
                        ["#owner"]        = DynamoDbScorePropertyNames.PartitionKey,
                        ["#score"]        = DynamoDbScorePropertyNames.SortKey,
                        ["#snapshotName"] = DynamoDbScorePropertyNames.SnapshotName,
                        ["#createAt"]     = DynamoDbScorePropertyNames.CreateAt,
                    },
                    ExpressionAttributeValues = new Dictionary <string, AttributeValue>()
                    {
                        [":owner"]      = new AttributeValue(partitionKey),
                        [":snapPrefix"] = new AttributeValue(ScoreDatabaseConstant.ScoreIdSnapPrefix + score),
                    },
                    KeyConditionExpression = "#owner = :owner and begins_with(#score, :snapPrefix)",
                    ProjectionExpression   = "#score, #snapshotName, #createAt",
                };

                try
                {
                    var response = await client.QueryAsync(request);

                    var subStartIndex = (ScoreDatabaseConstant.ScoreIdSnapPrefix + score).Length;

                    return(response.Items
                           .Select(x => (
                                       score: x[DynamoDbScorePropertyNames.SortKey].S,
                                       name: x[DynamoDbScorePropertyNames.SnapshotName].S,
                                       createAt: x[DynamoDbScorePropertyNames.CreateAt].S)
                                   )
                           .Select(x =>
                                   new ScoreSnapshotSummary()
                    {
                        Id = ScoreDatabaseUtils.ConvertToGuid(x.score.Substring(subStartIndex)),
                        Name = x.name,
                        CreateAt = ScoreDatabaseUtils.ConvertFromUnixTimeMilli(x.createAt),
                    }
                                   )
                           .ToArray());
                }
                catch (InternalServerErrorException ex)
                {
                    Console.WriteLine(ex.Message);
                    throw;
                }
                catch (ProvisionedThroughputExceededException ex)
                {
                    Console.WriteLine(ex.Message);
                    throw;
                }
                catch (RequestLimitExceededException ex)
                {
                    Console.WriteLine(ex.Message);
                    throw;
                }
                catch (ResourceNotFoundException ex)
                {
                    Console.WriteLine(ex.Message);
                    throw;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    throw;
                }
            }