public Task OnReceiveAssociationRequestAsync(FoDicomNetwork.DicomAssociation association) { _associationDataProvider = UserState as IApplicationEntityManager; if (_associationDataProvider is null) { throw new ArgumentNullException("userState must be an instance of IAssociationDataProvider"); } _logger = _associationDataProvider.GetLogger <ScpServiceInternal>(Association.CalledAE); _associationId = _associationDataProvider.NextAssociationNumber(); _associationIdStr = $"#{_associationId} {association.RemoteHost}:{association.RemotePort}"; _loggerScope = _logger?.BeginScope(new Dictionary <string, object> { { "Association", _associationIdStr } }); _logger?.Log(LogLevel.Information, "Association received from {0}:{1}", association.RemoteHost, association.RemotePort); if (!IsValidSourceAe(association.CallingAE)) { return(SendAssociationRejectAsync( FoDicomNetwork.DicomRejectResult.Permanent, FoDicomNetwork.DicomRejectSource.ServiceUser, FoDicomNetwork.DicomRejectReason.CallingAENotRecognized)); } if (!IsValidCalledAe(association.CalledAE)) { return(SendAssociationRejectAsync( FoDicomNetwork.DicomRejectResult.Permanent, FoDicomNetwork.DicomRejectSource.ServiceUser, FoDicomNetwork.DicomRejectReason.CalledAENotRecognized)); } foreach (var pc in association.PresentationContexts) { if (pc.AbstractSyntax == FoDicom.DicomUID.Verification) { if (!_associationDataProvider.Configuration.Value.Dicom.Scp.Verification.Enabled) { _logger?.Log(LogLevel.Warning, "Verification service is disabled: rejecting association"); return(SendAssociationRejectAsync( FoDicomNetwork.DicomRejectResult.Permanent, FoDicomNetwork.DicomRejectSource.ServiceUser, FoDicomNetwork.DicomRejectReason.ApplicationContextNotSupported )); } pc.AcceptTransferSyntaxes(_associationDataProvider.Configuration.Value.Dicom.Scp.Verification.TransferSyntaxes.ToDicomTransferSyntaxArray()); } else if (pc.AbstractSyntax.StorageCategory != FoDicom.DicomStorageCategory.None) { // Accept any proposed TS pc.AcceptTransferSyntaxes(pc.GetTransferSyntaxes().ToArray()); } } return(SendAssociationAcceptAsync(association)); }
public ScpService(IServiceScopeFactory serviceScopeFactory, IApplicationEntityManager applicationEntityManager, IHostApplicationLifetime appLifetime, IOptions <DicomAdapterConfiguration> dicomAdapterConfiguration) { _serviceScope = serviceScopeFactory.CreateScope(); _serviceProvider = _serviceScope.ServiceProvider; _associationDataProvider = applicationEntityManager ?? throw new ArgumentNullException(nameof(applicationEntityManager)); var logginFactory = _serviceProvider.GetService <ILoggerFactory>(); _logger = logginFactory.CreateLogger <ScpService>(); _appLifetime = appLifetime ?? throw new ArgumentNullException(nameof(appLifetime)); _dicomAdapterConfiguration = dicomAdapterConfiguration ?? throw new ArgumentNullException(nameof(dicomAdapterConfiguration)); var preloadDictionary = DicomDictionary.Default; }