Represents the data for an attribute. You can set one, and only one, of the elements.

        public virtual object FromAttributeValue(AttributeValue attrValue)
        {
            var iso8601String = attrValue.S;
            var date = iso8601String == null
                ? null
                : DateTimeSerializer.ParseManual(iso8601String, DateTimeKind.Utc);

            return date;
        }
        public void SaveNewVideo()
        {
            var client = new AmazonDynamoDBClient();
            var request = new PutItemRequest();
            request.TableName = "Local.Area";
            request.Item = new Dictionary<string, AttributeValue>();

            var value1 = new AttributeValue
            {
               S = "103"

            };

            request.Item.Add("Description", value1);
        }
        private CacheAttributeValueWrapper(SerializationInfo info, StreamingContext context)
        {
            this.AttributeValue = new AttributeValue();

            var en = info.GetEnumerator();
            while (en.MoveNext())
            {
                switch (en.Name)
                {
                    case "S":
                        this.AttributeValue.S = (string)en.Value;
                        break;
                    case "SS":
                        this.AttributeValue.SS = (List<string>)en.Value;
                        break;
                    case "N":
                        this.AttributeValue.N = (string)en.Value;
                        break;
                    case "NS":
                        this.AttributeValue.NS = (List<string>)en.Value;
                        break;
                    case "B":
                        this.AttributeValue.B = (MemoryStream)en.Value;
                        break;
                    case "BS":
                        this.AttributeValue.BS = (List<MemoryStream>)en.Value;
                        break;
                    case "M":
                        this.AttributeValue.M = ((CacheDictionaryOfAttributeValuesWrapper)en.Value).Dictionary;
                        break;
                    case "L":
                        this.AttributeValue.L = ((CacheListOfAttributeValuesWrapper)en.Value).List;
                        break;
                }
            }
        }
 /// <summary>
 /// Instantiates AttributeValueUpdate with the parameterized properties
 /// </summary>
 /// <param name="value">Represents the data for an attribute. Each attribute value is described as a name-value pair. The name is the data type, and the value is the data itself. For more information, see <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html#HowItWorks.DataTypes">Data TYpes</a> in the <i>Amazon DynamoDB Developer Guide</i>. </param>
 /// <param name="action">Specifies how to perform the update. Valid values are <code>PUT</code> (default), <code>DELETE</code>, and <code>ADD</code>. The behavior depends on whether the specified primary key already exists in the table.  <b>If an item with the specified <i>Key</i> is found in the table:</b>  <ul> <li>  <code>PUT</code> - Adds the specified attribute to the item. If the attribute already exists, it is replaced by the new value.  </li> <li>  <code>DELETE</code> - If no value is specified, the attribute and its value are removed from the item. The data type of the specified value must match the existing value's data type. If a <i>set</i> of values is specified, then those values are subtracted from the old set. For example, if the attribute value was the set <code>[a,b,c]</code> and the <code>DELETE</code> action specified <code>[a,c]</code>, then the final attribute value would be <code>[b]</code>. Specifying an empty set is an error. </li> <li>  <code>ADD</code> - If the attribute does not already exist, then the attribute and its values are added to the item. If the attribute does exist, then the behavior of <code>ADD</code> depends on the data type of the attribute: <ul> <li> If the existing attribute is a number, and if <code>Value</code> is also a number, then the <code>Value</code> is mathematically added to the existing attribute. If <code>Value</code> is a negative number, then it is subtracted from the existing attribute. <note>  If you use <code>ADD</code> to increment or decrement a number value for an item that doesn't exist before the update, DynamoDB uses 0 as the initial value. In addition, if you use <code>ADD</code> to update an existing item, and intend to increment or decrement an attribute value which does not yet exist, DynamoDB uses <code>0</code> as the initial value. For example, suppose that the item you want to update does not yet have an attribute named <i>itemcount</i>, but you decide to <code>ADD</code> the number <code>3</code> to this attribute anyway, even though it currently does not exist. DynamoDB will create the <i>itemcount</i> attribute, set its initial value to <code>0</code>, and finally add <code>3</code> to it. The result will be a new <i>itemcount</i> attribute in the item, with a value of <code>3</code>. </note> </li> <li> If the existing data type is a set, and if the <code>Value</code> is also a set, then the <code>Value</code> is added to the existing set. (This is a <i>set</i> operation, not mathematical addition.) For example, if the attribute value was the set <code>[1,2]</code>, and the <code>ADD</code> action specified <code>[3]</code>, then the final attribute value would be <code>[1,2,3]</code>. An error occurs if an Add action is specified for a set attribute and the attribute type specified does not match the existing set type.  Both sets must have the same primitive data type. For example, if the existing data type is a set of strings, the <code>Value</code> must also be a set of strings. The same holds true for number sets and binary sets. </li> </ul> This action is only valid for an existing attribute whose data type is number or is a set. Do not use <code>ADD</code> for any other data types. </li> </ul>  <b>If no item with the specified <i>Key</i> is found:</b>  <ul> <li>  <code>PUT</code> - DynamoDB creates a new item with the specified primary key, and then adds the attribute.  </li> <li>  <code>DELETE</code> - Nothing happens; there is no attribute to delete. </li> <li>  <code>ADD</code> - DynamoDB creates an item with the supplied primary key and number (or set of numbers) for the attribute value. The only data types allowed are number and number set; no other data types can be specified. </li> </ul></param>
 public AttributeValueUpdate(AttributeValue value, AttributeAction action)
 {
     _value  = value;
     _action = action;
 }
示例#5
0
 private List<Dictionary<string, string>> get(
     string table,
     string keyName,
     string keyValue)
 {
     string prefixedKeyName = ":v_" + keyName;
     AttributeValue av = new AttributeValue { S = keyValue };
     var response = this.client.Query(new QueryRequest(table) {
         ExpressionAttributeValues = new Dictionary<string, AttributeValue>() {
             { prefixedKeyName, av}
         },
         KeyConditionExpression = string.Format("{0} = {1}", keyName, prefixedKeyName),
     });
     if (response.Items.Count == 0) {
         return new List<Dictionary<string,string>>();
     }
     log.InfoFormat("Queried: {0}, {1}, {2}", table, keyName, keyValue);
     return response.Items.Select(i => i.ToDictionary(j => j.Key, j => j.Value.S)).ToList();
 }
示例#6
0
 private void add(string table, string keyName, string key, params TableAttribute[] values)
 {
     Dictionary<string, AttributeValue> attributes = new Dictionary<string, AttributeValue>();
     attributes[keyName] = new AttributeValue { S = key };
     foreach (var v in values) {
         attributes[v.AttributeName] = new AttributeValue { S = v.AttributeValue };
     }
     var response = client.BatchWriteItem(new BatchWriteItemRequest() {
         RequestItems = new Dictionary<string, List<WriteRequest>>() {
             {
               table,
               new List<WriteRequest>() {
                    new WriteRequest(
                        new PutRequest(
                            attributes
                            )
                         )
                     }
                 }
             },
     }
     );
     Debug.Assert(response.HttpStatusCode == System.Net.HttpStatusCode.OK);
     Debug.Assert(response.UnprocessedItems.Count == 0);
     log.Info(string.Format("Wrote Table: {0}, key: {1}, values: {2}", table, key, string.Join(",", values.Select(i => i.AttributeValue))));
 }
 public AttributeValueUpdate WithValue(AttributeValue value)
 {
     this.value = value;
     return(this);
 }
 /// <summary>
 /// Instantiates AttributeValueUpdate with the parameterized properties
 /// </summary>
 /// <param name="value">Sets the AttributeValueUpdate Value property</param>
 /// <param name="action">Specifies how to perform the update. Valid values are <code>PUT</code> (default), <code>DELETE</code>, and <code>ADD</code>. The behavior depends on whether the specified primary key already exists in the table.  <b>If an item with the specified <i>Key</i> is found in the table:</b>  <ul> <li> <code>PUT</code> - Adds the specified attribute to the item. If the attribute already exists, it is replaced by the new value.  </li> <li> <code>DELETE</code> - If no value is specified, the attribute and its value are removed from the item. The data type of the specified value must match the existing value's data type. If a <i>set</i> of values is specified, then those values are subtracted from the old set. For example, if the attribute value was the set <code>[a,b,c]</code> and the <i>DELETE</i> action specified <code>[a,c]</code>, then the final attribute value would be <code>[b]</code>. Specifying an empty set is an error. </li> <li> <code>ADD</code> - If the attribute does not already exist, then the attribute and its values are added to the item. If the attribute does exist, then the behavior of <code>ADD</code> depends on the data type of the attribute: <ul> <li> If the existing attribute is a number, and if <i>Value</i> is also a number, then the <i>Value</i> is mathematically added to the existing attribute. If <i>Value</i> is a negative number, then it is subtracted from the existing attribute. <note>  If you use <code>ADD</code> to increment or decrement a number value for an item that doesn't exist before the update, DynamoDB uses 0 as the initial value. In addition, if you use <code>ADD</code> to update an existing item, and intend to increment or decrement an attribute value which does not yet exist, DynamoDB uses <code>0</code> as the initial value. For example, suppose that the item you want to update does not yet have an attribute named <i>itemcount</i>, but you decide to <code>ADD</code> the number <code>3</code> to this attribute anyway, even though it currently does not exist. DynamoDB will create the <i>itemcount</i> attribute, set its initial value to <code>0</code>, and finally add <code>3</code> to it. The result will be a new <i>itemcount</i> attribute in the item, with a value of <code>3</code>. </note> </li> <li> If the existing data type is a set, and if the <i>Value</i> is also a set, then the <i>Value</i> is added to the existing set. (This is a <i>set</i> operation, not mathematical addition.) For example, if the attribute value was the set <code>[1,2]</code>, and the <code>ADD</code> action specified <code>[3]</code>, then the final attribute value would be <code>[1,2,3]</code>. An error occurs if an Add action is specified for a set attribute and the attribute type specified does not match the existing set type.  Both sets must have the same primitive data type. For example, if the existing data type is a set of strings, the <i>Value</i> must also be a set of strings. The same holds true for number sets and binary sets. </li> </ul> This action is only valid for an existing attribute whose data type is number or is a set. Do not use <code>ADD</code> for any other data types. </li> </ul>  <b>If no item with the specified <i>Key</i> is found:</b>  <ul> <li> <code>PUT</code> - DynamoDB creates a new item with the specified primary key, and then adds the attribute.  </li> <li> <code>DELETE</code> - Nothing happens; there is no attribute to delete. </li> <li> <code>ADD</code> - DynamoDB creates an item with the supplied primary key and number (or set of numbers) for the attribute value. The only data types allowed are number and number set; no other data types can be specified. </li> </ul></param>
 public AttributeValueUpdate(AttributeValue value, AttributeAction action)
 {
     _value = value;
     _action = action;
 }
 /// <summary>
 /// Instantiates ExpectedAttributeValue with the parameterized properties
 /// </summary>
 /// <param name="value">Sets the ExpectedAttributeValue Value property</param>
 public ExpectedAttributeValue(AttributeValue value)
 {
     _value = value;
 }
示例#10
0
        public void BatchSamples()
        {
            EnsureTables();

            {
                #region BatchGet Sample 1

                // Define attributes to get and keys to retrieve
                List<string> attributesToGet = new List<string> { "Author", "Title", "Year" };
                List<Dictionary<string, AttributeValue>> sampleTableKeys = new List<Dictionary<string, AttributeValue>>
                {
                    new Dictionary<string, AttributeValue>
                    {
                        { "Author", new AttributeValue { S = "Mark Twain" } },
                        { "Title", new AttributeValue { S = "The Adventures of Tom Sawyer" } }
                    },
                    new Dictionary<string, AttributeValue>
                    {
                        { "Author", new AttributeValue { S = "Mark Twain" } },
                        { "Title", new AttributeValue { S = "Adventures of Huckleberry Finn" } }
                    }
                };

                // Construct get-request for first table
                KeysAndAttributes sampleTableItems = new KeysAndAttributes
                {
                    AttributesToGet = attributesToGet,
                    Keys = sampleTableKeys
                };

                #endregion

                #region BatchGet Sample 2

                // Define keys to retrieve
                List<Dictionary<string, AttributeValue>> authorsTableKeys = new List<Dictionary<string, AttributeValue>>
                {
                    new Dictionary<string, AttributeValue>
                    {
                        { "Author", new AttributeValue { S = "Mark Twain" } },
                    },
                    new Dictionary<string, AttributeValue>
                    {
                        { "Author", new AttributeValue { S = "Booker Taliaferro Washington" } },
                    }
                };

                // Construct get-request for second table
                //  Skip setting AttributesToGet property to retrieve all attributes
                KeysAndAttributes authorsTableItems = new KeysAndAttributes
                {
                    Keys = authorsTableKeys,
                };

                #endregion

                #region BatchGet Sample 3

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Construct table-keys mapping
                Dictionary<string, KeysAndAttributes> requestItems = new Dictionary<string, KeysAndAttributes>();
                requestItems["SampleTable"] = sampleTableItems;
                requestItems["AuthorsTable"] = authorsTableItems;

                // Construct request
                BatchGetItemRequest request = new BatchGetItemRequest
                {
                    RequestItems = requestItems
                };

                BatchGetItemResult result;
                do
                {
                    // Issue request and retrieve items
                    result = client.BatchGetItem(request);

                    // Iterate through responses
                    Dictionary<string, List<Dictionary<string, AttributeValue>>> responses = result.Responses;
                    foreach (string tableName in responses.Keys)
                    {
                        // Get items for each table
                        List<Dictionary<string, AttributeValue>> tableItems = responses[tableName];

                        // View items
                        foreach (Dictionary<string, AttributeValue> item in tableItems)
                        {
                            Console.WriteLine("Item:");
                            foreach (var keyValuePair in item)
                            {
                                Console.WriteLine("{0} : S={1}, N={2}, SS=[{3}], NS=[{4}]",
                                    keyValuePair.Key,
                                    keyValuePair.Value.S,
                                    keyValuePair.Value.N,
                                    string.Join(", ", keyValuePair.Value.SS ?? new List<string>()),
                                    string.Join(", ", keyValuePair.Value.NS ?? new List<string>()));
                            }
                        }
                    }

                    // Some items may not have been retrieved!
                    //  Set RequestItems to the result's UnprocessedKeys and reissue request
                    request.RequestItems = result.UnprocessedKeys;

                } while (result.UnprocessedKeys.Count > 0);

                #endregion
            }


            {
                #region BatchWrite Sample 1

                // Create items to put into first table
                Dictionary<string, AttributeValue> item1 = new Dictionary<string, AttributeValue>();
                item1["Author"] = new AttributeValue { S = "Mark Twain" };
                item1["Title"] = new AttributeValue { S = "A Connecticut Yankee in King Arthur's Court" };
                item1["Pages"] = new AttributeValue { N = "575" };
                Dictionary<string, AttributeValue> item2 = new Dictionary<string, AttributeValue>();
                item2["Author"] = new AttributeValue { S = "Booker Taliaferro Washington" };
                item2["Title"] = new AttributeValue { S = "My Larger Education" };
                item2["Pages"] = new AttributeValue { N = "313" };
                item2["Year"] = new AttributeValue { N = "1911" };

                // Create key for item to delete from first table
                //  Hash-key of the target item is string value "Mark Twain"
                //  Range-key of the target item is string value "Tom Sawyer, Detective"
                Dictionary<string, AttributeValue> keyToDelete1 = new Dictionary<string, AttributeValue>
                {
                    { "Author", new AttributeValue { S = "Mark Twain" } },
                    { "Title", new AttributeValue { S = "Tom Sawyer, Detective" } }
                };

                // Construct write-request for first table
                List<WriteRequest> sampleTableItems = new List<WriteRequest>();
                sampleTableItems.Add(new WriteRequest
                {
                    PutRequest = new PutRequest { Item = item1 }
                });
                sampleTableItems.Add(new WriteRequest
                {
                    PutRequest = new PutRequest { Item = item2 }
                });
                sampleTableItems.Add(new WriteRequest
                {
                    DeleteRequest = new DeleteRequest { Key = keyToDelete1 }
                });

                #endregion

                #region BatchWrite Sample 2

                // Create key for item to delete from second table
                //  Hash-key of the target item is string value "Francis Scott Key Fitzgerald"
                Dictionary<string, AttributeValue> keyToDelete2 = new Dictionary<string, AttributeValue>
                {
                    { "Author", new AttributeValue { S = "Francis Scott Key Fitzgerald" } },
                };

                // Construct write-request for first table
                List<WriteRequest> authorsTableItems = new List<WriteRequest>();
                authorsTableItems.Add(new WriteRequest
                {
                    DeleteRequest = new DeleteRequest { Key = keyToDelete2 }
                });

                #endregion

                #region BatchWrite Sample 3

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Construct table-keys mapping
                Dictionary<string, List<WriteRequest>> requestItems = new Dictionary<string, List<WriteRequest>>();
                requestItems["SampleTable"] = sampleTableItems;
                requestItems["AuthorsTable"] = authorsTableItems;

                BatchWriteItemRequest request = new BatchWriteItemRequest { RequestItems = requestItems };
                BatchWriteItemResult result;
                do
                {
                    // Issue request and retrieve items
                    result = client.BatchWriteItem(request);

                    // Some items may not have been processed!
                    //  Set RequestItems to the result's UnprocessedItems and reissue request
                    request.RequestItems = result.UnprocessedItems;

                } while (result.UnprocessedItems.Count > 0);

                #endregion
            }
        }
示例#11
0
        public void SearchSamples()
        {
            RemoveTables();
            CreateLSITable();
            TableUtils.WaitUntilTableActive("SampleTable", TestClient);

            {
                // Create items to put into first table
                Dictionary<string, AttributeValue> item1 = new Dictionary<string, AttributeValue>();
                item1["Author"] = new AttributeValue { S = "Mark Twain" };
                item1["Title"] = new AttributeValue { S = "A Connecticut Yankee in King Arthur's Court" };
                item1["Pages"] = new AttributeValue { N = "575" };
                Dictionary<string, AttributeValue> item2 = new Dictionary<string, AttributeValue>();
                item2["Author"] = new AttributeValue { S = "Booker Taliaferro Washington" };
                item2["Title"] = new AttributeValue { S = "My Larger Education" };
                item2["Pages"] = new AttributeValue { N = "313" };
                item2["Year"] = new AttributeValue { N = "1911" };

                // Construct write-request for first table
                List<WriteRequest> sampleTableItems = new List<WriteRequest>();
                sampleTableItems.Add(new WriteRequest
                {
                    PutRequest = new PutRequest { Item = item1 }
                });
                sampleTableItems.Add(new WriteRequest
                {
                    PutRequest = new PutRequest { Item = item2 }
                });
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();
                client.BatchWriteItem(new BatchWriteItemRequest
                {
                    RequestItems = new Dictionary<string, List<WriteRequest>>
                    {
                        { "SampleTable", sampleTableItems }
                    }
                });

                PutSample();
            }


            {
                #region Query Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Define item hash-key to be string value "Mark Twain"
                AttributeValue hashKey = new AttributeValue { S = "Mark Twain" };

                // Define query condition to search for range-keys that begin with the string "The Adventures"
                Condition condition = new Condition
                {
                    ComparisonOperator = "BEGINS_WITH",
                    AttributeValueList = new List<AttributeValue>
                    {
                        new AttributeValue { S = "The Adventures" }
                    }
                };

                // Create the key conditions from hashKey and condition
                Dictionary<string, Condition> keyConditions = new Dictionary<string, Condition>
                {
                    // Hash key condition. ComparisonOperator must be "EQ".
                    { 
                        "Author",
                        new Condition
                        {
                            ComparisonOperator = "EQ",
                            AttributeValueList = new List<AttributeValue> { hashKey }
                        }
                    },
                    // Range key condition
                    {
                        "Title",
                        condition
                    }
                };

                // Define marker variable
                Dictionary<string, AttributeValue> startKey = null;

                do
                {
                    // Create Query request
                    QueryRequest request = new QueryRequest
                    {
                        TableName = "SampleTable",
                        ExclusiveStartKey = startKey,
                        KeyConditions = keyConditions
                    };

                    // Issue request
                    var result = client.Query(request);

                    // View all returned items
                    List<Dictionary<string, AttributeValue>> items = result.Items;
                    foreach (Dictionary<string, AttributeValue> item in items)
                    {
                        Console.WriteLine("Item:");
                        foreach (var keyValuePair in item)
                        {
                            Console.WriteLine("{0} : S={1}, N={2}, SS=[{3}], NS=[{4}]",
                                keyValuePair.Key,
                                keyValuePair.Value.S,
                                keyValuePair.Value.N,
                                string.Join(", ", keyValuePair.Value.SS ?? new List<string>()),
                                string.Join(", ", keyValuePair.Value.NS ?? new List<string>()));
                        }
                    }

                    // Set marker variable
                    startKey = result.LastEvaluatedKey;
                } while (startKey != null && startKey.Count > 0);

                #endregion
            }

            {
                #region Query Local Secondary Index Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Define item hash-key to be string value "Mark Twain"
                AttributeValue hashKey = new AttributeValue { S = "Mark Twain" };

                // Define query condition to search for range-keys ("Year", in "YearsIndex") that are less than 1900
                Condition condition = new Condition
                {
                    ComparisonOperator = "LT",
                    AttributeValueList = new List<AttributeValue>
                    {
                        new AttributeValue { N = "1900" }
                    }
                };

                // Create the key conditions from hashKey and condition
                Dictionary<string, Condition> keyConditions = new Dictionary<string, Condition>
                {
                    // Hash key condition. ComparisonOperator must be "EQ".
                    { 
                        "Author",
                        new Condition
                        {
                            ComparisonOperator = "EQ",
                            AttributeValueList = new List<AttributeValue> { hashKey }
                        }
                    },
                    // Range key condition
                    {
                        "Year", // Reference the correct range key when using indexes
                        condition
                    }
                };

                // Define marker variable
                Dictionary<string, AttributeValue> startKey = null;

                do
                {
                    // Create Query request
                    QueryRequest request = new QueryRequest
                    {
                        TableName = "SampleTable",
                        ExclusiveStartKey = startKey,
                        KeyConditions = keyConditions,
                        IndexName = "YearsIndex" // Specify the index to query against
                    };

                    // Issue request
                    var result = client.Query(request);

                    // View all returned items
                    List<Dictionary<string, AttributeValue>> items = result.Items;
                    foreach (Dictionary<string, AttributeValue> item in items)
                    {
                        Console.WriteLine("Item:");
                        foreach (var keyValuePair in item)
                        {
                            Console.WriteLine("{0} : S={1}, N={2}, SS=[{3}], NS=[{4}]",
                                keyValuePair.Key,
                                keyValuePair.Value.S,
                                keyValuePair.Value.N,
                                string.Join(", ", keyValuePair.Value.SS ?? new List<string>()),
                                string.Join(", ", keyValuePair.Value.NS ?? new List<string>()));
                        }
                    }

                    // Set marker variable
                    startKey = result.LastEvaluatedKey;
                } while (startKey != null && startKey.Count > 0);

                #endregion
            }

            {
                #region Scan Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Define scan conditions
                Dictionary<string, Condition> conditions = new Dictionary<string, Condition>();

                // Title attribute should contain the string "Adventures"
                Condition titleCondition = new Condition();
                titleCondition.ComparisonOperator = ComparisonOperator.CONTAINS;
                titleCondition.AttributeValueList.Add(new AttributeValue { S = "Adventures" });
                conditions["Title"] = titleCondition;

                // Pages attributes must be greater-than the numeric value "200"
                Condition pagesCondition = new Condition();
                pagesCondition.ComparisonOperator = ComparisonOperator.GT;;
                pagesCondition.AttributeValueList.Add(new AttributeValue { N = "200" });
                conditions["Pages"] = pagesCondition;


                // Define marker variable
                Dictionary<string, AttributeValue> startKey = null;

                do
                {
                    // Create Scan request
                    ScanRequest request = new ScanRequest
                    {
                        TableName = "SampleTable",
                        ExclusiveStartKey = startKey,
                        ScanFilter = conditions
                    };

                    // Issue request
                    ScanResult result = client.Scan(request);

                    // View all returned items
                    List<Dictionary<string, AttributeValue>> items = result.Items;
                    foreach (Dictionary<string, AttributeValue> item in items)
                    {
                        Console.WriteLine("Item:");
                        foreach (var keyValuePair in item)
                        {
                            Console.WriteLine("{0} : S={1}, N={2}, SS=[{3}], NS=[{4}]",
                                keyValuePair.Key,
                                keyValuePair.Value.S,
                                keyValuePair.Value.N,
                                string.Join(", ", keyValuePair.Value.SS ?? new List<string>()),
                                string.Join(", ", keyValuePair.Value.NS ?? new List<string>()));
                        }
                    }

                    // Set marker variable
                    startKey = result.LastEvaluatedKey;
                } while (startKey != null && startKey.Count > 0);

                #endregion
            }

            {
                // Create lots of items to put into first table
                var table = Amazon.DynamoDBv2.DocumentModel.Table.LoadTable(TestClient, "SampleTable");
                var batchWrite = table.CreateBatchWrite();
                for (int i = 0; i < 100; i++)
                {
                    var document = new Amazon.DynamoDBv2.DocumentModel.Document();
                    document["Author"] = "FakeAuthor" + i;
                    document["Title"] = "Book" + i;
                    document["Pages"] = (180 + i);
                    document["Year"] = 1900 + i;
                    batchWrite.AddDocumentToPut(document);
                }
                batchWrite.Execute();
            }


            {
                #region Parallel Scan Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Define scan conditions
                Dictionary<string, Condition> conditions = new Dictionary<string, Condition>();

                // Pages attributes must be greater-than the numeric value "200"
                Condition pagesCondition = new Condition();
                pagesCondition.ComparisonOperator = ComparisonOperator.GT;
                pagesCondition.AttributeValueList.Add(new AttributeValue { N = "200" });
                conditions["Pages"] = pagesCondition;

                // Setup 10 simultaneous threads, each thread calling Scan operation
                // with its own segment value.
                int totalSegments = 10;
                Parallel.For(0, totalSegments, segment =>
                {
                    // Define marker variable
                    Dictionary<string, AttributeValue> startKey = null;

                    do
                    {
                        // Create Scan request
                        ScanRequest request = new ScanRequest
                        {
                            TableName = "SampleTable",
                            ExclusiveStartKey = startKey,
                            ScanFilter = conditions,
                            // Total segments to split the table into
                            TotalSegments = totalSegments,
                            // Current segment to scan
                            Segment = segment
                        };

                        // Issue request
                        var result = client.Scan(request);

                        // Write returned items to file
                        string path = string.Format("ParallelScan-{0}-of-{1}.txt", totalSegments, segment);
                        List<Dictionary<string, AttributeValue>> items = result.Items;
                        using (Stream stream = File.OpenWrite(path))
                        using (StreamWriter writer = new StreamWriter(stream))
                        {
                            foreach (Dictionary<string, AttributeValue> item in items)
                            {
                                writer.WriteLine("Item:");
                                foreach (var keyValuePair in item)
                                {
                                    writer.WriteLine("{0} : S={1}, N={2}, SS=[{3}], NS=[{4}]",
                                        keyValuePair.Key,
                                        keyValuePair.Value.S,
                                        keyValuePair.Value.N,
                                        string.Join(", ", keyValuePair.Value.SS ?? new List<string>()),
                                        string.Join(", ", keyValuePair.Value.NS ?? new List<string>()));
                                }
                            }
                        }

                        // Set marker variable
                        startKey = result.LastEvaluatedKey;
                    } while (startKey != null && startKey.Count > 0);
                });

                #endregion
            }

        }
示例#12
0
        private void PutSample()
        {
            {
                #region PutItem Sample 1

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Define item attributes
                Dictionary<string, AttributeValue> attributes = new Dictionary<string, AttributeValue>();
                // Author is hash-key
                attributes["Author"] = new AttributeValue { S = "Mark Twain" };
                // Title is range-key
                attributes["Title"] = new AttributeValue { S = "The Adventures of Tom Sawyer" };
                // Other attributes
                attributes["Year"] = new AttributeValue { N = "1876" };
                attributes["Setting"] = new AttributeValue { S = "Missouri" };
                attributes["Pages"] = new AttributeValue { N = "275" };
                attributes["Genres"] = new AttributeValue
                {
                    SS = new List<string> { "Satire", "Folk", "Children's Novel" }
                };

                // Create PutItem request
                PutItemRequest request = new PutItemRequest
                {
                    TableName = "SampleTable",
                    Item = attributes
                };

                // Issue PutItem request
                client.PutItem(request);

                #endregion
            }
        }
示例#13
0
 private object GetValueFromAttribute(AttributeValue value)
 {
     if (value.N != null)
     {
         int iValue = 0;
         decimal dValue = 0;
         if (int.TryParse(value.N, out iValue))
         {
             return iValue;
         }
         if (decimal.TryParse(value.N, out dValue))
         {
             return dValue;
         }
         return value.N;
     }
     if (value.S != null)
         return value.S;
     if (value.SS != null && value.SS.Any())
         return value.SS;
     if (value.NULL)
     {
         return null;
     }
     return value.BOOL;
 }
        protected void submitButton_Click(object sender, EventArgs e)
        {
            if (inId.Value != "" && inQid.Value != "" && txtQuestion.Text != "" && txtCorrectAnswer.Text != "" && txtOptions0.Text != "")
            {
                string message = "";
                int iCount = 0;
                int iNewCount = 0;
                List<string> txtOptionsList = new List<string>();
                foreach (TextBox textBox in divTest.Controls.OfType<TextBox>())
                {
                    if (!string.IsNullOrEmpty(textBox.Text))
                    {
                        {
                            if (textBox.ID == "txtOptions" + iNewCount)
                            {
                                iNewCount = iNewCount + 1;
                                message = textBox.Text;
                            }
                            txtOptionsList.Add(message);
                        }
                    }
                }

                string alpha = "ABCDEFGHIJKLMNOPQRSTUVQXYZ";

                Dictionary<string, AttributeValue> attValue = new Dictionary<string, AttributeValue>();
                int alphabet = 0;
                for (int i = 0; i <= txtOptionsList.Count - 1; i++)
                {
                    {
                        AttributeValue attribute = new AttributeValue();
                        attribute.S = txtOptionsList[i];
                        attValue.Add(alpha[alphabet].ToString().ToLower(), attribute);
                        alphabet = alphabet + 1;
                    }
                }
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();
                // Amazon.DynamoDBv2.DocumentModel.Table table = Amazon.DynamoDBv2.DocumentModel.Table.LoadTable(client, "Event");		+                // Amazon.DynamoDBv2.DocumentModel.Table table = Amazon.DynamoDBv2.DocumentModel.Table.LoadTable(client, "Event");
                client.PutItem("QuizQuestion", new Dictionary<string, AttributeValue>

            {
            { "eventId", new AttributeValue { S = inId.Value } },
            { "questionId", new AttributeValue { S = inQid.Value } },
            { "question", new AttributeValue { S = txtQuestion.Text } },
            { "questionType", new AttributeValue { S = ddlQuestionType.SelectedItem.Text } },
            { "correctAnswer", new AttributeValue { S = txtCorrectAnswer.Text } },
            //{ "endTime", new AttributeValue { S = "28/10/2017 4:00 PM" } },
            //{ "startTime", new AttributeValue { S = "28/10/2016 4:00 PM" } },
            { "options", new AttributeValue {
            M = attValue
            }
            }
            });
                string script = "alert(\"Successfully created the Question.\");";
                ScriptManager.RegisterStartupScript(this, GetType(),
                                      "ServerControlScript", script, true);

                Response.Redirect("Question.aspx");

            }
            else
            {
                string script = "alert(\"Please fill all the data.\");";
                ScriptManager.RegisterStartupScript(this, GetType(),
                                      "ServerControlScript", script, true);
            }
        }
示例#15
0
        public int GetItemValue(GetItemResponse itemResponse, string columnName, out string outResponse)
        {
            int response = (int)DBEnum.DBResponseCodes.DEFAULT_VALUE;
            AttributeValue av = new AttributeValue();
            itemResponse.Item.TryGetValue(columnName, out av);
            string tempOutResponse;

            try
            {
                response = (int)DBEnum.DBResponseCodes.SUCCESS;
                tempOutResponse = av.S;
            }

            catch
            {
                response = (int)DBEnum.DBResponseCodes.DYNAMODB_EXCEPTION;
                tempOutResponse = null;
            }

            outResponse = tempOutResponse;
            return response;
        }
 public AttributeValueUpdate WithValue(AttributeValue value)
 {
     this.value = value;
     return this;
 }
        private object ConvertAttributeValue(AttributeValue value)
        {
            if (value.N != null)
            {
                return ConvertNumber(value.N);
            }

            if (value.NS != null && value.NS.Count > 0)
            {
                var result = new double[value.NS.Count];
                for (var index = 0; index < result.Length; ++index)
                    result[index] = ConvertNumber(value.NS[index]);
                return result;
            }

            if (value.S != null)
            {
                return value.S;
            }

            if (value.SS != null && value.SS.Count > 0)
            {
                var result = new string[value.SS.Count];
                for (var index = 0; index < result.Length; ++index)
                    result[index] = value.SS[index];
                return result;
            }

            if (value.IsBOOLSet)
            {
                return value.BOOL;
            }

            if (value.IsLSet && value.L != null)
            {
                var result = new object[value.L.Count];
                for (var index = 0; index < result.Length; ++index)
                    result[index] = ConvertAttributeValue(value.L[index]);
                return result;
            }

            if (value.IsMSet && value.M != null)
            {
                return new DynamoDbDataItem(value.M);
            }

            if (value.B != null)
            {
                return ConvertBinaryData(value.B);
            }

            if (value.BS != null && value.BS.Count > 0)
            {
                var result = new byte[value.BS.Count][];
                for (var index = 0; index < result.Length; ++index)
                    result[index] = ConvertBinaryData(value.BS[index]);
                return result;
            }

            return null;
        }
 public DynamoDbItemAttribute(string name, AttributeValue value)
 {
     this.Name = name;
     this.Value = value;
 }
示例#19
0
 /// <summary>
 /// Instantiates ExpectedAttributeValue with the parameterized properties
 /// </summary>
 /// <param name="value">Sets the ExpectedAttributeValue Value property</param>
 public ExpectedAttributeValue(AttributeValue value)
 {
     _value = value;
 }
 /// <summary>
 /// Sets the Value property
 /// </summary>
 /// <param name="value">The value to set for the Value property </param>
 /// <returns>this instance</returns>
 public ExpectedAttributeValue WithValue(AttributeValue value)
 {
     this.value = value;
     return this;
 }
 public CacheAttributeValueWrapper(AttributeValue attributeValue)
 {
     this.AttributeValue = attributeValue;
 }