public Scan ( |
||
request | Container for the necessary parameters to execute the Scan service method. | |
return |
public void InstantiateIn(System.Web.UI.Control container) { AmazonDynamoDBClient client = new AmazonDynamoDBClient(); // string tableName = "Attendee"; var request = new ScanRequest { TableName = "QuizQuestion", }; var response = client.Scan(request); List<QuestionData> questionDataList = new List<QuestionData>(); foreach (Dictionary<string, AttributeValue> item in response.ScanResult.Items) { // Process the result. QuestionData question = new QuestionData(); if (item.ContainsKey("options")) { foreach (var itemNew in item["options"].M) { Label link = new Label(); link.ID = "linkmodel"; container.Controls.Add(link); link.Text = itemNew.Value.S; //Label value = questionData.FindControl("options") as Label; ////testM = itemNew.Key.ToString(); //value.Text = itemNew.Value.S; } } } }
public List<Dictionary<string, object>> GetPinWithUserIDs(List<string> userIDs, double since, int takeCnt) { List<Dictionary<string, object>> retval = new List<Dictionary<string, object>>(); Dictionary<string, object> tmpObject = null; var config = new AmazonDynamoDBConfig(); config.ServiceURL = System.Configuration.ConfigurationManager.AppSettings["ServiceURL"]; client = new AmazonDynamoDBClient(config); List<AttributeValue> users = new List<AttributeValue>(); foreach (string item in userIDs) { users.Add(new AttributeValue() { S = item }); } try { ScanRequest sreq = new ScanRequest() { TableName = "Pin", ScanFilter = new Dictionary<string, Condition>() { { "Owner", new Condition { ComparisonOperator = ComparisonOperator.IN, AttributeValueList = users } }, { "PinDate", new Condition() { ComparisonOperator = ComparisonOperator.LT, AttributeValueList = new List<AttributeValue> { new AttributeValue { N = since.ToString() } } } } } }; var response = client.Scan(sreq); foreach (var item in response.Items) { tmpObject = new Dictionary<string, object>(); tmpObject.Add("Title", item["Title"].S); tmpObject.Add("Owner", item["Owner"].S); tmpObject.Add("OwnerName", item["UserName"].S); tmpObject.Add("OwnerHeadshot", item["HeadshotURL"].S); tmpObject.Add("Latitude", item["Latitude"].S); tmpObject.Add("Longitude", item["Longitude"].S); tmpObject.Add("PinDate", Convert.ToDouble(item["PinDate"].N)); tmpObject.Add("Images", item["Images"].SS); retval.Add(tmpObject); } retval = retval.OrderByDescending(a => a["PinDate"]).ToList<Dictionary<string, object>>(); } catch (AmazonDynamoDBException e) { Console.WriteLine(e.Message); } catch (AmazonServiceException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } return retval; }
private static void SelectSpecificAttributes(AmazonDynamoDBClient client, DynamoDBContext context) { var selectQuery = string.Format("SELECT GameTitle, TopScoreDateTime FROM GameScores WHERE GameTitle = \"{0}\"", StarshipX); Console.WriteLine("(AmazonDynamoDBClient) Running basic scan :\n\t\t{0}", selectQuery); var response = client.Scan(selectQuery); Debug.Assert(response.Items.Count == 1000); Debug.Assert(response.Items.TrueForAll(i => i["GameTitle"].S == StarshipX)); Debug.Assert(response.Items.TrueForAll(i => i.Count == 2)); Console.WriteLine("(DynamoDBContext) Running basic scan :\n\t\t{0}", selectQuery); var gameScores = context.ExecScan<GameScore>(selectQuery).ToArray(); Debug.Assert(gameScores.Count() == 1000); Debug.Assert(gameScores.All(gs => gs.GameTitle == StarshipX)); Debug.Assert(gameScores.All(gs => gs.TopScoreDateTime > default(DateTime) && gs.Wins == 0 && gs.Losses == 0 && gs.TopScore == 0 && String.IsNullOrWhiteSpace(gs.UserId))); }
private static void ScanWithNoReturnedConsumedCapacity(AmazonDynamoDBClient client) { var selectQuery = string.Format("SELECT * FROM GameScores WHERE GameTitle = \"{0}\" WITH (NoReturnedCapacity)", StarshipX); Console.WriteLine("(AmazonDynamoDBClient) Running scan with NoReturnedCapacity :\n\t\t{0}", selectQuery); var response = client.Scan(selectQuery); Debug.Assert(response.Items.Count == 1000); Debug.Assert(response.Items.TrueForAll(i => i["GameTitle"].S == StarshipX)); Debug.Assert(response.ConsumedCapacity == null); }
private static void ScanWithScanPageSizeAndSegments(AmazonDynamoDBClient client, DynamoDBContext context) { var selectQuery = string.Format("SELECT * FROM GameScores WHERE GameTitle = \"{0}\" WITH (PageSize(20), Segments(2))", StarshipX); Console.WriteLine("(AmazonDynamoDBClient) Running scan with PageSize and 2 segments :\n\t\t{0}", selectQuery); var response = client.Scan(selectQuery); Debug.Assert(response.Items.Count == 1000); Debug.Assert(response.Items.TrueForAll(i => i["GameTitle"].S == StarshipX)); Console.WriteLine("(DynamoDBContext) Running scan with PageSize and 2 segments :\n\t\t{0}", selectQuery); var gameScores = context.ExecScan<GameScore>(selectQuery).ToArray(); Debug.Assert(gameScores.Count() == 1000); Debug.Assert(gameScores.All(gs => gs.GameTitle == StarshipX)); }
private static void BasicScan(AmazonDynamoDBClient client, DynamoDBContext context) { var selectQuery = string.Format("SELECT * FROM GameScores WHERE GameTitle = \"{0}\"", StarshipX); Console.WriteLine("(AmazonDynamoDBClient) Running basic scan :\n\t\t{0}", selectQuery); var response = client.Scan(selectQuery); Debug.Assert(response.Items.Count == 1000); Debug.Assert(response.Items.TrueForAll(i => i["GameTitle"].S == StarshipX)); Console.WriteLine("(DynamoDBContext) Running basic scan :\n\t\t{0}", selectQuery); var gameScores = context.ExecScan<GameScore>(selectQuery).ToArray(); Debug.Assert(gameScores.Count() == 1000); Debug.Assert(gameScores.All(gs => gs.GameTitle == StarshipX)); }
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 } }
public virtual List<Dictionary<string, AttributeValue>> GetImageItems(AmazonDynamoDBClient dynamoDbClient) { try { string tableName = ConfigurationManager.AppSettings["SESSIONTABLE"]; string keyPrefix = ConfigurationManager.AppSettings["PARAM3"]; var scanRequest = new ScanRequest { Select = "ALL_ATTRIBUTES", TableName = tableName }; // If the filter criteria is empty, then don't filter it. if (!String.IsNullOrEmpty(keyPrefix)) { scanRequest.ScanFilter = new Dictionary<string, Condition> { { "Key", new Condition { ComparisonOperator = "BEGINS_WITH", AttributeValueList = new List<AttributeValue> { new AttributeValue {S = keyPrefix} } } } }; } return dynamoDbClient.Scan(scanRequest).Items; } catch (Exception ex) { _Default.LogMessageToPage("GetImageItems Error: {0}", ex.Message); return null; } }