Ejemplo n.º 1
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="settings">アプリケーション設定</param>
        /// <param name="connectionString">接続文字列</param>
        /// <param name="polly">BlobPolly</param>
        /// <param name="logger">logger</param>
        /// <param name="memberName">呼び出し元メンバ名</param>
        /// <param name="sourceFilePath">呼び出し元ファイルパス</param>
        /// <param name="sourceLineNumber">呼び出し元ファイル行数</param>
        public Blob(
            AppSettings settings,
            string connectionString,
            BlobPolly polly,
            ILogger <Blob> logger,
            [System.Runtime.CompilerServices.CallerMemberName] string memberName    = "",
            [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath  = "",
            [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0)
        {
            // 本クラスはabstractであるため、派生クラスコンストラクタの呼び出し元を出力するためにmemberName類を渡す。
            Assert.IfNull(settings, memberName, sourceFilePath, sourceLineNumber);
            Assert.IfNullOrEmpty(connectionString, "connectionString", memberName, sourceFilePath, sourceLineNumber);
            Assert.IfNull(polly, memberName, sourceFilePath, sourceLineNumber);
            Assert.IfNull(logger, memberName, sourceFilePath, sourceLineNumber);

            _settings = settings;
            var _account = CloudStorageAccount.Parse(connectionString);

            Client = _account.CreateCloudBlobClient();

            Client.DefaultRequestOptions.RetryPolicy =
                new ExponentialRetry(TimeSpan.FromSeconds(_settings.BlobAccessDelayDeltaSeconds), _settings.BlobAccessMaxAttempts);

            _polly  = polly;
            _logger = logger;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// DIを実行する
        /// </summary>
        /// <param name="utcNow">TimeProviderに渡す日時</param>
        /// <param name="serviceLogger">Service用のロガー</param>
        /// <param name="configures">AppSettingsに追加する項目</param>
        private void DependencyInjection(DateTime utcNow, TestLogger <CleanBlobService> serviceLogger, Dictionary <string, string> configures = null)
        {
            TestDiProviderBuilder builder = new TestDiProviderBuilder();

            // Blob
            builder.ServiceCollection.AddTransient <PrimaryBlob>();

            // Polly
            builder.ServiceCollection.AddSingleton(s => new BlobPolly(s.GetService <AppSettings>()));
            builder.ServiceCollection.AddSingleton(s => new DBPolly(s.GetService <AppSettings>()));

            // Logger
            builder.ServiceCollection.AddSingleton <ILogger <CleanBlobService> >(serviceLogger);

            // Controller生成
            builder.ServiceCollection.AddTransient <BlobCleanController>();

            // Repository生成
            builder.ServiceCollection.AddTransient <IDtDeviceFileRepository, DtDeviceFileRepositoryMock>();
            builder.ServiceCollection.AddTransient <IPrimaryRepository, PrimaryBlobRepositoryMock>();

            builder.ServiceCollection.AddSingleton <ITimeProvider>(UnitTestHelper.CreateTimeProvider(utcNow));

            // 追加の設定項目
            if (configures != null)
            {
                builder.AddConfigures(configures);
            }

            _provider = builder.Build();

            // AppSettings
            _appSettings = _provider.GetService <AppSettings>();

            // DateTimeProvider
            _dateTimeProvider = _provider.GetService <ITimeProvider>() as DateTimeProvider;

            // PrimaryBlob
            _primaryBlob = _provider.GetService <PrimaryBlob>();

            // BlobPolly
            _blobPolly = _provider.GetService <BlobPolly>();

            // DBPolly
            _dBPolly = _provider.GetService <DBPolly>();

            // BlobCleanController
            _controller = _provider.GetService <BlobCleanController>();

            // DtDeviceFileRepository
            _dtDeviceFileRepositoryMock = _provider.GetService <IDtDeviceFileRepository>() as DtDeviceFileRepositoryMock;

            // PrimaryBlobRepository
            _primaryBlobRepositoryMock = _provider.GetService <IPrimaryRepository>() as PrimaryBlobRepositoryMock;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// PrimaryBlobクラス
 /// </summary>
 /// <param name="settings">設定</param>
 /// <param name="polly">BlobPolly</param>
 /// <param name="logger">logger</param>
 public PrimaryBlob(
     AppSettings settings,
     BlobPolly polly,
     ILogger <PrimaryBlob> logger) : base(
         settings,
         settings.PrimaryBlobConnectionString,
         polly,
         logger)
 {
     // HACK: 本来ならこのように呼び出し元を出力したいが、コンストラクタによる呼び出しはリフレクションを使用しているようで、
     // Azure Functions上で起動すると以下のようなエラーが出るため、行わない。
     // > Anonymously Hosted DynamicMethods Assembly: Object reference not set to an instance of an object.
     // [System.Runtime.CompilerServices.CallerMemberName] string memberName = "",
     // [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "",
     // [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0
 }
Ejemplo n.º 4
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="settings">AppSettings</param>
        /// <param name="deliveringBlob">DeliveringBlob</param>
        /// <param name="polly">BlobPolly</param>
        /// <param name="logger">Logger</param>
        public DeliveringBlobRepository(
            AppSettings settings,
            DeliveringBlob deliveringBlob,
            BlobPolly polly,
            ILogger <DeliveringBlobRepository> logger)
        {
            Assert.IfNull(settings);
            Assert.IfNull(deliveringBlob);
            Assert.IfNull(logger);
            Assert.IfNull(polly);

            _settings       = settings;
            _deliveringBlob = deliveringBlob;
            _log            = logger;
            _polly          = polly;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="settings">AppSettings</param>
        /// <param name="primaryBlob">PrimaryBlob</param>
        /// <param name="polly">BlobPolly</param>
        /// <param name="logger">Logger</param>
        public PrimaryBlobRepository(
            AppSettings settings,
            PrimaryBlob primaryBlob,
            BlobPolly polly,
            ILogger <PrimaryBlobRepository> logger)
        {
            Assert.IfNull(settings);
            Assert.IfNull(primaryBlob);
            Assert.IfNull(logger);
            Assert.IfNull(polly);

            _settings    = settings;
            _primaryBlob = primaryBlob;
            _polly       = polly;
            _log         = logger;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="settings">AppSettings</param>
        /// <param name="failureBlob">FailureBlob</param>
        /// <param name="polly">BlobPolly</param>
        /// <param name="logger">Logger</param>
        public FailureBlobRepository(
            AppSettings settings,
            FailureBlob failureBlob,
            BlobPolly polly,
            ILogger <FailureBlobRepository> logger)
        {
            Assert.IfNull(settings);
            Assert.IfNull(failureBlob);
            Assert.IfNull(logger);
            Assert.IfNull(polly);

            _settings    = settings;
            _failureBlob = failureBlob;
            _log         = logger;
            _polly       = polly;
        }