Пример #1
0
        public static QueryResult FromJson(JsonObject json)
        {
            var result = new QueryResult {
                Count = (int)json["Count"]
            };

            if (json.ContainsKey("ConsumedCapacity"))
            {
                result.ConsumedCapacity = ConsumedCapacity.FromJson((JsonObject)json["ConsumedCapacity"]);
            }

            if (json.ContainsKey("LastEvaluatedKey"))
            {
                result.LastEvaluatedKey = AttributeCollection.FromJson((JsonObject)json["LastEvaluatedKey"]);
            }

            if (json.ContainsKey("Items"))
            {
                foreach (var item in (JsonArray)json["Items"])
                {
                    result.Items.Add(AttributeCollection.FromJson((JsonObject)item));
                }
            }

            return(result);
        }
Пример #2
0
        public static BatchGetItemResult FromJson(JsonObject json)
        {
            var result = new BatchGetItemResult();

            var items = new List <AttributeCollection>();

            if (json.ContainsKey("ConsumedCapacity")) // Array
            {
                foreach (var item in (JsonArray)json["ConsumedCapacity"])
                {
                    var unit = ConsumedCapacity.FromJson((JsonObject)item);

                    // TODO
                }
            }

            if (json.ContainsKey("Responses"))
            {
                foreach (var tableEl in (JsonObject)json["Responses"])
                {
                    var table = new TableItems(tableEl.Key);

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

                    result.Responses.Add(table);
                }
            }

            /*
             *          if (json.ContainsKey("UnprocessedKeys"))
             *          {
             *                  foreach (var tableEl in (JsonObject)json["UnprocessedKeys"])
             *                  {
             *                          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(result);
        }
Пример #3
0
 public QueryResult(
     ConsumedCapacity consumedCapacity,
     AttributeCollection[] items,
     AttributeCollection lastEvaluatedKey,
     int count)
 {
     ConsumedCapacity = consumedCapacity;
     LastEvaluatedKey = lastEvaluatedKey;
     Items            = items;
     Count            = count;
 }
Пример #4
0
        public static DeleteItemResult FromJson(JsonObject json)
        {
            var result = new DeleteItemResult();

            if (json.ContainsKey("ConsumedCapacity"))
            {
                result.ConsumedCapacity = ConsumedCapacity.FromJson((JsonObject)json["ConsumedCapacity"]);
            }

            if (json.ContainsKey("Attributes"))
            {
                result.Attributes = AttributeCollection.FromJson((JsonObject)json["Attributes"]);
            }

            return(result);
        }
Пример #5
0
        public static DeleteItemResult FromJson(JsonObject json)
        {
            var result = new DeleteItemResult();

            if (json.TryGetValue("ConsumedCapacity", out var consumedCapacityNode))
            {
                result.ConsumedCapacity = ConsumedCapacity.FromJson((JsonObject)consumedCapacityNode);
            }

            if (json.TryGetValue("Attributes", out var attributesNode))
            {
                result.Attributes = AttributeCollection.FromJson((JsonObject)attributesNode);
            }

            return(result);
        }
Пример #6
0
        public static GetItemResult FromJson(JsonObject json)
        {
            var result = new GetItemResult();

            if (json.ContainsKey("ConsumedCapacity"))
            {
                result.ConsumedCapacity = ConsumedCapacity.FromJson((JsonObject)json["ConsumedCapacity"]);
            }

            if (json.ContainsKey("Item"))
            {
                result.Item = AttributeCollection.FromJson((JsonObject)json["Item"]);
            }

            return(result);
        }
Пример #7
0
        public static GetItemResult FromJson(JsonObject json)
        {
            var result = new GetItemResult();


            if (json.TryGetValue("ConsumedCapacity", out var consumedCapacityNode))
            {
                result.ConsumedCapacity = ConsumedCapacity.FromJson((JsonObject)consumedCapacityNode);
            }

            if (json.TryGetValue("Item", out var itemNode))
            {
                result.Item = AttributeCollection.FromJson((JsonObject)itemNode);
            }

            return(result);
        }
Пример #8
0
        public static PutItemResult FromJson(JsonObject json)
        {
            AttributeCollection attributes       = null;
            ConsumedCapacity    consumedCapacity = null;

            if (json.TryGetValue("ConsumedCapacity", out var consumedCapacityNode))
            {
                consumedCapacity = ConsumedCapacity.FromJson((JsonObject)consumedCapacityNode);
            }

            if (json.TryGetValue("Attributes", out var attributeNode))
            {
                attributes = AttributeCollection.FromJson((JsonObject)attributeNode);
            }

            return(new PutItemResult(attributes, consumedCapacity));
        }
Пример #9
0
        internal static ConsumedCapacity FromJsonElement(JsonElement el)
        {
            var result = new ConsumedCapacity();

            foreach (var property in el.EnumerateObject())
            {
                if (property.NameEquals("TableName"))
                {
                    result.TableName = property.Value.GetString();
                }
                else if (property.NameEquals("CapacityUnits"))
                {
                    result.CapacityUnits = property.Value.GetSingle();
                }
            }

            return(result);
        }
Пример #10
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()
                       ));
        }
Пример #11
0
        public static QueryResult FromJson(JsonObject json)
        {
            ConsumedCapacity    consumedCapacity = null;
            AttributeCollection lastEvaluatedKey = null;

            if (json.TryGetValue("ConsumedCapacity", out var consumedCapacityNode))
            {
                consumedCapacity = ConsumedCapacity.FromJson((JsonObject)consumedCapacityNode);
            }

            if (json.TryGetValue("LastEvaluatedKey", out var lastEvaluatedKeyNode))
            {
                lastEvaluatedKey = AttributeCollection.FromJson((JsonObject)lastEvaluatedKeyNode);
            }

            AttributeCollection[] items;

            if (json.TryGetValue("Items", out var itemsNode))
            {
                var itemsJson = (JsonArray)itemsNode;

                items = new AttributeCollection[itemsJson.Count];

                for (var i = 0; i < items.Length; i++)
                {
                    items[i] = AttributeCollection.FromJson((JsonObject)itemsJson[i]);
                }
            }
            else
            {
                items = Array.Empty <AttributeCollection>();
            }

            return(new QueryResult(
                       consumedCapacity: consumedCapacity,
                       items: items,
                       lastEvaluatedKey: lastEvaluatedKey,
                       count: (int)json["Count"]
                       ));
        }
Пример #12
0
 public PutItemResult(AttributeCollection attributes, ConsumedCapacity consumedCapacity)
 {
     Attributes       = attributes;
     ConsumedCapacity = consumedCapacity;
 }