/*-------------------------------------------------------------------------- * checkingTableExistence_async *--------------------------------------------------------------------------*/ static async Task <bool> checkingTableExistence_async(string tblNm) { DescribeTableResponse descResponse; operationSucceeded = false; operationFailed = false; ListTablesResponse tblResponse = await Ddb_Intro.client.ListTablesAsync(); if (tblResponse.TableNames.Contains(tblNm)) { Console.WriteLine(" A table named {0} already exists in DynamoDB!", tblNm); // If the table exists, get its description try { descResponse = await Ddb_Intro.client.DescribeTableAsync(Ddb_Intro.movies_table_name); operationSucceeded = true; } catch (Exception ex) { Console.WriteLine(" However, its description is not available ({0})", ex.Message); Ddb_Intro.moviesTableDescription = null; operationFailed = true; return(true); } Ddb_Intro.moviesTableDescription = descResponse.Table; return(true); } return(false); }
/*-------------------------------------------------------------------------- * checkingTableExistence_async *--------------------------------------------------------------------------*/ public async Task <bool> checkingTableExistence_async(string tblNm) { DescribeTableResponse descResponse; ListTablesResponse tblResponse = await client.ListTablesAsync(); if (tblResponse.TableNames.Contains(tblNm)) { Console.WriteLine(" A table named {0} already exists in DynamoDB!", tblNm); // If the table exists, get its description try { descResponse = await client.DescribeTableAsync(tblNm); } catch (Exception ex) { throw new Exception($" However, its description is not available ({ex.Message})"); } Console.WriteLine(" Status of the table: '{0}'.", descResponse.Table.TableStatus); return(true); } return(false); }
public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems) { AmazonTimestreamWriteConfig config = new AmazonTimestreamWriteConfig(); config.RegionEndpoint = region; ConfigureClient(config); AmazonTimestreamWriteClient client = new AmazonTimestreamWriteClient(creds, config); ListTablesResponse resp = new ListTablesResponse(); do { ListTablesRequest req = new ListTablesRequest { NextToken = resp.NextToken , MaxResults = maxItems }; resp = client.ListTables(req); CheckError(resp.HttpStatusCode, "200"); foreach (var obj in resp.Tables) { AddObject(obj); } }while (!string.IsNullOrEmpty(resp.NextToken)); }
public async Task <bool> Exists() { CredentialProfileOptions options = new CredentialProfileOptions(); Settings settings = Settings.Load(); options.AccessKey = settings.DBKey; options.SecretKey = settings.DBSecret; CredentialProfile profile = new CredentialProfile("Default", options); profile.Region = RegionEndpoint.APSoutheast2; SharedCredentialsFile sharedFile = new SharedCredentialsFile(); sharedFile.RegisterProfile(profile); AmazonDynamoDBConfig dbConfig = new AmazonDynamoDBConfig(); this.client = new AmazonDynamoDBClient(dbConfig); ListTablesResponse listTablesResponse = await this.client.ListTablesAsync(); return(listTablesResponse.TableNames.Contains(this.InternalName)); }
private TableDescriptionSource SetupPagingTest() { var firstTableName = "Table-1"; _firstPage = new ListTablesResponse { LastEvaluatedTableName = firstTableName, TableNames = new List <string> { firstTableName } }; var secondTableName = "Table-2"; _secondPage = new ListTablesResponse { LastEvaluatedTableName = secondTableName, TableNames = new List <string> { secondTableName } }; _thirdPage = new ListTablesResponse { TableNames = new List <string> { "Table-3" } }; var describeSecondTableResponse = new DescribeTableResponse { Table = new TableDescription { TableName = secondTableName } }; var dynamoDbMock = new Mock <IAmazonDynamoDB>(); dynamoDbMock.Setup(s => s.ListTablesAsync( It.Is <string>(r => r == null), It.IsAny <CancellationToken>() )).ReturnsAsync(_firstPage); dynamoDbMock.Setup(s => s.ListTablesAsync( It.Is <string>(r => r == firstTableName), It.IsAny <CancellationToken>() )).ReturnsAsync(_secondPage); dynamoDbMock.Setup(s => s.ListTablesAsync( It.Is <string>(r => r == secondTableName), It.IsAny <CancellationToken>() )).ReturnsAsync(_thirdPage); dynamoDbMock.Setup(s => s.DescribeTableAsync(It.Is <string>(r => r == secondTableName), It.IsAny <CancellationToken>())) .ReturnsAsync(describeSecondTableResponse); return(new TableDescriptionSource(dynamoDbMock.Object)); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { ListTablesResponse response = new ListTablesResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("LastEvaluatedTableName", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.LastEvaluatedTableName = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("TableNames", targetDepth)) { var unmarshaller = new ListUnmarshaller <string, StringUnmarshaller>(StringUnmarshaller.Instance); response.TableNames = unmarshaller.Unmarshall(context); continue; } } return(response); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { ListTablesResponse response = new ListTablesResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("nextToken", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.NextToken = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("tables", targetDepth)) { var unmarshaller = new ListUnmarshaller <TableSummary, TableSummaryUnmarshaller>(TableSummaryUnmarshaller.Instance); response.Tables = unmarshaller.Unmarshall(context); continue; } } return(response); }
public async Task ListTables() { Console.WriteLine("Listing Tables"); try { var listTablesRequest = new ListTablesRequest { MaxResults = 5, DatabaseName = Constants.DATABASE_NAME }; ListTablesResponse response = await writeClient.ListTablesAsync(listTablesRequest); PrintTables(response.Tables); string nextToken = response.NextToken; while (nextToken != null) { listTablesRequest.NextToken = nextToken; response = await writeClient.ListTablesAsync(listTablesRequest); PrintTables(response.Tables); nextToken = response.NextToken; } } catch (Exception e) { Console.WriteLine("List table failed:" + e.ToString()); } }
/// <summary> /// Save attribute information. /// </summary> /// <param name="attributes">Must have, at least, the URN property</param> /// <returns></returns> public async Task <bool> SaveAttributes(Model.Attributes attributes) { ListTablesResponse existingTables = await client.ListTablesAsync(); if (!existingTables.TableNames.Contains(TABLE_NAME)) { await SetupTable(client, TABLE_NAME, "URN"); } try { // create a generic dictionary Dictionary <string, DynamoDBEntry> dic = new Dictionary <string, DynamoDBEntry>(); dic.Add("URN", attributes.URN); dic.Add("Data", attributes.Data.ToString()); // save as a DynamoDB document Table table = Table.LoadTable(client, TABLE_NAME); Document document = new Document(dic); await table.PutItemAsync(document); // all good! return(true); } catch (Exception ex) { Console.WriteLine("Error saving attributes: " + ex.Message); } return(false); }
public async Task <List <Model.ObjectCode> > List(string parentObjectCodeId) { ListTablesResponse existingTables = await client.ListTablesAsync(); if (!existingTables.TableNames.Contains(TABLE_NAME)) { await SetupTable(client, TABLE_NAME, "CodeId"); } try { List <ScanCondition> filter = new List <ScanCondition>() { new ScanCondition("ParentId", ScanOperator.Equal, parentObjectCodeId.ToUpper()) }; AsyncSearch <Model.ObjectCode> scan = DDBContext.ScanAsync <Model.ObjectCode>(filter); List <Model.ObjectCode> documentList = new List <Model.ObjectCode>(); do { documentList.AddRange(await scan.GetNextSetAsync()); } while (!scan.IsDone); return(documentList); } catch (Exception ex) { Console.WriteLine("Error listing object codes: " + ex.Message); } return(null); }
public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems) { AmazonDynamoDBConfig config = new AmazonDynamoDBConfig(); config.RegionEndpoint = region; ConfigureClient(config); AmazonDynamoDBClient client = new AmazonDynamoDBClient(creds, config); ListTablesResponse resp = new ListTablesResponse(); do { ListTablesRequest req = new ListTablesRequest { ExclusiveStartTableName = resp.LastEvaluatedTableName , Limit = maxItems }; resp = client.ListTables(req); CheckError(resp.HttpStatusCode, "200"); foreach (var obj in resp.TableNames) { AddObject(obj); } }while (!string.IsNullOrEmpty(resp.LastEvaluatedTableName)); }
public async Task RegisterAsync() { _tables = await _dynamoDB.ListTablesAsync(); await CreateTableCard(); await CreateTableEvent(); await CreateTablePerson(); await CreateTableCompany(); }
public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { ListTablesResponse response = new ListTablesResponse(); context.Read(); UnmarshallResult(context, response); return(response); }
public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { ListTablesResponse response = new ListTablesResponse(); context.Read(); response.ListTablesResult = ListTablesResultUnmarshaller.GetInstance().Unmarshall(context); return(response); }
internal static async Task <bool> BuildExists(String tableName, AmazonDynamoDBClient dynamodbClient) { ListTablesResponse listOfTables = await Build(dynamodbClient); List <String> listOfTableNames = listOfTables.TableNames; bool doesTableExist = listOfTableNames.Contains(tableName); return(doesTableExist); }
public static async Task <List <string> > GetTablesList() { using (IAmazonDynamoDB client = GetDynamoDbClient()) { ListTablesRequest listTablesRequest = new ListTablesRequest(); listTablesRequest.Limit = 5; ListTablesResponse listTablesResponse = await client.ListTablesAsync(listTablesRequest); return(listTablesResponse.TableNames); } }
public static void ListTables() { Console.WriteLine(Utils.CurrentMethod); Task <ListTablesResponse> t = client.ListTablesAsync(); t.Wait(10000); ListTablesResponse response = t.Result; foreach (string tableName in response.TableNames) { Console.WriteLine(">> " + tableName); } }
public async void CreateDynamoDbTable() { var amazonDbClient = new AmazonDynamoDBClient(); Console.WriteLine("Fetching Existing Tables"); ListTablesResponse currentTables = await amazonDbClient.ListTablesAsync(); Console.WriteLine("Existing Tables" + currentTables.TableNames); if (!(currentTables.TableNames.Contains(TableName))) { var createTableReq = new CreateTableRequest() { AttributeDefinitions = new List <AttributeDefinition> { new AttributeDefinition { AttributeName = "PocAppointmentId", AttributeType = "N" }, new AttributeDefinition { AttributeName = "PocAppointmentDate", AttributeType = "S" }, }, KeySchema = new List <KeySchemaElement> { new KeySchemaElement { AttributeName = "PocAppointmentId", KeyType = "HASH" }, new KeySchemaElement { AttributeName = "PocAppointmentDate", KeyType = "Range" }, }, ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 5, WriteCapacityUnits = 5 }, TableName = TableName }; var response = await amazonDbClient.CreateTableAsync(createTableReq); Console.WriteLine("Table Created " + response.ResponseMetadata.RequestId); } }
public static async Task <List <string> > GetAllTables() { List <string> _tableList = new List <string>(); ListTablesResponse _response = new ListTablesResponse(); do { _response = (await _dynamodDbClient.ListTablesAsync(new ListTablesRequest { ExclusiveStartTableName = _response.LastEvaluatedTableName ?? null })); _tableList.AddRange(_response.TableNames); }while (_response.LastEvaluatedTableName != null); return(_tableList); }
private async Task <int> SaveUser(FakeUser u) { ListTablesResponse tableResponse = await client.ListTablesAsync(); if (tableResponse.TableNames.Contains(tableName)) { await worker.SaveAsync(u.Model); return(200); } else { return(500); } }
public static ListTablesResponse Unmarshall(UnmarshallerContext _ctx) { ListTablesResponse listTablesResponse = new ListTablesResponse(); listTablesResponse.HttpResponse = _ctx.HttpResponse; listTablesResponse.RequestId = _ctx.StringValue("ListTables.RequestId"); listTablesResponse.Success = _ctx.BooleanValue("ListTables.Success"); listTablesResponse.ErrorMessage = _ctx.StringValue("ListTables.ErrorMessage"); listTablesResponse.ErrorCode = _ctx.StringValue("ListTables.ErrorCode"); listTablesResponse.TotalCount = _ctx.LongValue("ListTables.TotalCount"); List <ListTablesResponse.ListTables_Table> listTablesResponse_tableList = new List <ListTablesResponse.ListTables_Table>(); for (int i = 0; i < _ctx.Length("ListTables.TableList.Length"); i++) { ListTablesResponse.ListTables_Table table = new ListTablesResponse.ListTables_Table(); table.TableId = _ctx.StringValue("ListTables.TableList[" + i + "].TableId"); table.DatabaseId = _ctx.StringValue("ListTables.TableList[" + i + "].DatabaseId"); table.TableName = _ctx.StringValue("ListTables.TableList[" + i + "].TableName"); table.TableSchemaName = _ctx.StringValue("ListTables.TableList[" + i + "].TableSchemaName"); table.Engine = _ctx.StringValue("ListTables.TableList[" + i + "].Engine"); table.Encoding = _ctx.StringValue("ListTables.TableList[" + i + "].Encoding"); table.TableType = _ctx.StringValue("ListTables.TableList[" + i + "].TableType"); table.NumRows = _ctx.LongValue("ListTables.TableList[" + i + "].NumRows"); table.StoreCapacity = _ctx.LongValue("ListTables.TableList[" + i + "].StoreCapacity"); table.TableGuid = _ctx.StringValue("ListTables.TableList[" + i + "].TableGuid"); table.Description = _ctx.StringValue("ListTables.TableList[" + i + "].Description"); List <string> table_ownerIdList = new List <string>(); for (int j = 0; j < _ctx.Length("ListTables.TableList[" + i + "].OwnerIdList.Length"); j++) { table_ownerIdList.Add(_ctx.StringValue("ListTables.TableList[" + i + "].OwnerIdList[" + j + "]")); } table.OwnerIdList = table_ownerIdList; List <string> table_ownerNameList = new List <string>(); for (int j = 0; j < _ctx.Length("ListTables.TableList[" + i + "].OwnerNameList.Length"); j++) { table_ownerNameList.Add(_ctx.StringValue("ListTables.TableList[" + i + "].OwnerNameList[" + j + "]")); } table.OwnerNameList = table_ownerNameList; listTablesResponse_tableList.Add(table); } listTablesResponse.TableList = listTablesResponse_tableList; return(listTablesResponse); }
public IEnumerable <string> GetTableNames() { ListTablesResponse response = null; do { response = response == null ? Exec(() => DynamoDb.ListTables(new ListTablesRequest())) : Exec(() => DynamoDb.ListTables(new ListTablesRequest(response.LastEvaluatedTableName))); foreach (var tableName in response.TableNames) { yield return(tableName); } } while (response.LastEvaluatedTableName != null); }
private async Task <bool> TableExists(CreateTableRequest table) { bool returnValue = false; // *** // *** Get a list of tables // *** ListTablesResponse response = await this.Client.ListTablesAsync(); // *** // *** Check if the specified table exists // *** returnValue = response.TableNames.Contains(table.TableName); return(returnValue); }
private static void UnmarshallResult(JsonUnmarshallerContext context, ListTablesResponse response) { int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; while (context.Read()) { if (context.TestExpression("TableNames", targetDepth)) { context.Read(); response.TableNames = new List <String>(); if (context.CurrentTokenType == JsonToken.Null) { continue; } StringUnmarshaller unmarshaller = StringUnmarshaller.GetInstance(); while (context.Read()) { JsonToken token = context.CurrentTokenType; if (token == JsonToken.ArrayStart) { continue; } if (token == JsonToken.ArrayEnd) { break; } response.TableNames.Add(unmarshaller.Unmarshall(context)); } continue; } if (context.TestExpression("LastEvaluatedTableName", targetDepth)) { context.Read(); response.LastEvaluatedTableName = StringUnmarshaller.GetInstance().Unmarshall(context); continue; } if (context.CurrentDepth <= originalDepth) { return; } } return; }
public async Task EnsureCreatedAsync(CancellationToken cancellationToken = default) { ListTablesResponse tables = await _dynamoDB.ListTablesAsync(cancellationToken).ConfigureAwait(false); if (tables.TableNames.Contains(_options.TableName)) { return; } await _dynamoDB.CreateTableAsync(new CreateTableRequest { TableName = _options.TableName, AttributeDefinitions = new List <AttributeDefinition>() { new AttributeDefinition { AttributeName = "aggregateId", AttributeType = Defaults.IsNumericType <TKey>() ? "N" : "S" }, new AttributeDefinition { AttributeName = "aggregateVersion", AttributeType = "N" } }, KeySchema = new List <KeySchemaElement> { new KeySchemaElement { AttributeName = "aggregateId", KeyType = "HASH" //Partition key }, new KeySchemaElement { AttributeName = "aggregateVersion", KeyType = "RANGE" //Sort key } }, ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 5, WriteCapacityUnits = 5 }, }, cancellationToken).ConfigureAwait(false); }
public async Task <List <string> > GetTableNamesAsync(CancellationToken token = default) { ListTablesResponse response = null; var to = new List <string>(); do { response = response == null ? await ExecAsync(async() => await DynamoDb.ListTablesAsync(new ListTablesRequest(), token)).ConfigAwait() : await ExecAsync(async() => await DynamoDb.ListTablesAsync(new ListTablesRequest(response.LastEvaluatedTableName), token)).ConfigAwait(); foreach (var tableName in response.TableNames) { to.Add(tableName); } } while (response.LastEvaluatedTableName != null); return(to); }
public async static Task <int> MainWriteAsync(SongDescription Song) { ListTablesResponse tableResponse = await client.ListTablesAsync(); if (Song != null) { if (Song.Duration == null) { Song.Duration = " "; } if (Song.Artist != null && Song.SongTitle != null) { Song.SongTitle = await GetNormaliseText(Song.SongTitle); Song.Artist = await GetNormaliseText(Song.Artist); if (Song.Artist != "" && Song.SongTitle != "") { if (tableResponse.TableNames.Contains(tableName)) { Music currentMusic = new Music { Artist = Song.Artist, SongTitle = Song.SongTitle, Duration = Song.Duration }; await worker.SaveAsync(currentMusic); return(200); } else { return(500); } } else { return(501); } } } return(502); }
public async Task <Model.ObjectCode> Get(string objectCodeId) { ListTablesResponse existingTables = await client.ListTablesAsync(); if (!existingTables.TableNames.Contains(TABLE_NAME)) { await SetupTable(client, TABLE_NAME, "CodeId"); } try { var doc = await DDBContext.LoadAsync <Model.ObjectCode>(objectCodeId.ToUpper()); return(doc); } catch (Exception ex) { Console.WriteLine("Error loading object code: " + ex.Message); } return(null); }
/// <summary> /// Get attribute information for a given URN /// </summary> /// <param name="urn"></param> /// <returns></returns> public async Task <string> GetAttributes(string urn) { ListTablesResponse existingTables = await client.ListTablesAsync(); if (!existingTables.TableNames.Contains(TABLE_NAME)) { await SetupTable(client, TABLE_NAME, "URN"); } try { Table table = Table.LoadTable(client, TABLE_NAME); Document document = await table.GetItemAsync(urn); return(document["Data"].AsString()); // will be parsed later } catch (Exception ex) { Console.WriteLine("Error loading attributes: " + ex.Message); } return(null); }
private async Task EnsureTable() { if (this.client == null) { throw new Exception("Database is not connected"); } ListTablesResponse listTablesResponse = await this.client.ListTablesAsync(); if (listTablesResponse.TableNames.Contains(this.InternalName)) { return; } CreateTableRequest request = new CreateTableRequest { TableName = this.InternalName, AttributeDefinitions = new List <AttributeDefinition>() { new AttributeDefinition("Id", ScalarAttributeType.S), }, KeySchema = new List <KeySchemaElement>() { new KeySchemaElement("Id", KeyType.HASH), }, ProvisionedThroughput = new ProvisionedThroughput(1, 1), }; try { CreateTableResponse createTableResponse = await this.client.CreateTableAsync(request); Log.Write("Created the Table: \"" + this.InternalName + "\"", "Database"); } catch (Exception ex) { throw new Exception("Failed to create table: \"" + this.InternalName + "\"", ex); } }