Пример #1
0
        /// <summary>
        /// Gets the accepted SOP classes and transfer syntaxes.
        /// </summary>
        /// <returns>The accepted SOP classes and transfer syntaxes.</returns>
        private IReadOnlyDictionary <DicomUID, DicomTransferSyntax[]> GetAcceptedSopClassesAndTransferSyntaxes()
        {
            try
            {
                var gatewayReceiveConfig = _getReceiveServiceConfig();

                if (gatewayReceiveConfig != null)
                {
                    _receiveServiceConfig = gatewayReceiveConfig;
                }
            }
            // We catch all exceptions and return the latest cached result on error. We do not want to stop accepting data
            // just because we cannot communicate with our API. We should stop processing further down the chain.
            catch (Exception e)
            {
                LogError(LogEntry.Create(ServiceStatus.GetAcceptedSopClassesAndTransferSyntaxesError),
                         e);
            }

            return(_receiveServiceConfig.AcceptedSopClassesAndTransferSyntaxes);
        }
        /// <summary>
        /// Called when the service is started.
        /// </summary>
        protected override void OnServiceStart()
        {
            LogTrace(LogEntry.Create(AssociationStatus.ReceiveServiceStart));

            _receiveServiceConfig = _getReceiveServiceConfig();

            // Create a folder for saving data and the data saver object.
            var imageSaver = new ListenerDicomSaver(_receiveServiceConfig.RootDicomFolder);

            _dataReceiver = new ListenerDataReceiver(imageSaver);
            _dataReceiver.DataReceived += DataReceiver_DataReceived;

            // Start listening
            var serverStarted = _dataReceiver.StartServer(
                port: _receiveServiceConfig.GatewayDicomEndPoint.Port,
                getAcceptedTransferSyntaxes: () => _receiveServiceConfig.AcceptedSopClassesAndTransferSyntaxes,
                timeout: TimeSpan.FromSeconds(2));

            if (!serverStarted)
            {
                throw new ArgumentException("Failed to start the Dicom data receiver. The input configuration is not correct.", nameof(_receiveServiceConfig));
            }
        }