public async Task ShowProfileData(string myid) { progressBar.Visibility = Visibility.Visible; try { //Console.WriteLine("name vvvvv- - - ", myid); ////Console.WriteLine(aPassword); try { tableName = MyAWSConfigs.AdminDBTableName; item = Dynamodb.GetItem(myid, tableName); //Console.WriteLine(item["aPassword"]); //check item is there if (item != null) { //Console.WriteLine("name - - - ", item["aName"]); AdminName.Text = item["aName"]; AdminPhone.Text = item["aPhone"]; AdminEMail.Text = item["aId"]; //set pro pic to image string imagename = item["aPropic"]; await Task.Run(() => Models.S3Bucket.DownloadFile(imagename, MyAWSConfigs.AdminS3BucketName)); var BaseDirectoryPath = AppDomain.CurrentDomain.BaseDirectory; string filePath = BaseDirectoryPath + $"Resources/Images/{imagename}"; AdminDp.Source = new BitmapImage(new Uri(filePath)); AdminType.Text = "Non-Root Admin"; //check admin is root or not if (item["root"].AsBoolean() == true) { AdminType.Text = "Root Admin - Only you can access other Admins data"; } } else { MessageBox.Show("Can not Load Data!!!"); } } catch (AmazonDynamoDBException ex) { MessageBox.Show("Message : Server Error", ex.Message); } catch (Exception ex) { MessageBox.Show("Message : Unknown Error", ex.Message); } } finally { Mouse.OverrideCursor = null; } }
private async void ButtonSubmit_Click(object sender, RoutedEventArgs e) { try { bool isFilePathEmpty = string.IsNullOrEmpty(uploadFilePath); if (!isFilePathEmpty) { ProgressDialogController controller = await this.ShowProgressAsync("Please wait...", "Uploading data"); controller.SetIndeterminate(); controller.SetCancelable(false); string[] temp = uploadFilePath.Split('.'); string fileId = $"{myId}.{temp[temp.Length - 1]}"; string BaseDirectoryPath = AppDomain.CurrentDomain.BaseDirectory; string filePath = BaseDirectoryPath + $"Resources\\Images\\{fileId}"; Item item = Dynamodb.GetItem(myId, MyAWSConfigs.AdminDBTableName); string oldImage = item["aPropic"]; Console.WriteLine("><><><><><><><><><><>" + oldImage); //Delete old profile pic in local //string oldFilePath = BaseDirectoryPath + $"Resources\\Images\\{oldImage}"; //DeleteOldPic(oldFilePath); //Delete old profile pic in s3Bucket S3Bucket.DeleteFile(oldImage, MyAWSConfigs.AdminS3BucketName); item["aPropic"] = fileId; await Task.Run(() => Models.S3Bucket.UploadFile(uploadFilePath, fileId, MyAWSConfigs.AdminS3BucketName)); MessageBox.Show(fileId); await Task.Run(() => Models.Dynamodb.UpdateItem(item, Models.MyAWSConfigs.AdminDBTableName)); await controller.CloseAsync(); await this.ShowMessageAsync("Success", "Changed Successfully..", MessageDialogStyle.Affirmative); //activity recorded Models.ActivityLogs.Activity(Models.Components.AdminComponent, "User Changed Profile Picture"); //imgUploadImage.Source = null; } else { await this.ShowMessageAsync("Error", "Please check all fields", MessageDialogStyle.Affirmative); } } catch { await this.ShowMessageAsync("Error", "Task not completed", MessageDialogStyle.Affirmative); } }
public void MoveSingleImageForReview() { var dynamoDbClient = GalleryAwsCredentialsFactory.ProductionDbClient; var modelResult = dynamoDbClient.GetItemAsync(new ClassificationModel().GetTable(), new ClassificationModel { Source = MinistereDeLaCultureIndexer.SourceMinistereDeLaCulture, PageId = "000PE024954" }.GetKey()).Result; var model = JsonConvert.DeserializeObject <ClassificationModel>(Document.FromAttributeMap(modelResult.Item).ToJson()); var s3Client = GalleryAwsCredentialsFactory.S3Client; new ReviewProcess().MoveForReview(dynamoDbClient, GalleryAwsCredentialsFactory.ElasticSearchClient, s3Client, model); }
public static Amazon.DynamoDBv2.DocumentModel.Document ObjectToDoc(User user) { var item = new Amazon.DynamoDBv2.DocumentModel.Document(); item["first_name"] = user.Firstname; item["last_name"] = user.Lastname; item["email"] = user.Email; item["family_group"] = user.FamilyGroup; item["date_created"] = user.DateCreated; item["last_updated"] = user.LastUpdated; item["last_login_date"] = user.LastLoginDate; return(item); }
public static Amazon.DynamoDBv2.DocumentModel.Document ObjectToDoc(Album album) { var item = new Amazon.DynamoDBv2.DocumentModel.Document(); item["partition_key"] = album.Partition_Key; item["sort_key"] = "alb"; item["owner"] = album.Owner; item["year"] = album.Year; item["id"] = album.Id; item["name"] = album.Name; item["datecreated"] = album.DateCreated; item["last_modified_date"] = album.LastUpdated; item["photocount"] = album.PhotoCount; return(item); }
private void ButtonMenuAdmins_Click(object sender, RoutedEventArgs e) { Item item = Models.Dynamodb.GetItem(adminId, Models.MyAWSConfigs.AdminDBTableName); if (item["root"].AsBoolean() == true) { MenuPage.Content = admins; lblTitle.Content = "ADMINS"; admins.LoadData().ConfigureAwait(false); } else { MessageBox.Show("Only the Root-Admin can Access the this section"); } ButtonMenuAdmins.Background = Brushes.MediumSeaGreen; adminIcon.Foreground = Brushes.White; adminLable.Foreground = Brushes.White; ButtonMenuPeopleIn.Background = null; historyIcon.Foreground = Brushes.MediumSeaGreen; historyLable.Foreground = Brushes.MediumSeaGreen; ButtonMenuHome.Background = null; homeIcon.Foreground = Brushes.MediumSeaGreen; homeLable.Foreground = Brushes.MediumSeaGreen; ButtonMenuAllPeople.Background = null; refIcon.Foreground = Brushes.MediumSeaGreen; refLable.Foreground = Brushes.MediumSeaGreen; ButtonMenuReaders.Background = null; readerIcon.Foreground = Brushes.MediumSeaGreen; readerLable.Foreground = Brushes.MediumSeaGreen; ButtonMenuCameras.Background = null; cameraIcon.Foreground = Brushes.MediumSeaGreen; cameraLable.Foreground = Brushes.MediumSeaGreen; ButtonMenuActivityLogs.Background = null; logsIcon.Foreground = Brushes.MediumSeaGreen; logsLable.Foreground = Brushes.MediumSeaGreen; admins.LoadData().ConfigureAwait(false); }
public void MoveImagesNotInPublicDomain() { const int thresholdYear = 1924; // https://fairuse.stanford.edu/overview/public-domain/ var request = new QueryRequest(new ClassificationModel().GetTable()) { ScanIndexForward = true, ExpressionAttributeValues = new Dictionary <string, AttributeValue> { { ":source", new AttributeValue { S = Constants.SOURCE_THE_ATHENAEUM } } }, ExpressionAttributeNames = new Dictionary <string, string> { { "#source", "source" } }, KeyConditionExpression = "#source = :source" }; var dynamoDbClient = GalleryAwsCredentialsFactory.ProductionDbClient; var elasticSearchClient = GalleryAwsCredentialsFactory.ElasticSearchClient; var s3Client = GalleryAwsCredentialsFactory.S3Client; QueryResponse response = null; do { if (response != null) { request.ExclusiveStartKey = response.LastEvaluatedKey; } response = dynamoDbClient.QueryAsync(request).Result; foreach (var item in response.Items) { var model = JsonConvert.DeserializeObject <ClassificationModel>(Document.FromAttributeMap(item).ToJson()); if (!int.TryParse(model.Date, out int parsedYear)) { Console.WriteLine("Unknown date: " + model.Date); } else if (parsedYear > thresholdYear) { new ReviewProcess().MoveForReview(dynamoDbClient, elasticSearchClient, s3Client, model); Thread.Sleep(200); } } } while (response.LastEvaluatedKey.Any()); }
public void MoveClassificationsWithoutImageData() { var elasticSearchClient = GalleryAwsCredentialsFactory.ElasticSearchClient; var dynamoDbClient = GalleryAwsCredentialsFactory.ProductionDbClient; var s3Client = GalleryAwsCredentialsFactory.S3Client; var request = new ScanRequest(new ClassificationModel().GetTable()) { FilterExpression = "attribute_not_exists(orientation)" }; var response = dynamoDbClient.ScanAsync(request).Result; Parallel.ForEach(response.Items, new ParallelOptions { MaxDegreeOfParallelism = 10 }, item => { var modelJson = Document.FromAttributeMap(item).ToJson(); var classification = JsonConvert.DeserializeObject <ClassificationModel>(modelJson); var metaData = s3Client.GetObjectMetadataAsync(Constants.IMAGES_BUCKET, classification.S3Path).Result; if (metaData.ContentLength == 0) { new ReviewProcess().MoveForReview(dynamoDbClient, elasticSearchClient, s3Client, classification); } }); }
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 } }
private async void BtnChangePropic_Click(object sender, RoutedEventArgs e) { //ChangeAdminPropic changeAdminPassword = new ChangeAdminPropic(myId); //changeAdminPassword.ShowDialog(); OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Image files | *.jpg; *.jpeg; *.png"; openFileDialog.FilterIndex = 1; openFileDialog.Multiselect = false; //open file dialog if (openFileDialog.ShowDialog() == true) { uploadFilePath = openFileDialog.FileName; AdminDp.Source = null; } try { bool isFilePathEmpty = string.IsNullOrEmpty(uploadFilePath); if (!isFilePathEmpty) { tableName = MyAWSConfigs.AdminDBTableName; string[] temp = uploadFilePath.Split('.'); string fileId = $"{myId}.{temp[temp.Length - 1]}"; string BaseDirectoryPath = AppDomain.CurrentDomain.BaseDirectory; //get current dp name item = Dynamodb.GetItem(myId, tableName); string oldImage = item["aPropic"]; Console.WriteLine("><><><><><><><><><><>" + oldImage); //Delete old profile pic in local string oldFilePath = BaseDirectoryPath + $"Resources\\Images\\{oldImage}"; DeleteOldPic(oldFilePath); //Delete old profile pic in s3Bucket S3Bucket.DeleteFile(oldImage, MyAWSConfigs.AdminS3BucketName); item["aPropic"] = fileId; //activity recorded Models.ActivityLogs.Activity(Models.Components.AdminComponent, "User Changed Profile Picture"); await Task.Run(() => S3Bucket.UploadFile(uploadFilePath, fileId, MyAWSConfigs.AdminS3BucketName)); MessageBox.Show("Success", "Successfully Updated!"); } else { MessageBox.Show("Error", "Please check all fields"); } } catch { MessageBox.Show("Error", "Task not completed"); } }
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 } }