/// <summary> /// 閾値を作成する /// </summary> /// <param name="setting">設定</param> /// <returns>閾値</returns> private DateTime CreateThreshold(CleanBlobSetting setting) { // 年月まででそれ以下は考慮外という仕様 DateTime thresholdMonth = _timeProvider.UtcNow.AddMonths(-setting.RetentionPeriodMonth); return(new DateTime(thresholdMonth.Year, thresholdMonth.Month, 1)); }
public void ValidKey(string Key, string ExpectedContainerName, string ExpectedFilePathPrefix) { var setting = CleanBlobSetting.Create(Key, "10"); Assert.IsNotNull(setting); Assert.AreEqual(ExpectedContainerName, setting.ContainerName); Assert.AreEqual(ExpectedFilePathPrefix, setting.FilePathPrefix); }
/// <summary> /// 一定期間より古いファイルを削除する /// </summary> public void Clean() { _logger.Enter(); try { // 削除設定を取得する(ファイル削除設定一覧のwrapperを取得する) var targetSettings = _settings.GetConfigs(CleanBlobSetting.KeyPrefix); IEnumerable <CleanBlobSetting> settings = targetSettings.Select(x => { try { return(CleanBlobSetting.Create(x.Key, x.Value)); } catch (RmsInvalidAppSettingException e) { _logger.Error(e, nameof(Resources.CO_BLC_BLC_002), new object[] { e.Message }); return(null); } }) .Where(x => x != null); if (!settings.Any()) { _logger.Error(nameof(Resources.CO_BLC_BLC_002), new object[] { "settings is empty." }); return; } foreach (var setting in settings) { DateTime threshold = CreateThreshold(setting); // Sq1.1: 対象パス以下のファイル情報一覧を取得する if (!GetDeletableDevices(setting, threshold, out IEnumerable <DtDeviceFile> deviceFiles)) { continue; } foreach (var file in deviceFiles) { // Sq1.2: 一定期間より古いファイル情報を削除する // Sq1.3: 一定期間より古いファイルを削除する DeleteFile(file); } } } catch (Exception ex) { _logger.Error(ex, nameof(Resources.CO_BLC_BLC_001)); } finally { _logger.Leave(); } }
public void InvalidValue(string Value) { try { var setting = CleanBlobSetting.Create("BlobCleanTarget_container_filepath", Value); } catch (RmsInvalidAppSettingException) { return; } Assert.Fail(); }
public void InvalidContainerName(string ConfigKey) { try { var setting = CleanBlobSetting.Create(ConfigKey, "1"); } catch (RmsInvalidAppSettingException) { return; } Assert.Fail(); }
/// <summary> /// 削除対象のデバイスファイルを取得する /// </summary> /// <param name="setting">BlobClean設定</param> /// <param name="threshold">閾値</param> /// <param name="deviceFiles">削除対象のデバイスファイル</param> /// <returns>true: 取得成功、false:取得エラー</returns> private bool GetDeletableDevices(CleanBlobSetting setting, DateTime threshold, out IEnumerable <DtDeviceFile> deviceFiles) { deviceFiles = null; try { deviceFiles = _dtDeviceFileRepository.FindByFilePathStartingWithAndUpdateDatetimeLessThan(setting.ContainerName, setting.FilePathPrefix, threshold); if (deviceFiles == null) { // 処理自体は続行する。 _logger.Info(nameof(Resources.CO_BLC_BLC_004), new object[] { setting.ContainerName, setting.FilePathPrefix, threshold }); return(false); } } catch (Exception ex) { // 処理自体は続行する。 _logger.Error(ex, nameof(Resources.CO_BLC_BLC_003), new object[] { setting.ContainerName, setting.FilePathPrefix, threshold }); return(false); } return(true); }
public void ValidValue(string Value, int Expected) { var setting = CleanBlobSetting.Create("BlobCleanTarget_container_filepath", Value); Assert.AreEqual(Expected, setting.RetentionPeriodMonth); }