/// <summary> /// Initializes the provider by pulling the config info from the web.config and validate/create the DynamoDB table. /// If the table is being created this method will block until the table is active. /// </summary> /// <param name="name"></param> /// <param name="config"></param> public override void Initialize(string name, NameValueCollection config) { if (config == null) { throw new ArgumentNullException("config"); } base.Initialize(name, config); GetConfigSettings(config); var region = RegionEndpoint.GetBySystemName(this._regionName); if (!string.IsNullOrEmpty(this._accessKey)) { this._ddbClient = new AmazonDynamoDBClient(this._accessKey, this._secretKey, region); } else { this._ddbClient = new AmazonDynamoDBClient(region); } SetupTable(); }
protected override void OnCreate(Bundle bundle) { base.OnCreate (bundle); // Set our view from the "main" layout resource SetContentView (Android.Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById<Button> (Android.Resource.Id.myButton); button.Click += delegate { Console.WriteLine(); Console.WriteLine("Setting up DynamoDB client"); client = new AmazonDynamoDBClient(RegionEndpoint.USWest2); Console.WriteLine(); Console.WriteLine("Creating sample tables"); CreateSampleTables(); Console.WriteLine(); Console.WriteLine("Running DataModel sample"); RunDataModelSample(); Console.WriteLine(); Console.WriteLine("Running DataModel sample"); RunDocumentModelSample(); Console.WriteLine(); Console.WriteLine("Removing sample tables"); DeleteSampleTables(); Console.WriteLine(); }; }
public static void Main(string[] args) { Console.WriteLine(); Console.WriteLine("Setting up DynamoDB client"); client = new AmazonDynamoDBClient(RegionEndpoint.USWest2); Console.WriteLine(); Console.WriteLine("Creating sample tables"); CreateSampleTables(); Console.WriteLine(); Console.WriteLine("Running DataModel sample"); RunDataModelSample(); Console.WriteLine(); Console.WriteLine("Running DataModel sample"); RunDocumentModelSample(); Console.WriteLine(); Console.WriteLine("Removing sample tables"); DeleteSampleTables(); Console.WriteLine(); Console.WriteLine("Press Enter to continue..."); Console.Read(); }
/// <summary> /// A utility method for cleaning up expired sessions that IIS failed to delete. The method performs a scan on the table /// with a condition that the expiration date is in the past and calls delete on all the keys returned. Scans can be costly on performance /// so use this method sparingly like a nightly or weekly clean job. /// </summary> /// <param name="dbClient">The AmazonDynamoDB client used to find a delete expired sessions.</param> /// <param name="tableName">The table to search.</param> public static void DeleteExpiredSessions(AmazonDynamoDB dbClient, string tableName) { Table table = Table.LoadTable(dbClient, tableName, Table.DynamoDBConsumer.SessionStateProvider); ScanFilter filter = new ScanFilter(); filter.AddCondition(ATTRIBUTE_EXPIRES, ScanOperator.LessThan, DateTime.Now); ScanOperationConfig config = new ScanOperationConfig(); config.AttributesToGet = new List <string>(); config.AttributesToGet.Add(ATTRIBUTE_SESSION_ID); config.Filter = filter; Search search = table.Scan(config); do { List <Document> page = search.GetNextSet(); foreach (var document in page) { table.DeleteItem(document); } } while (!search.IsDone); }
private Table(AmazonDynamoDB ddbClient, string tableName, Table.DynamoDBConsumer consumer) { DDBClient = ddbClient; TableConsumer = consumer; TableName = tableName; HashKeyIsNumeric = RangeKeyIsDefined = RangeKeyIsNumeric = false; }
/// <summary> /// A utility method for cleaning up expired sessions that IIS failed to delete. The method performs a scan on the table /// with a condition that the expiration date is in the past and calls delete on all the keys returned. Scans can be costly on performance /// so use this method sparingly like a nightly or weekly clean job. /// </summary> /// <param name="dbClient">The AmazonDynamoDB client used to find a delete expired sessions.</param> /// <param name="tableName">The table to search.</param> public static void DeleteExpiredSessions(AmazonDynamoDB dbClient, string tableName) { Table table = Table.LoadTable(dbClient, tableName, Table.DynamoDBConsumer.SessionStateProvider); ScanFilter filter = new ScanFilter(); filter.AddCondition(ATTRIBUTE_EXPIRES, ScanOperator.LessThan, DateTime.Now); ScanOperationConfig config = new ScanOperationConfig(); config.AttributesToGet = new List <string> { ATTRIBUTE_SESSION_ID }; config.Select = SelectValues.SpecificAttributes; config.Filter = filter; DocumentBatchWrite batchWrite = table.CreateBatchWrite(); Search search = table.Scan(config); do { List <Document> page = search.GetNextSet(); foreach (var document in page) { batchWrite.AddItemToDelete(document); } } while (!search.IsDone); batchWrite.Execute(); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Android.Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById <Button> (Android.Resource.Id.myButton); button.Click += delegate { Console.WriteLine(); Console.WriteLine("Setting up DynamoDB client"); client = new AmazonDynamoDBClient(RegionEndpoint.USWest2); Console.WriteLine(); Console.WriteLine("Creating sample tables"); CreateSampleTables(); Console.WriteLine(); Console.WriteLine("Running DataModel sample"); RunDataModelSample(); Console.WriteLine(); Console.WriteLine("Running DataModel sample"); RunDocumentModelSample(); Console.WriteLine(); Console.WriteLine("Removing sample tables"); DeleteSampleTables(); Console.WriteLine(); }; }
private Table(AmazonDynamoDB ddbClient, string tableName, Table.DynamoDBConsumer consumer) { DDBClient = ddbClient; TableConsumer = consumer; TableName = tableName; RangeKeyIsDefined = false; HashKeyType = DynamoDBEntryType.String; RangeKeyType = DynamoDBEntryType.String; }
private void CallUntilCompletion(BatchWriteItemRequest request, AmazonDynamoDB client) { do { var batchWriteItemResponse = client.BatchWriteItem(request); var result = batchWriteItemResponse.BatchWriteItemResult; request.RequestItems = result.UnprocessedItems; } while (request.RequestItems.Count > 0); }
private Table(AmazonDynamoDB ddbClient, string tableName, Table.DynamoDBConsumer consumer) { DDBClient = ddbClient; TableConsumer = consumer; TableName = tableName; Keys = new Dictionary<string, KeyDescription>(); HashKeys = new List<string>(); RangeKeys = new List<string>(); LocalSecondaryIndexes = new Dictionary<string, LocalSecondaryIndexDescription>(); LocalSecondaryIndexNames = new List<string>(); Attributes = new List<AttributeDefinition>(); }
/// <summary> /// A utility method for cleaning up expired sessions that IIS failed to delete. The method performs a scan on the table /// with a condition that the expiration date is in the past and calls delete on all the keys returned. Scans can be costly on performance /// so use this method sparingly like a nightly or weekly clean job. /// </summary> /// <param name="dbClient">The AmazonDynamoDB client used to find a delete expired sessions.</param> /// <param name="tableName">The table to search.</param> public static void DeleteExpiredSessions(AmazonDynamoDB dbClient, string tableName) { Table table = Table.LoadTable(dbClient, tableName, Table.DynamoDBConsumer.SessionStateProvider); ScanFilter filter = new ScanFilter(); filter.AddCondition(ATTRIBUTE_EXPIRES, ScanOperator.LessThan, DateTime.Now); ScanOperationConfig config = new ScanOperationConfig(); config.AttributesToGet = new List<string>(); config.AttributesToGet.Add(ATTRIBUTE_SESSION_ID); config.Filter = filter; Search search = table.Scan(config); do { List<Document> page = search.GetNextSet(); foreach (var document in page) { table.DeleteItem(document); } } while (!search.IsDone); }
/// <summary> /// A utility method for cleaning up expired sessions that IIS failed to delete. The method performs a scan on the ASP.NET_SessionState table /// with a condition that the expiration date is in the past and calls delete on all the keys returned. Scans can be costly on performance /// so use this method sparingly like a nightly or weekly clean job. /// </summary> /// <param name="dbClient">The AmazonDynamoDB client used to find a delete expired sessions.</param> public static void DeleteExpiredSessions(AmazonDynamoDB dbClient) { DeleteExpiredSessions(dbClient, DEFAULT_TABLENAME); }
/// <summary> /// Constructor for testing. /// </summary> /// <param name="ddbClient"></param> public DynamoDBSessionStateStore(AmazonDynamoDB ddbClient) { this._ddbClient = ddbClient; SetupTable(); }
/// <summary> /// Creates a Table object with the specified name, using the /// passed-in client to load the table definition. /// /// This method will throw an exception if the table does not exist. /// </summary> /// <param name="ddbClient">Client to use to access DynamoDB.</param> /// <param name="tableName">Name of the table.</param> /// <returns>Table object representing the specified table.</returns> public static Table LoadTable(AmazonDynamoDB ddbClient, string tableName) { Table table = new Table(ddbClient, tableName, Table.DynamoDBConsumer.DocumentModel); table.GetKeyInfo(); return table; }
private void sendDynamoMachineName() { //Image image = Image.FromFile(raw.Text); //System.Drawing.Imaging.ImageFormat format = image.RawFormat; //string picture = ImageToBase64(image, format); string[] SampleTables = new string[] { "Computer", "Index", "Images" }; Console.WriteLine("Getting list of tables"); List<string> currentTables = client.ListTables().ListTablesResult.TableNames; Console.WriteLine("Number of tables: " + currentTables.Count); client = new AmazonDynamoDBClient(RegionEndpoint.USWest2); bool tablesAdded = false; if (!currentTables.Contains("Computer")) { Console.WriteLine("Computer table does not exist, creating"); client.CreateTable(new CreateTableRequest { TableName = "Computer", ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 10, WriteCapacityUnits = 10 }, KeySchema = new KeySchema { HashKeyElement = new KeySchemaElement { AttributeName = "compID", AttributeType = "S" }, } }); tablesAdded = true; } //if (!currentTables.Contains("Index")) //{ // Console.WriteLine("Index table does not exist, creating"); // client.CreateTable(new CreateTableRequest // { // TableName = "Index", // ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 10, WriteCapacityUnits = 10 }, // KeySchema = new KeySchema // { // HashKeyElement = new KeySchemaElement { AttributeName = "indexID", AttributeType = "S" } // } // }); // tablesAdded = true; //} //if (!currentTables.Contains("Images")) //{ // Console.WriteLine("Images table does not exist, creating"); // client.CreateTable(new CreateTableRequest // { // TableName = "Images", // ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 10, WriteCapacityUnits = 10 }, // KeySchema = new KeySchema // { // HashKeyElement = new KeySchemaElement { AttributeName = "imgeID", AttributeType = "S" }, // } // }); // tablesAdded = true; //} if (tablesAdded) { while (true) { bool allActive = true; foreach (var table in SampleTables) { string tableStatus = GetTableStatus(table); bool isTableActive = string.Equals(tableStatus, "ACTIVE", StringComparison.OrdinalIgnoreCase); if (!isTableActive) allActive = false; } if (allActive) { Console.WriteLine("All tables are ACTIVE"); break; } } } //Console.WriteLine("All sample tables created"); //Console.WriteLine("Creating the context object"); DynamoDBContext context = new DynamoDBContext(client); //Console.WriteLine("Creating actors"); Computer newcomputer = new Computer { compID1 = compID, compName1 = machineName }; //Index newIndex = new Index //{ // indexID1 = indexID.Text, // compID2 = CompID.Text, // XMLProfile1 = XML.Text //}; //Images newImage = new Images //{ // imgID1 = ImgID.Text, // indexID1 = indexID.Text, // extension1 = Extension.Text, // location1 = Location.Text, // raw1 = picture //}; }
/// <summary> /// Creates a Table object with the specified name, using the /// passed-in client to load the table definition. /// /// This method will throw an exception if the table does not exist. /// </summary> /// <param name="ddbClient">Client to use to access DynamoDB.</param> /// <param name="tableName">Name of the table.</param> /// <returns>Table object representing the specified table.</returns> public static Table LoadTable(AmazonDynamoDB ddbClient, string tableName) { return LoadTable(ddbClient, tableName, DynamoDBConsumer.DocumentModel); }
/// <summary> /// A utility method for cleaning up expired sessions that IIS failed to delete. The method performs a scan on the table /// with a condition that the expiration date is in the past and calls delete on all the keys returned. Scans can be costly on performance /// so use this method sparingly like a nightly or weekly clean job. /// </summary> /// <param name="dbClient">The AmazonDynamoDB client used to find a delete expired sessions.</param> /// <param name="tableName">The table to search.</param> public static void DeleteExpiredSessions(AmazonDynamoDB dbClient, string tableName) { Table table = Table.LoadTable(dbClient, tableName, Table.DynamoDBConsumer.SessionStateProvider); ScanFilter filter = new ScanFilter(); filter.AddCondition(ATTRIBUTE_EXPIRES, ScanOperator.LessThan, DateTime.Now); ScanOperationConfig config = new ScanOperationConfig(); config.AttributesToGet = new List<string> { ATTRIBUTE_SESSION_ID }; config.Select = SelectValues.SpecificAttributes; config.Filter = filter; DocumentBatchWrite batchWrite = table.CreateBatchWrite(); Search search = table.Scan(config); do { List<Document> page = search.GetNextSet(); foreach (var document in page) { batchWrite.AddItemToDelete(document); } } while (!search.IsDone); batchWrite.Execute(); }
/// <summary> /// Initializes the provider by pulling the config info from the web.config and validate/create the DynamoDB table. /// If the table is being created this method will block until the table is active. /// </summary> /// <param name="name"></param> /// <param name="config"></param> public override void Initialize(string name, NameValueCollection config) { if (config == null) throw new ArgumentNullException("config"); base.Initialize(name, config); GetConfigSettings(config); var region = RegionEndpoint.GetBySystemName(this._regionName); if (!string.IsNullOrEmpty(this._accessKey)) { this._ddbClient = new AmazonDynamoDBClient(this._accessKey, this._secretKey, region); } else { this._ddbClient = new AmazonDynamoDBClient(region); } SetupTable(); }
private void sendDynamoMachineName() { //Image image = Image.FromFile(raw.Text); //System.Drawing.Imaging.ImageFormat format = image.RawFormat; //string picture = ImageToBase64(image, format); string[] SampleTables = new string[] { "Computer", "Index", "Images" }; Console.WriteLine("Getting list of tables"); List <string> currentTables = client.ListTables().ListTablesResult.TableNames; Console.WriteLine("Number of tables: " + currentTables.Count); client = new AmazonDynamoDBClient(RegionEndpoint.USWest2); bool tablesAdded = false; if (!currentTables.Contains("Computer")) { Console.WriteLine("Computer table does not exist, creating"); client.CreateTable(new CreateTableRequest { TableName = "Computer", ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 10, WriteCapacityUnits = 10 }, KeySchema = new KeySchema { HashKeyElement = new KeySchemaElement { AttributeName = "compID", AttributeType = "S" }, } }); tablesAdded = true; } //if (!currentTables.Contains("Index")) //{ // Console.WriteLine("Index table does not exist, creating"); // client.CreateTable(new CreateTableRequest // { // TableName = "Index", // ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 10, WriteCapacityUnits = 10 }, // KeySchema = new KeySchema // { // HashKeyElement = new KeySchemaElement { AttributeName = "indexID", AttributeType = "S" } // } // }); // tablesAdded = true; //} //if (!currentTables.Contains("Images")) //{ // Console.WriteLine("Images table does not exist, creating"); // client.CreateTable(new CreateTableRequest // { // TableName = "Images", // ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 10, WriteCapacityUnits = 10 }, // KeySchema = new KeySchema // { // HashKeyElement = new KeySchemaElement { AttributeName = "imgeID", AttributeType = "S" }, // } // }); // tablesAdded = true; //} if (tablesAdded) { while (true) { bool allActive = true; foreach (var table in SampleTables) { string tableStatus = GetTableStatus(table); bool isTableActive = string.Equals(tableStatus, "ACTIVE", StringComparison.OrdinalIgnoreCase); if (!isTableActive) { allActive = false; } } if (allActive) { Console.WriteLine("All tables are ACTIVE"); break; } } } //Console.WriteLine("All sample tables created"); //Console.WriteLine("Creating the context object"); DynamoDBContext context = new DynamoDBContext(client); //Console.WriteLine("Creating actors"); Computer newcomputer = new Computer { compID1 = compID, compName1 = machineName }; //Index newIndex = new Index //{ // indexID1 = indexID.Text, // compID2 = CompID.Text, // XMLProfile1 = XML.Text //}; //Images newImage = new Images //{ // imgID1 = ImgID.Text, // indexID1 = indexID.Text, // extension1 = Extension.Text, // location1 = Location.Text, // raw1 = picture //}; }
/// <summary> /// Creates a Table object with the specified name, using the /// passed-in client to load the table definition. /// /// This method will return false if the table does not exist. /// </summary> /// <param name="ddbClient">Client to use to access DynamoDB.</param> /// <param name="tableName">Name of the table.</param> /// <param name="table">Loaded table.</param> /// <returns> /// True if table was successfully loaded; otherwise false. /// </returns> public static bool TryLoadTable(AmazonDynamoDB ddbClient, string tableName, out Table table) { try { table = LoadTable(ddbClient, tableName); return true; } catch { table = null; return false; } }
internal static Table LoadTable(AmazonDynamoDB ddbClient, string tableName, Table.DynamoDBConsumer consumer) { Table table = new Table(ddbClient, tableName, consumer); table.GetKeyInfo(); return table; }
private void CallUntilCompletion(BatchWriteItemRequest request, Dictionary <Key, Document> documentMap, AmazonDynamoDB client) { do { var batchWriteItemResponse = client.BatchWriteItem(request); var result = batchWriteItemResponse.BatchWriteItemResult; request.RequestItems = result.UnprocessedItems; Dictionary <Key, Document> unprocessedDocuments = new Dictionary <Key, Document>(keyComparer); foreach (var unprocessedItems in result.UnprocessedItems) { Table table = tableMap[unprocessedItems.Key]; foreach (var writeRequest in unprocessedItems.Value) { if (writeRequest.PutRequest != null) { var key = table.MakeKey(Document.FromAttributeMap(writeRequest.PutRequest.Item)); Document document = null; if (documentMap.TryGetValue(key, out document)) { // Remove unprocessed requests from the document map // and copy them to unprocessed documents. unprocessedDocuments.Add(key, document); documentMap.Remove(key); } } } } // Commit the remaining documents in the document map foreach (var document in documentMap.Values) { document.CommitChanges(); } documentMap = unprocessedDocuments; } while (request.RequestItems.Count > 0); // Commit any remaining documents in document map. // This would only happen if we are not able to match the items sent in the request // with the items returned back as unprocessed items. foreach (var document in documentMap.Values) { document.CommitChanges(); } }