184 lines
6.4 KiB
C#
184 lines
6.4 KiB
C#
//using System;
|
|
//using System.Collections.Generic;
|
|
//using System.Linq;
|
|
//using System.Text;
|
|
//using System.Threading.Tasks;
|
|
|
|
|
|
//using Amazon.DynamoDBv2;
|
|
//using Amazon.DynamoDBv2.Model;
|
|
//using Amazon.DynamoDBv2.DocumentModel;
|
|
//using Amazon.Runtime;
|
|
|
|
|
|
//using ServerCore; using ServerBase;
|
|
|
|
|
|
//namespace ServerCommon
|
|
//{
|
|
// public static class DynamoDBHelper
|
|
// {
|
|
// public static AmazonDynamoDBClient? CreateClient(ServerConfig config)
|
|
// {
|
|
// AmazonDynamoDBClient? client;
|
|
// AmazonDynamoDBConfig ddbConfig = new AmazonDynamoDBConfig();
|
|
// ddbConfig.BufferSize = 4 * 1024 * 1024; // 4 MB
|
|
// ddbConfig.RetryMode = RequestRetryMode.Standard;
|
|
// ddbConfig.DisableLogging = false; // Logging is disabled by default. - Set to true to enable request-level logging.
|
|
// ddbConfig.ThrottleRetries = false; // Throttled requests are not automatically retried. - Set to false to automatically retry throttled requests.
|
|
// if (config.AWS.LocalDynamoDB)
|
|
// {
|
|
// // DynamoDB-Local is running, so create a client
|
|
// Log.getLogger().info("Setting up a DynamoDB-Local client (DynamoDB Local seems to be running)");
|
|
// ddbConfig.ServiceURL = config.Dynamodb;
|
|
|
|
// try
|
|
// {
|
|
// client = new AmazonDynamoDBClient("AKIA3UC3QYDRYBC4IN66", "uErT6wYLyyTqTBIoV5o/tJGogVem6EhdmlTr9cgJ", ddbConfig);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// Log.getLogger().error($"FAILED to create a DynamoDBLocal client: {ex}");
|
|
// return null;
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// Log.getLogger().info($" -- Setting up a DynamoDB-Remote client : TargetRegion:{config.AWS.Region}");
|
|
|
|
// try
|
|
// {
|
|
// ddbConfig.RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(config.AWS.Region);
|
|
// client = new AmazonDynamoDBClient( config.AWS.AccessKey, config.AWS.SecretKey
|
|
// , ddbConfig );
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// Log.getLogger().error($"FAILED to create a DynamoDB-Remote client: {ex}");
|
|
// return null;
|
|
// }
|
|
// }
|
|
|
|
// return client;
|
|
// }
|
|
|
|
// public static async Task<bool> CheckingTableExistence(AmazonDynamoDBClient client, string tblNm)
|
|
// {
|
|
// try
|
|
// {
|
|
// var response = await client.ListTablesAsync();
|
|
// return response.TableNames.Contains(tblNm);
|
|
// }
|
|
// catch(Exception e)
|
|
// {
|
|
// Log.getLogger().error($"table:{tblNm} {e}");
|
|
// return false;
|
|
// }
|
|
|
|
// }
|
|
|
|
// public static async Task<bool> CreateTable(AmazonDynamoDBClient client, string tableName,
|
|
// List<AttributeDefinition> tableAttributes,
|
|
// List<KeySchemaElement> tableKeySchema)
|
|
// {
|
|
// bool response = true;
|
|
|
|
// // Build the 'CreateTableRequest' structure for the new table
|
|
// var toCreateUpdate = new CreateTableRequest
|
|
// {
|
|
// TableName = tableName,
|
|
// AttributeDefinitions = tableAttributes,
|
|
// KeySchema = tableKeySchema,
|
|
// BillingMode = BillingMode.PAY_PER_REQUEST
|
|
// };
|
|
|
|
// try
|
|
// {
|
|
// var makeTbl = await client.CreateTableAsync(toCreateUpdate);
|
|
// Log.getLogger().info($"Table : {makeTbl.TableDescription.TableName}");
|
|
// }
|
|
// //catch (AmazonDynamoDBException ex) { Log.getLogger().error(ex.ToString()); }
|
|
// //catch (AmazonServiceException ex) { Log.getLogger().error(ex.ToString()); }
|
|
// catch (Exception ex)
|
|
// {
|
|
// Log.getLogger().error($"table:{tableName} {ex}");
|
|
// response = false;
|
|
// }
|
|
|
|
// return response;
|
|
// }
|
|
|
|
// public static async Task<bool> CreateTable(AmazonDynamoDBClient client, string tableName,
|
|
// List<AttributeDefinition> tableAttributes,
|
|
// List<KeySchemaElement> tableKeySchema,
|
|
// List<GlobalSecondaryIndex> globalSecondaryIndexes)
|
|
// {
|
|
// bool response = true;
|
|
|
|
// // Build the 'CreateTableRequest' structure for the new table
|
|
// var request = new CreateTableRequest
|
|
// {
|
|
// TableName = tableName,
|
|
// AttributeDefinitions = tableAttributes,
|
|
// KeySchema = tableKeySchema,
|
|
// GlobalSecondaryIndexes = globalSecondaryIndexes,
|
|
// BillingMode = BillingMode.PAY_PER_REQUEST
|
|
// };
|
|
|
|
// try
|
|
// {
|
|
// var makeTbl = await client.CreateTableAsync(request);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// Log.getLogger().error($"table:{tableName} {ex}");
|
|
// response = false;
|
|
// }
|
|
|
|
// return response;
|
|
// }
|
|
|
|
// public static async Task<bool> DeleteTable(AmazonDynamoDBClient client, string tableName)
|
|
// {
|
|
// bool response = true;
|
|
|
|
// // Build the 'CreateTableRequest' structure for the new table
|
|
// var request = new DeleteTableRequest
|
|
// {
|
|
// TableName = tableName,
|
|
// };
|
|
|
|
// try
|
|
// {
|
|
// var makeTbl = await client.DeleteTableAsync(request);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// Log.getLogger().error($"table:{tableName} {ex}");
|
|
// response = false;
|
|
// }
|
|
|
|
// return response;
|
|
// }
|
|
|
|
// public static async Task<TableDescription?> GetTableDescription(AmazonDynamoDBClient client, string tableName)
|
|
// {
|
|
// TableDescription? result = null;
|
|
|
|
// // If the table exists, get its description.
|
|
// try
|
|
// {
|
|
// var response = await client.DescribeTableAsync(tableName);
|
|
// result = response.Table;
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// Log.getLogger().error($"GetTableDescription : {ex}");
|
|
// return null;
|
|
// }
|
|
|
|
// return result;
|
|
// }
|
|
// }
|
|
//}
|