private AmazonAnnotationPackageProviderConfig GetConfig() { var config = new AmazonAnnotationPackageProviderConfig { AccessKeyId = ConfigurationManager.AppSettings["accessKeyId"], SecretAccessKey = ConfigurationManager.AppSettings["secretAccessKey"], ExtractionFolder = ConfigurationManager.AppSettings["extractionFolder"], S3ServiceUrl = ConfigurationManager.AppSettings["s3ServiceUrl"], BucketName = ConfigurationManager.AppSettings["bucketName"]?.ToLower(), DynamoDbServiceUrl = ConfigurationManager.AppSettings["dynamoDbServiceUrl"], DbTableName = ConfigurationManager.AppSettings["dbTableName"], }; return(config); }
private bool ValidateConfig(AmazonAnnotationPackageProviderConfig config) { if (string.IsNullOrEmpty(config.BucketName)) { return(false); } if (string.IsNullOrEmpty(config.AccessKeyId)) { return(false); } if (string.IsNullOrEmpty(config.SecretAccessKey)) { return(false); } return(true); }
public AmazonAnnotationPackageProvider() { this._packagesToDownload = new Queue <AnnotationPackage>(); var config = this.GetConfig(); #region Validate config if (!this.ValidateConfig(config)) { using (var dialog = new AmazonConfigurationDialog()) { dialog.SetConfig(config); dialog.ShowDialog(); } config = this.GetConfig(); if (!this.ValidateConfig(config)) { throw new Exception("Configuration invalid"); } } #endregion this._config = config; if (string.IsNullOrEmpty(config.S3ServiceUrl) || string.IsNullOrEmpty(config.DynamoDbServiceUrl)) { this._s3Client = new AmazonS3Client(config.AccessKeyId, config.SecretAccessKey, RegionEndpoint.EUWest1); this._dynamoDbClient = new AmazonDynamoDBClient(config.AccessKeyId, config.SecretAccessKey, RegionEndpoint.EUWest1); } else { var s3Config = new AmazonS3Config { ServiceURL = config.S3ServiceUrl, ForcePathStyle = true }; var dbConfig = new AmazonDynamoDBConfig { ServiceURL = config.DynamoDbServiceUrl }; this._s3Client = new AmazonS3Client(config.AccessKeyId, config.SecretAccessKey, s3Config); this._dynamoDbClient = new AmazonDynamoDBClient(config.AccessKeyId, config.SecretAccessKey, dbConfig); using (var tokenSource = new CancellationTokenSource(3000)) { if (!this._s3Client.DoesS3BucketExistAsync(this._config.BucketName).GetAwaiter().GetResult()) { this._s3Client.PutBucketAsync(this._config.BucketName, tokenSource.Token).GetAwaiter().GetResult(); } var createTableRequest = new CreateTableRequest { TableName = this._config.DbTableName, AttributeDefinitions = new List <AttributeDefinition>(), KeySchema = new List <KeySchemaElement>(), GlobalSecondaryIndexes = new List <GlobalSecondaryIndex>(), LocalSecondaryIndexes = new List <LocalSecondaryIndex>(), ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 1, WriteCapacityUnits = 1 } }; createTableRequest.KeySchema = new List <KeySchemaElement> { new KeySchemaElement { AttributeName = "Id", KeyType = KeyType.HASH, }, }; createTableRequest.AttributeDefinitions = new List <AttributeDefinition> { new AttributeDefinition { AttributeName = "Id", AttributeType = ScalarAttributeType.S, } }; var tables = this._dynamoDbClient.ListTablesAsync(tokenSource.Token).GetAwaiter().GetResult(); if (!tables.TableNames.Contains(this._config.DbTableName)) { this._dynamoDbClient.CreateTableAsync(createTableRequest, tokenSource.Token).GetAwaiter().GetResult(); } } } }