Ejemplo n.º 1
0
 /// <summary>
 /// Creates the receive properties for logging.
 /// </summary>
 /// <param name="e">The <see cref="DicomDataReceiverProgressEventArgs"/> instance containing the event data.</param>
 /// <returns>The receive properties.</returns>
 private static (object progressCode, string remoteHost, int remotePort, string uid, string version, string logPresentation) CreateReceiveProperties(DicomDataReceiverProgressEventArgs e) =>
 (e.ProgressCode, e.DicomAssociation.RemoteHost, e.DicomAssociation.RemotePort,
Ejemplo n.º 2
0
        /// <summary>
        /// Method for when data is received. Used for adding a received folder onto the message queue
        /// when the association is closed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The progress update.</param>
        private void DataReceiver_DataReceived(object sender, DicomDataReceiverProgressEventArgs e)
        {
            var queueItem = new UploadQueueItem(
                calledApplicationEntityTitle: e.DicomAssociation?.CalledAE,
                callingApplicationEntityTitle: e.DicomAssociation?.CallingAE,
                associationFolderPath: e.FolderPath,
                rootDicomFolderPath: e.RootFolderPath,
                associationGuid: e.AssociationId,
                associationDateTime: e.SocketConnectionDateTime);

            if (e.ProgressCode == DicomReceiveProgressCode.AssociationReleased || e.ProgressCode == DicomReceiveProgressCode.TransferAborted)
            {
                // Send a log event
                LogInformation(LogEntry.Create(AssociationStatus.DicomAssociationClosed,
                                               uploadQueueItem: queueItem,
                                               dicomDataReceiverProgress: CreateReceiveProperties(e)));

                // If no data has been received, we do not need to add to the message queue.
                // An example of a no data received scenario is a Dicom echo.
                if (!e.AnyDataReceived)
                {
                    return;
                }

                using (var transaction = CreateQueueTransaction(_uploadQueuePath))
                {
                    BeginMessageQueueTransaction(transaction);

                    try
                    {
                        // Add the receive queue item onto the queue.
                        // No retry logic as if the method fails, retrying will not help
                        EnqueueMessage(queueItem, _uploadQueuePath, transaction);
                        transaction.Commit();
                    }
                    // This should never happen unless someone has manually changed the queue configuration
#pragma warning disable CA1031 // Do not catch general exception types
                    catch (Exception exception)
#pragma warning restore CA1031 // Do not catch general exception types
                    {
                        transaction.Abort();
                        LogError(LogEntry.Create(AssociationStatus.ReceiveEnqueueError, uploadQueueItem: queueItem),
                                 exception);
                    }
                }
            }
            else if (e.ProgressCode == DicomReceiveProgressCode.FileReceived ||
                     e.ProgressCode == DicomReceiveProgressCode.ConnectionClosed ||
                     e.ProgressCode == DicomReceiveProgressCode.AssociationEstablished)
            {
                LogInformation(LogEntry.Create(AssociationStatus.FileReceived,
                                               uploadQueueItem: queueItem,
                                               dicomDataReceiverProgress: CreateReceiveProperties(e)));
            }
            else if (e.ProgressCode == DicomReceiveProgressCode.AssociationEstablished)
            {
                LogInformation(LogEntry.Create(AssociationStatus.DicomAssociationOpened,
                                               uploadQueueItem: queueItem,
                                               dicomDataReceiverProgress: CreateReceiveProperties(e)));
            }
            else if (e.ProgressCode == DicomReceiveProgressCode.Echo)
            {
                LogInformation(LogEntry.Create(AssociationStatus.DicomEcho,
                                               uploadQueueItem: queueItem,
                                               dicomDataReceiverProgress: CreateReceiveProperties(e)));
            }
            else
            {
                LogError(LogEntry.Create(AssociationStatus.ReceiveUploadError, uploadQueueItem: queueItem,
                                         dicomDataReceiverProgress: CreateReceiveProperties(e)),
                         new ReceiveServiceException("Cannot add to upload queue"));
            }
        }