/// <summary> /// Saves specified <code>InstanceStorage</code> to disk. /// </summary> /// <param name="request">Instance of <code>DicomCStoreRequest</code> to be stored to disk.</param> /// <param name="instanceStorage">Instance of <code>InstanceStorage</code></param> public void Save(DicomCStoreRequest request, InstanceStorageInfo instanceStorage) { Guard.Against.Null(instanceStorage, nameof(instanceStorage)); if (ShouldBeIgnored(instanceStorage.SopClassUid)) { _logger.Log(LogLevel.Warning, "Instance with SOP Class {0} ignored based on configured AET {1}", instanceStorage.SopClassUid, Configuration.AeTitle); return; } Policy.Handle <Exception>() .WaitAndRetry(3, (retryAttempt) => { return(retryAttempt == 1 ? TimeSpan.FromMilliseconds(250) : TimeSpan.FromMilliseconds(500)); }, (exception, retryCount, context) => { _logger.Log(LogLevel.Error, "Failed to save instance, retry count={retryCount}: {exception}", retryCount, exception); }) .Execute(() => { if (ShouldSaveInstance(instanceStorage)) { _logger.Log(LogLevel.Information, "Saving {path}.", instanceStorage.InstanceStorageFullPath); _dicomToolkit.Save(request.File, instanceStorage.InstanceStorageFullPath); _logger.Log(LogLevel.Debug, "Instance saved successfully."); _instanceStoredNotificationService.NewInstanceStored(instanceStorage); _logger.Log(LogLevel.Information, "Instance stored and notified successfully."); } }); }
private void SaveFile(DicomFile file, InstanceStorageInfo instanceStorageInfo) { Guard.Against.Null(file, nameof(file)); Guard.Against.Null(instanceStorageInfo, nameof(instanceStorageInfo)); Policy.Handle <Exception>() .WaitAndRetry(3, (retryAttempt) => { return(retryAttempt == 1 ? TimeSpan.FromMilliseconds(250) : TimeSpan.FromMilliseconds(500)); }, (exception, retryCount, context) => { _logger.Log(LogLevel.Error, "Failed to save instance, retry count={retryCount}: {exception}", retryCount, exception); }) .Execute(() => { _logger.Log(LogLevel.Information, "Saving DICOM instance {path}.", instanceStorageInfo.InstanceStorageFullPath); _dicomToolkit.Save(file, instanceStorageInfo.InstanceStorageFullPath); _logger.Log(LogLevel.Debug, "Instance saved successfully."); }); }