Esempio n. 1
0
        public Initialisor(IBus bus, IBus eventProcessingBus)
        {
            if (bus == null)
            {
                throw new ArgumentNullException("bus");
            }

            _bus = bus;
            _eventProcessingBus = eventProcessingBus;
            _membershipService  = new MembershipService(_bus);

            _s3Config = AwsConfigFactory.GetS3Config();
            var awsClientFactory = new AwsClientFactory();

            _fileStore = new S3FileStore(awsClientFactory);

            var dynamoDbConfig      = AwsConfigFactory.GetDynamoDbConfig();
            var mediaRepository     = new MediaRepository(dynamoDbConfig, awsClientFactory);
            var uniquNameRepository = new UniqueNameRepository(dynamoDbConfig, awsClientFactory);

            _mediaService = new MediaService(_bus, mediaRepository, uniquNameRepository, _fileStore);


            _heartbeatService = new HeartbeatService(_bus, ServerSettings.ServerName);
            _heartbeatService.Start();

            AutoMapperConfiguration.Configure();
        }
        public IAmazonDynamoDB CreateDynamoDBClient()
        {
            var            config = AwsConfigFactory.GetDynamoDbConfig();
            RegionEndpoint region = config.GetRegionEndpoint();

            CredentialProfileStoreChain credentialProfileStoreChain = new CredentialProfileStoreChain();

            CredentialProfile profile;

            if (credentialProfileStoreChain.TryGetProfile(config.ProfileName, out profile))
            {
                AWSCredentials awsCredentials;
                if (AWSCredentialsFactory.TryGetAWSCredentials(profile, null, out awsCredentials))
                {
                    return(new AmazonDynamoDBClient(awsCredentials, region));
                }
            }

            // Production. Uses roles.

            return(new AmazonDynamoDBClient(region));
        }
Esempio n. 3
0
        private void ApplyDbTransforms()
        {
            try
            {
                // Ensure that the bucket exists on start-up rather than rely on
                try
                {
                    Logger.LogMessage("Create Bucket for processed images.");
                    var bucket = _s3Config.ProcessedImagesBucket;
                    _fileStore.EnsureBucketExists(bucket);
                    Logger.LogMessage("Create Bucket - Completed.");
                }
                catch (Exception ex)
                {
                    // Failed occasionally when bucket exists.
                    // Sink
                    Logger.LogException(ex, "Failed to create bucked for processed images on startup");
                }

                var awsClientFactory = new AwsClientFactory();

                // Create DynamoDB tables...
                Logger.LogMessage("Applying DB Transformations");
                var config = AwsConfigFactory.GetDynamoDbConfig();
                MediaRepositoryMigrationV1 v1Migations = new MediaRepositoryMigrationV1(config, awsClientFactory);
                v1Migations.CreateMediaItemTable().Wait();
                Logger.LogMessage("Apply Media V1 Transforms - Completed.");

                Logger.LogMessage("Apply Unique Name V1 Transforms.");
                UniqueNameRepositoryMigrationV1 uniqueNameV1Migrations = new UniqueNameRepositoryMigrationV1(config, awsClientFactory);
                uniqueNameV1Migrations.CreateTable().Wait();
                Logger.LogMessage("Apply Unique Name V1 Transforms - Completed.");
            }
            catch (Exception ex)
            {
                Logger.LogException(ex, "Failed during ApplyDbTransforms");
            }
        }