Ejemplo n.º 1
0
        public static BatchGetItemResult FromJsonElement(JsonElement json)
        {
            // TODO: ConsumedCapacity

            IReadOnlyList <TableItemCollection> responses;

            if (json.TryGetProperty("Responses", out JsonElement responsesNode))
            {
                var collections = new List <TableItemCollection>();

                foreach (var tableEl in responsesNode.EnumerateObject()) // table elements
                {
                    var table = new TableItemCollection(tableEl.Name);

                    foreach (JsonElement item in tableEl.Value.EnumerateArray())
                    {
                        table.Add(AttributeCollection.FromJsonElement(item));
                    }

                    collections.Add(table);
                }

                responses = collections;
            }
            else
            {
                responses = Array.Empty <TableItemCollection>();
            }

            // TODO: UnprocessedKeys

            return(new BatchGetItemResult(responses));
        }
Ejemplo n.º 2
0
        public static UpdateItemResult FromJsonElement(JsonElement json)
        {
            ConsumedCapacity?   consumedCapacity = null;
            AttributeCollection?attributes       = null;

            if (json.TryGetProperty("ConsumedCapacity", out var consumedCapacityEl))
            {
                consumedCapacity = ConsumedCapacity.FromJsonElement(consumedCapacityEl);
            }

            if (json.TryGetProperty("Attributes", out var attributesEl))
            {
                attributes = AttributeCollection.FromJsonElement(attributesEl);
            }

            return(new UpdateItemResult(attributes, consumedCapacity));
        }
Ejemplo n.º 3
0
        public static GetItemResult FromJsonElement(JsonElement json)
        {
            AttributeCollection?item             = null;
            ConsumedCapacity?   consumedCapacity = null;

            if (json.TryGetProperty("ConsumedCapacity", out var consumedCapacityEl))
            {
                consumedCapacity = ConsumedCapacity.FromJsonElement(consumedCapacityEl);
            }

            if (json.TryGetProperty("Item", out var itemEl))
            {
                item = AttributeCollection.FromJsonElement(itemEl);
            }

            return(new GetItemResult(item !, consumedCapacity));
        }
Ejemplo n.º 4
0
        public static QueryResult FromJsonElement(JsonElement json)
        {
            ConsumedCapacity?   consumedCapacity = null;
            AttributeCollection?lastEvaluatedKey = null;

            if (json.TryGetProperty("ConsumedCapacity", out JsonElement consumedCapacityEl))
            {
                consumedCapacity = ConsumedCapacity.FromJsonElement(consumedCapacityEl);
            }

            if (json.TryGetProperty("LastEvaluatedKey", out JsonElement lastEvaluatedKeyEl))
            {
                lastEvaluatedKey = AttributeCollection.FromJsonElement(lastEvaluatedKeyEl);
            }

            AttributeCollection[] items;

            if (json.TryGetProperty("Items", out JsonElement itemsEl))
            {
                items = new AttributeCollection[itemsEl.GetArrayLength()];

                int i = 0;

                foreach (var itemEl in itemsEl.EnumerateArray())
                {
                    items[i] = AttributeCollection.FromJsonElement(itemEl);

                    i++;
                }
            }
            else
            {
                items = Array.Empty <AttributeCollection>();
            }

            return(new QueryResult(
                       consumedCapacity: consumedCapacity,
                       items: items,
                       lastEvaluatedKey: lastEvaluatedKey,
                       count: json.GetProperty("Count").GetInt32()
                       ));
        }
Ejemplo n.º 5
0
        public static TableRequests FromElementJson(string key, JsonElement batch)
        {
            var requests = new List <ItemRequest>(batch.GetArrayLength());

            foreach (var request in batch.EnumerateArray())
            {
                /*
                 *              {
                 *                      ""PutRequest"": {
                 *                              ""Item"": {
                 *                                      ""name"": { ""S"": ""marcywilliams"" },
                 *                                      ""ownerId"": { ""N"": ""3033325"" },
                 *                                      ""type"": { ""N"": ""1"" }
                 *                              }
                 *                      },
                 *                      ""DeleteRequest"": {
                 *                              ""Key"": {
                 *                                      ""name"": { ""S"": ""marcywilliams"" },
                 *                                      ""ownerId"": { ""N"": ""3033325"" }
                 *                              }
                 *                      }
                 *              }
                 */

                if (request.TryGetProperty("PutRequest", out var putRequestNode))
                {
                    var itemAttributes = AttributeCollection.FromJsonElement(putRequestNode.GetProperty("Item"));

                    requests.Add(new PutRequest(itemAttributes));
                }
                else if (request.TryGetProperty("DeleteRequest", out var deleteRequestNode))
                {
                    var keyAttributes = AttributeCollection.FromJsonElement(deleteRequestNode.GetProperty("Key"));

                    requests.Add(new DeleteRequest(keyAttributes));
                }
            }

            return(new TableRequests(key, requests));
        }