public async Task <ActionResult <string> > Create(SourceApplicationEntity item) { try { if (!item.IsValid(_dicomAdapterRepository.AsQueryable().Select(p => p.AeTitle), out IList <string> validationErrors)) { throw new ConfigurationException(string.Join(Environment.NewLine, validationErrors)); } await _dicomAdapterRepository.AddAsync(item); await _dicomAdapterRepository.SaveChangesAsync(); _logger.Log(LogLevel.Information, $"DICOM source added AE Title={item.AeTitle}, Host/IP={item.HostIp}."); return(CreatedAtAction(nameof(GetAeTitle), new { aeTitle = item.AeTitle }, item)); } catch (ConfigurationException ex) { return(Problem(title: "Validation error.", statusCode: (int)System.Net.HttpStatusCode.BadRequest, detail: ex.Message)); } catch (Exception ex) { _logger.Log(LogLevel.Error, ex, "Error adding new Source Application Entity."); return(Problem(title: "Error adding new Source Application Entity.", statusCode: (int)System.Net.HttpStatusCode.InternalServerError, detail: ex.Message)); } }
public async Task <ActionResult <ClaraApplicationEntity> > Create(ClaraApplicationEntity item) { try { ValidateProcessor(item); item.SetDefaultValues(); await _dicomAdapterRepository.AddAsync(item); await _dicomAdapterRepository.SaveChangesAsync(); _claraAeChangedNotificationService.Notify(new ClaraApplicationChangedEvent(item, ChangedEventType.Added)); _logger.Log(LogLevel.Information, $"Clara SCP AE Title added AE Title={item.AeTitle}."); return(CreatedAtAction(nameof(GetAeTitle), new { aeTitle = item.AeTitle }, item)); } catch (ConfigurationException ex) { return(Problem(title: "Validation error.", statusCode: (int)System.Net.HttpStatusCode.BadRequest, detail: ex.Message)); } catch (Exception ex) { _logger.Log(LogLevel.Error, ex, "Error adding new Clara Application Entity."); return(Problem(title: "Error adding new Clara Application Entity.", statusCode: (int)System.Net.HttpStatusCode.InternalServerError, detail: ex.Message)); } }
public async Task Add(InferenceRequest inferenceRequest) { Guard.Against.Null(inferenceRequest, nameof(inferenceRequest)); using var loggerScope = _logger.BeginScope(new LogginDataDictionary <string, object> { { "JobId", inferenceRequest.JobId }, { "TransactionId", inferenceRequest.TransactionId } }); await Policy .Handle <Exception>() .WaitAndRetryAsync( 3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (exception, timeSpan, retryCount, context) => { _logger.Log(LogLevel.Error, exception, $"Error saving inference request. Waiting {timeSpan} before next retry. Retry attempt {retryCount}."); }) .ExecuteAsync(async() => { await _inferenceRequestRepository.AddAsync(inferenceRequest); await _inferenceRequestRepository.SaveChangesAsync(); _inferenceRequestRepository.Detach(inferenceRequest); _logger.Log(LogLevel.Debug, $"Inference request saved."); }) .ConfigureAwait(false); }
/// <summary> /// Adds a new job to the queue (database). A copy of the payload is made to support multiple pipelines per AE Title. /// </summary> /// <param name="job">Job to be queued.</param> /// <param name="enableTracking">Indicates if change tracking should be enabled with Entity Framework.</param> public async Task Add(InferenceJob job, bool enableTracking) { Guard.Against.Null(job, nameof(job)); using (_logger.BeginScope(new LogginDataDictionary <string, object> { { "JobId", job.JobId }, { "PayloadId", job.PayloadId } })) { ConfigureStoragePath(job); // Makes a copy of the payload to support multiple pipelines per AE Title. // Future, consider use of persisted payloads. MakeACopyOfPayload(job); await Policy .Handle <Exception>() .WaitAndRetryAsync( 3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (exception, timeSpan, retryCount, context) => { _logger.Log(LogLevel.Error, exception, $"Error saving inference job. Waiting {timeSpan} before next retry. Retry attempt {retryCount}."); }) .ExecuteAsync(async() => { await _inferenceJobRepository.AddAsync(job); await _inferenceJobRepository.SaveChangesAsync(); if (!enableTracking) { _inferenceJobRepository.Detach(job); } }) .ConfigureAwait(false); } }