示例#1
0
        private byte SelectPresentationContext(ClientAssociationParameters association, StorageInstance fileToSend, out DicomMessage msg)
        {
            byte pcid;

            if (PresentationContextSelectionDelegate != null)
            {
                // Note, this may do a conversion of the file according to codecs, need to catch a codec exception if it occurs
                var dicomFile = fileToSend.LoadFile();
                pcid = PresentationContextSelectionDelegate(association, dicomFile, out msg);
            }
            else
            {
                msg = null;

                pcid = association.FindAbstractSyntaxWithTransferSyntax(fileToSend.SopClass,
                                                                        fileToSend.TransferSyntax);

                if (fileToSend.TransferSyntax.Encapsulated)
                {
                    if (pcid == 0)
                    {
                        // We can compress/decompress the file. Check if remote device accepts it
                        if (DicomCodecRegistry.GetCodec(fileToSend.TransferSyntax) != null)
                        {
                            var dicomFile = fileToSend.LoadFile();
                            msg  = new DicomMessage(dicomFile);
                            pcid = SelectUncompressedPresentationContext(association, msg);
                        }
                    }
                }
                else
                {
                    if (pcid == 0)
                    {
                        var dicomFile = fileToSend.LoadFile();
                        msg  = new DicomMessage(dicomFile);
                        pcid = SelectUncompressedPresentationContext(association, msg);
                    }
                }

                if (pcid != 0 && fileToSend.FileIsLoaded)
                {
                    msg = new DicomMessage(fileToSend.LoadFile());
                }
            }

            return(pcid);
        }
示例#2
0
        /// <summary>
        /// Generic routine to send the next C-STORE-RQ message in the <see cref="StorageInstanceList"/>.
        /// </summary>
        /// <param name="client">DICOM Client class</param>
        /// <param name="association">Association Parameters</param>
        private bool SendCStore(DicomClient client, ClientAssociationParameters association)
        {
            StorageInstance fileToSend = _storageInstanceList[_fileListIndex];

            OnImageStoreStarted(fileToSend);

            DicomFile dicomFile;

            try
            {
                // Check to see if image does not exist or is corrupted
                if (fileToSend.SendStatus == DicomStatuses.ProcessingFailure)
                {
                    _failureSubOperations++;
                    _remainingSubOperations--;
                    OnImageStoreCompleted(fileToSend);
                    return(false);
                }

                dicomFile = fileToSend.LoadFile();
            }
            catch (DicomException e)
            {
                LogAdapter.Logger.Error(e, "Unexpected exception when loading DICOM file {0}", fileToSend.ToString());

                fileToSend.ExtendedFailureDescription = e.GetType().Name + " " + e.Message;
                _failureSubOperations++;
                _remainingSubOperations--;
                OnImageStoreCompleted(fileToSend);
                return(false);
            }

            try
            {
                DicomMessage msg;

                byte pcid = SelectPresentationContext(association, fileToSend, dicomFile, out msg);

                if (pcid == 0)
                {
                    fileToSend.SendStatus = DicomStatuses.SOPClassNotSupported;
                    fileToSend.ExtendedFailureDescription = string.Format(SR.ErrorSendSopClassNotSupported, msg.SopClass);

                    LogError(fileToSend, msg, DicomStatuses.SOPClassNotSupported);

                    _failureSubOperations++;
                    _remainingSubOperations--;
                    OnImageStoreCompleted(fileToSend);
                    return(false);
                }

                try
                {
                    SendOnPresentationContext(client, association, pcid, fileToSend, msg);
                }
                catch (DicomCodecUnsupportedSopException e)
                {
                    if (!msg.TransferSyntax.Encapsulated)
                    {
                        pcid = SelectUncompressedPresentationContext(association, msg);
                        if (pcid != 0)
                        {
                            SendOnPresentationContext(client, association, pcid, fileToSend, msg);
                            LogAdapter.Logger.Warn("Could not send SOP as compressed, sent as uncompressed: {0}, file: {1}", e.Message, fileToSend.SopInstanceUid);
                            return(true);
                        }
                    }

                    throw;
                }
            }
            catch (DicomNetworkException)
            {
                throw; //This is a DicomException-derived class that we want to throw.
            }
            catch (DicomCodecException e)
            {
                LogAdapter.Logger.Error(e, "Unexpected exception when compressing or decompressing file before send {0}", fileToSend.ToString());

                fileToSend.SendStatus = DicomStatuses.ProcessingFailure;
                fileToSend.ExtendedFailureDescription = string.Format("Error decompressing or compressing file before send: {0}", e.Message);
                _failureSubOperations++;
                _remainingSubOperations--;
                OnImageStoreCompleted(fileToSend);
                return(false);
            }
            catch (DicomException e)
            {
                LogAdapter.Logger.Error(e, "Unexpected exception while sending file {0}", fileToSend.ToString());

                fileToSend.SendStatus = DicomStatuses.ProcessingFailure;
                fileToSend.ExtendedFailureDescription = string.Format("Unexpected exception while sending file: {0}", e.Message);
                _failureSubOperations++;
                _remainingSubOperations--;
                OnImageStoreCompleted(fileToSend);
                return(false);
            }

            return(true);
        }