Esempio 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));
        }
Esempio n. 2
0
        public async Task <IReadOnlyList <T> > FindAllAsync(params IEnumerable <KeyValuePair <string, object> >[] keys)
        {
            if (keys is null || keys.Length == 0)
            {
                return(Array.Empty <T>());
            }

            var request = new BatchGetItemRequest(new TableKeys(tableName, keys));

            var result = await client.BatchGetItemAsync(request).ConfigureAwait(false);

            TableItemCollection r0 = result.Responses[0];

            var items = new T[r0.Count];

            for (int i = 0; i < items.Length; i++)
            {
                items[i] = r0[i].As <T>(metadata);
            }

            return(items);
        }
Esempio n. 3
0
        public static BatchGetItemResult FromJson(JsonObject json)
        {
            // var items = new List<AttributeCollection>();

            if (json.TryGetValue("ConsumedCapacity", out var consumedCapacityNode)) // Array
            {
                foreach (var item in (JsonArray)consumedCapacityNode)
                {
                    var unit = item.As <ConsumedCapacity>();

                    // TODO
                }
            }

            TableItemCollection[] responses;

            if (json.TryGetValue("Responses", out var responsesNode))
            {
                var tableElements = (JsonObject)responsesNode;

                var collections = new TableItemCollection[tableElements.Keys.Count];

                int i = 0;

                foreach (var tableEl in tableElements)
                {
                    var table = new TableItemCollection(tableEl.Key);

                    foreach (var item in (JsonArray)tableEl.Value)
                    {
                        table.Add(AttributeCollection.FromJson((JsonObject)item));
                    }

                    collections[i] = table;

                    i++;
                }

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

            /*
             *          if (json.TryGetValue("UnprocessedKeys", out var unprocessedKeysNode))
             *          {
             *  var unprocessedKeys = new List<TableKeys>();
             *
             *                  foreach (var tableEl in (JsonObject)unprocessedKeysNode)
             *                  {
             *                          var tableName = tableEl.Key;
             *
             *                          foreach (var keyEl in (XArray) tableEl.Value["Keys"])
             *                          {
             *                                  var attributes = new KeyValuePair<string, object>();
             *
             *                                  foreach (var prop in (JsonObject)keyEl)
             *                                  {
             *                                          var name = prop.Key;
             *                                          var value = DbValue.FromJson((JsonObject)prop.Value);
             *                                  }
             *
             *                                  var key = new Key(attributes);
             *                          }
             *                  }
             *          }
             */

            return(new BatchGetItemResult(responses));
        }