コード例 #1
0
        private async Task Cleanup(IDicomClientConnection connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }

            var listener = connection.Listener;

            try
            {
                connection.Dispose();
            }
            catch (Exception e)
            {
                _dicomClient.Logger.Warn($"[{this}] The listener for incoming DICOM communication could not be disposed properly: " + e);
            }

            try
            {
                connection.NetworkStream?.Dispose();
            }
            catch (Exception e)
            {
                _dicomClient.Logger.Warn($"[{this}] The connection network stream could not be disposed properly: " + e);
            }

            // wait until listener task realizes connection is gone
            if (listener != null)
            {
                await listener.ConfigureAwait(false);
            }
        }
コード例 #2
0
        public static Task <IDicomClientState> TransitionToCompletedWithErrorState(this DicomClient dicomClient,
                                                                                   IDicomClientConnection connection,
                                                                                   Exception exception, DicomClientCancellation cancellation)
        {
            var completedWithErrorParameters = connection == null
                ? new DicomClientCompletedState.DicomClientCompletedWithErrorInitialisationParameters(exception)
                : new DicomClientCompletedState.DicomClientCompletedWithErrorInitialisationParameters(exception, connection);
            var completedWithErrorState = new DicomClientCompletedState(dicomClient, completedWithErrorParameters);

            return(dicomClient.Transition(completedWithErrorState, cancellation));
        }
コード例 #3
0
        public async Task <IDicomClientState> GetNextStateAsync(DicomClientCancellation cancellation)
        {
            if (cancellation.Token.IsCancellationRequested)
            {
                _dicomClient.Logger.Warn($"[{this}] Cancellation requested, won't connect");
                return(await _dicomClient.TransitionToIdleState(cancellation).ConfigureAwait(false));
            }

            _disposables.Add(cancellation.Token.Register(() => _cancellationRequestedTaskCompletionSource.SetResult(true)));

            var connect = Connect(cancellation);
            var cancel  = _cancellationRequestedTaskCompletionSource.Task;

            var winner = await Task.WhenAny(connect, cancel).ConfigureAwait(false);

            if (winner == connect)
            {
                IDicomClientConnection connection = null;
                try
                {
                    connection = await connect.ConfigureAwait(false);

                    return(await _dicomClient.TransitionToRequestAssociationState(connection, cancellation).ConfigureAwait(false));
                }
                catch (Exception e)
                {
                    return(await _dicomClient.TransitionToCompletedWithErrorState(connection, e, cancellation).ConfigureAwait(false));
                }
            }

            if (winner != cancel)
            {
                throw new DicomNetworkException("Unknown winner of Task.WhenAny in DICOM client, this is likely a bug: " + winner);
            }

            // Cancellation or abort was triggered but wait for the connection anyway, because we need to dispose of it properly
            try
            {
                var connection = await connect.ConfigureAwait(false);

                return(await _dicomClient.TransitionToCompletedState(connection, cancellation).ConfigureAwait(false));
            }
            catch (Exception e)
            {
                return(await _dicomClient.TransitionToCompletedWithErrorState((IDicomClientConnection)null, e, cancellation).ConfigureAwait(false));
            }
        }
コード例 #4
0
        public static Task <IDicomClientState> TransitionToCompletedState(this DicomClient dicomClient, IDicomClientConnection connection,
                                                                          DicomClientCancellation cancellation)
        {
            var completedParameters = new DicomClientCompletedState.DicomClientCompletedWithoutErrorInitialisationParameters(connection);
            var completedState      = new DicomClientCompletedState(dicomClient, completedParameters);

            return(dicomClient.Transition(completedState, cancellation));
        }
コード例 #5
0
        public static Task <IDicomClientState> TransitionToRequestAssociationState(this DicomClient dicomClient, IDicomClientConnection connection,
                                                                                   DicomClientCancellation cancellation)
        {
            var requestAssociationParameters = new DicomClientRequestAssociationState.InitialisationParameters(connection);
            var requestAssociationState      = new DicomClientRequestAssociationState(dicomClient, requestAssociationParameters);

            return(dicomClient.Transition(requestAssociationState, cancellation));
        }
コード例 #6
0
 public DicomClientCompletedWithErrorInitialisationParameters(Exception exceptionToThrow, IDicomClientConnection connection)
     : this(exceptionToThrow)
 {
     Connection = connection ?? throw new ArgumentNullException(nameof(connection));
 }
コード例 #7
0
 public DicomClientCompletedWithoutErrorInitialisationParameters(IDicomClientConnection connection)
 {
     Connection = connection ?? throw new ArgumentNullException(nameof(connection));
 }
コード例 #8
0
 public InitialisationParameters(DicomAssociation association, IDicomClientConnection connection)
 {
     Association = association ?? throw new ArgumentNullException(nameof(association));
     Connection  = connection ?? throw new ArgumentNullException(nameof(connection));
 }
コード例 #9
0
 public InitialisationParameters(IDicomClientConnection connection)
 {
     Connection = connection;
 }