public static LoadTable ( IAmazonDynamoDB ddbClient, string tableName ) : |
||
ddbClient | IAmazonDynamoDB | Client to use to access DynamoDB. |
tableName | string | Name of the table. |
return |
public static List <Document> GetAllDocumentsWithFilter(string tableName, string columnName, string filterValue) { try { AmazonDynamoDBClient client = new AmazonDynamoDBClient(MyAWSConfigs.DynamodbRegion); Table table = Table.LoadTable(client, tableName); ScanFilter scanFilter = new ScanFilter(); scanFilter.AddCondition(columnName, ScanOperator.Equal, filterValue); Search search = table.Scan(scanFilter); List <Document> docs = new List <Document>(); do { docs.AddRange(search.GetNextSet().ToList <Document>()); } while (!search.IsDone); var temp = docs.ToList <Document>(); client.Dispose(); return(temp); } catch (AmazonDynamoDBException e) { Console.WriteLine("AmazonDynamoDBException: " + e); } catch (Exception e) { Console.WriteLine("Error: " + e); } return(null); }
public void loadData() { AmazonDynamoDBClient client = new AmazonDynamoDBClient(Amazon.RegionEndpoint.USEast2); Table table = Table.LoadTable(client, "Users"); string email = TxtUserEmail.Text; string password = TxtPassword.Password; if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) { MessageBox.Show("Fields can't be empty!", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation); } else { Document doc = table.GetItem(email); string emailInput = doc.Values.ElementAt(1); string userPasword = doc.Values.ElementAt(0); string result = emailInput; string pass = userPasword; if (email == result & password == pass) { bookShelf = new BookShelf(); this.bookShelf.UserEmail = emailInput; HomePage homePage = new HomePage(this.bookShelf); homePage.Show(); this.Close(); } else { MessageBox.Show("Incorrect Email or Password entered!"); } } }
private void BtnConfirmDelete_Click(object sender, RoutedEventArgs e) { var tableName = "Cameras"; //load DynamoDB table var table = Table.LoadTable(client, tableName); var item = table.GetItem(DeleteCamId); try { if (item != null) { table.DeleteItem(item); MessageBox.Show("Successfully Deleted!"); } else { MessageBox.Show("There is no such a Camera!"); } MainView mainv = new MainView(); CamerasPageView cams = new CamerasPageView(); mainv.MenuPage.Content = cams; mainv.Show(); } catch (AmazonDynamoDBException ex) { MessageBox.Show("Message : Server Error", ex.Message); } catch (Exception ex) { MessageBox.Show("Message : Unknown Error", ex.Message); } }
private void AddCamera(string camid, string loc, string qlty) { try { string tableName = "Cameras"; var table = Table.LoadTable(client, tableName); var search = table.Scan(new Amazon.DynamoDBv2.DocumentModel.Expression()); if (search.Count != 0) { var item = table.GetItem(camid); if (item == null) { //Console.WriteLine("search = ", search); //Console.WriteLine("search.count = ", search.Count); this.Close(); MessageBox.Show("New Camera Was Successfully Added!"); } else { CreateCameraTable(tableName); MessageBox.Show("Camera ID is already exist! (Please try a different one)"); } Document camObj = new Document(); camObj["camId"] = camid; camObj["location"] = loc; camObj["quality"] = qlty; table.PutItem(camObj); } else { MessageBox.Show("Table scan doesn't gives results"); } MainView mainv = new MainView(); CamerasPageView cams = new CamerasPageView(); mainv.MenuPage.Content = cams; mainv.Show(); } catch (AmazonDynamoDBException ex) { MessageBox.Show("Message : Server Error", ex.Message); } catch (Exception ex) { MessageBox.Show("Message : Unknown Error", ex.Message); } }
protected void LoadData(object obj) { //load DynamoDB table var table = Table.LoadTable(client, "Cameras"); //scan the table for get all details var search = table.Scan(new Amazon.DynamoDBv2.DocumentModel.Expression()); // create DynamoDB document with scanned data var documentList = new List <Document>(); do { documentList.AddRange(search.GetNextSet()); } while (!search.IsDone); // create a Collection //Camera is the name of the model in <Camera>, it is in Models Folder(Camera.cs) var cameras = new ObservableCollection <Camera>(); // getting DynamoDB Document data to Collection foreach (var doc in documentList) { var camera = new Camera(); foreach (var attribute in doc.GetAttributeNames()) { var value = doc[attribute]; if (attribute == "camId") { camera.camId = value.AsPrimitive().Value.ToString(); //Console.WriteLine(camera.camId); } else if (attribute == "location") { camera.location = value.AsPrimitive().Value.ToString(); //Console.WriteLine(camera.location); } else if (attribute == "quality") { camera.quality = value.AsPrimitive().Value.ToString(); //Console.WriteLine("quality",camera.quality); } } //Add camera data to collection cameras.Add(camera); //give itemsource to datagrid in the frontend, DataGrid's name is CamerasDataGrid CamerasDataGrid.ItemsSource = cameras; } }
public bool userExists() { AmazonDynamoDBClient client = new AmazonDynamoDBClient(Amazon.RegionEndpoint.USEast2); Table table = Table.LoadTable(client, "Users"); string email = TxtUserEmail.Text; Document doc = table.GetItem(email); if (doc == null) { userExist = false; } else { userExist = true; } return(userExist); }
//update item query public static void UpdateItem(Document item, string tableName) { try { AmazonDynamoDBClient client; using (client = new AmazonDynamoDBClient(MyAWSConfigs.DynamodbRegion)) { var table = Table.LoadTable(client, tableName); table.UpdateItem(item); } } catch (AmazonDynamoDBException e) { Console.WriteLine("AmazonDynamoDBException: " + e); } catch (Exception e) { Console.WriteLine("Error: " + e); } }
private void UpdateCamera(string cid, string loc, string qlty) { var tableName = "Cameras"; //load DynamoDB table var table = Table.LoadTable(client, tableName); var item = table.GetItem(cid); try { //Console.WriteLine(item["aPassword"]); if (item != null) { Document camObj = new Document(); camObj["camId"] = cid; camObj["location"] = loc; camObj["quality"] = qlty; table.PutItem(camObj); MessageBox.Show("Successfully Updated!"); } else { MessageBox.Show("There is no such a Camera!"); } MainView mainv = new MainView(); CamerasPageView cams = new CamerasPageView(); mainv.MenuPage.Content = cams; mainv.Show(); } catch (AmazonDynamoDBException ex) { MessageBox.Show("Message : Server Error", ex.Message); } catch (Exception ex) { MessageBox.Show("Message : Unknown Error", ex.Message); } }
private void searchTravelPackageButton_Click(object sender, RoutedEventArgs e) { SecondWindow f2 = new SecondWindow(); f2.destinationLabel.Content = "Destination: " + destinationSelectionBox.SelectionBoxItem; f2.budgetLabel.Content = "Budget: $" + budgetTextBox.Text; f2.Show(); Close(); Table table = Table.LoadTable(client, "Travels"); var travel = new Document(); int bgt = int.Parse(budgetTextBox.Text); String des = (string)destinationSelectionBox.SelectionBoxItem; travel["Budget"] = bgt; travel["Destination"] = des; table.PutItem(travel); }
public static Document GetItem(String itemId, string tableName) { try { AmazonDynamoDBClient client; using (client = new AmazonDynamoDBClient(MyAWSConfigs.DynamodbRegion)) { var table = Table.LoadTable(client, tableName); Document item = table.GetItem(itemId); return(item); } } catch (AmazonDynamoDBException e) { Console.WriteLine("AmazonDynamoDBException: " + e); return(new Document()); } catch (Exception e) { Console.WriteLine("Error: " + e); return(new Document()); } }
private void GiveRedersToRefernces(List <String> refList, String readerId) { try { Console.WriteLine(readerId); foreach (String chkd_ref in refList) { string tableName = MyAWSConfigs.RefPersonsDBTableName; Table table = Table.LoadTable(client, tableName); Console.WriteLine("\n*** Executing UpdateMultipleAttributes() ***"); Console.WriteLine("\nUpdating multiple attributes...."); string partitionKey = chkd_ref; Document doc = new Document(); doc["id"] = partitionKey; // List of attribute updates. // The following replaces the existing authors list. Item item = table.GetItem(chkd_ref); Console.WriteLine(item["id"]); //Console.WriteLine(item["readerList"]); List <string> readersList = new List <string>(); if (item["readerList"] != null) { readersList = item["readerList"].AsListOfString(); var match = readersList.FirstOrDefault(stringToCheck => stringToCheck.Contains(readerId)); if (match != null) { readersList.Add(readerId); foreach (string i in readersList) { Console.WriteLine("reader !match >>>>>> " + i); } doc["readerList"] = readersList; // Optional parameters. UpdateItemOperationConfig config = new UpdateItemOperationConfig { // Get updated item in response. ReturnValues = ReturnValues.AllNewAttributes }; Document updatedadmin = table.UpdateItem(doc, config); Console.WriteLine("UpdateMultipleAttributes: Printing item after updates ..."); //MessageBox.Show("Successfully Updated! not null"); } else { readersList.Add(readerId); foreach (string i in readersList) { Console.WriteLine("reader match >>>>>> " + i); } doc["readerList"] = readersList; // Optional parameters. UpdateItemOperationConfig config = new UpdateItemOperationConfig { // Get updated item in response. ReturnValues = ReturnValues.AllNewAttributes }; Document updatedadmin = table.UpdateItem(doc, config); Console.WriteLine("UpdateMultipleAttributes: Printing item after updates ..."); //MessageBox.Show("Successfully Updated! not null"); } } else { foreach (string i in readersList) { Console.WriteLine("reader null >>>>>> " + i); } doc["readerList"] = readersList; // Optional parameters. UpdateItemOperationConfig config = new UpdateItemOperationConfig { // Get updated item in response. ReturnValues = ReturnValues.AllNewAttributes }; Document updatedadmin = table.UpdateItem(doc, config); Console.WriteLine("UpdateMultipleAttributes: Printing item after updates ..."); MessageBox.Show("Successfully Updated! null"); } } } catch (AmazonDynamoDBException ex) { MessageBox.Show("Message : Server Error", ex.Message); } catch (Exception ex) { //MessageBox.Show("Message : Unknown Error- Updating Refs", ex.Message); } finally { } }
private async void ButtonSubmit_Click(object sender, RoutedEventArgs e) { //MessageBox.Show("this is submit button"); String name = txtName.Text; //MessageBox.Show(name); try { bool isNameEmpty = string.IsNullOrEmpty(txtName.Text); bool isPhoneEmpty = string.IsNullOrEmpty(txtPhone.Text); bool isDescriptionEmpty = string.IsNullOrEmpty(txtDescription.Text); bool isFilePathEmpty = string.IsNullOrEmpty(uploadFilePath); bool isFileIdEmpty = string.IsNullOrEmpty(txtId.Text); if (!isNameEmpty && !isDescriptionEmpty && !isPhoneEmpty) { string tableName = MyAWSConfigs.ReaderDBtableName; Table table = Table.LoadTable(client, tableName); ProgressDialogController controller = await this.ShowProgressAsync("Please wait...", ""); controller.SetIndeterminate(); controller.SetCancelable(false); string partitionKey = txtId.Text; Console.WriteLine("oooooooooooooooooooooooooooooooo" + partitionKey); var item = new Document(); Document doc = new Document(); doc["id"] = partitionKey; doc["name"] = txtName.Text; doc["phone"] = txtPhone.Text; doc["description"] = txtDescription.Text; /////////////////////////////////////////////////// //#ToDo : Add readerList //item["readerList"] = readerList; UpdateItemOperationConfig config = new UpdateItemOperationConfig { // Get updated item in response. ReturnValues = ReturnValues.AllNewAttributes }; if (uploadFilePath != null) { string[] temp = uploadFilePath.Split('.'); string BaseDirectoryPath = AppDomain.CurrentDomain.BaseDirectory; string filePath = BaseDirectoryPath + $"Resources\\Images\\{partitionKey}"; item = table.GetItem(partitionKey); 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 controller.SetMessage("Deleting File"); await Task.Run(() => S3Bucket.DeleteFile(oldImage, MyAWSConfigs.RefImagesBucketName)); controller.SetMessage("Uploading file"); await Task.Run(() => Models.S3Bucket.UploadFile(uploadFilePath, partitionKey, Models.MyAWSConfigs.RefImagesBucketName)); } controller.SetMessage("Adding database record"); await Task.Run(() => table.UpdateItem(doc, config)); Console.WriteLine("UpdateMultipleAttributes: Printing item after updates ..."); //MessageBox.Show("Successfully Updated!"); await controller.CloseAsync(); await this.ShowMessageAsync("Success", "Person Updated !", MessageDialogStyle.Affirmative); } else { await this.ShowMessageAsync("Error", "Please check all fields", MessageDialogStyle.Affirmative); } } catch { await this.ShowMessageAsync("Error", "Task not completed", MessageDialogStyle.Affirmative); } }
/// <summary> /// Gets the DynamoDB table /// </summary> /// <param name="tableName"></param> /// <returns></returns> private async Task <DynamoDbTable> TableWithName(string tableName) { var hashKeyName = TableConfigProvider.GetTableHashKeyName(tableName); var rangeKeyName = TableConfigProvider.GetTableRangeKeyName(tableName); Logger.Debug("Checking if table '{0}' exists in DynamoDB...", tableName); try { if (!DynamoDbTable.TryLoadTable(DynamoDb, tableName, out var table)) { // if we failed to load the table, this is basically a retry that will throw an exception. // The expectation is that this will expose whatever error caused the TryLoadTable method // to return false, but if for some reason it happens to succed on retry, that also works. if (!TableConfigProvider.CreateIfNotExists) { return(DynamoDbTable.LoadTable(DynamoDb, tableName)); } //throw new Exception($"Table {tableName} does not exist in DynamoDB."); Logger.Info("Table '{0}' does not exist in DynamoDB. Creating it now...", tableName); var createResp = await DynamoDb.CreateTableAsync(tableName, new List <KeySchemaElement> { new KeySchemaElement { AttributeName = hashKeyName, KeyType = KeyType.HASH }, new KeySchemaElement { AttributeName = rangeKeyName, KeyType = KeyType.RANGE } }, new List <AttributeDefinition> { new AttributeDefinition { AttributeName = hashKeyName, AttributeType = ScalarAttributeType.S }, new AttributeDefinition { AttributeName = rangeKeyName, AttributeType = ScalarAttributeType.S } }, new ProvisionedThroughput(1, 1)); if (createResp.HttpStatusCode != HttpStatusCode.OK) { throw new Exception($"Failed to create table '{tableName}' in DynamoDB. Response code is {createResp.HttpStatusCode}."); } Logger.Info("Successfully created DynamoDB table '{0}'.", tableName); table = DynamoDbTable.LoadTable(DynamoDb, tableName); } return(table); } catch (Exception exception) { Logger.Error($"An error occurred loading the DynamoDB table for type {tableName}.", exception); throw; } }