Esempio n. 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);
        }
Esempio n. 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)
            {
                Platform.Log(LogLevel.Error, e, "Unexpected exception when loading DICOM file {0}", fileToSend.Filename);

                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);
                            Platform.Log(LogLevel.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)
            {
                Platform.Log(LogLevel.Error, e, "Unexpected exception when compressing or decompressing file before send {0}", fileToSend.Filename);

                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)
            {
                Platform.Log(LogLevel.Error, e, "Unexpected exception while sending file {0}", fileToSend.Filename);

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

            return(true);
        }
Esempio n. 3
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)
            {
                Platform.Log(LogLevel.Error, e, "Unexpected exception when loading DICOM file {0}", fileToSend.Filename);

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

            DicomMessage msg = new DicomMessage(dicomFile);

            byte pcid = 0;

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

                if (DicomCodecRegistry.GetCodec(fileToSend.TransferSyntax) != null)
                {
                    if (pcid == 0)
                    {
                        pcid = association.FindAbstractSyntaxWithTransferSyntax(fileToSend.SopClass,
                                                                                TransferSyntax.ExplicitVrLittleEndian);
                    }
                    if (pcid == 0)
                    {
                        pcid = association.FindAbstractSyntaxWithTransferSyntax(fileToSend.SopClass,
                                                                                TransferSyntax.ImplicitVrLittleEndian);
                    }
                }
            }
            else
            {
                if (pcid == 0)
                {
                    pcid = association.FindAbstractSyntaxWithTransferSyntax(fileToSend.SopClass,
                                                                            TransferSyntax.ExplicitVrLittleEndian);
                }
                if (pcid == 0)
                {
                    pcid = association.FindAbstractSyntaxWithTransferSyntax(fileToSend.SopClass,
                                                                            TransferSyntax.ImplicitVrLittleEndian);
                }
            }

            if (pcid == 0)
            {
                fileToSend.SendStatus = DicomStatuses.SOPClassNotSupported;
                fileToSend.ExtendedFailureDescription = "No valid presentation contexts for file.";
                OnImageStoreCompleted(fileToSend);
                _failureSubOperations++;
                _remainingSubOperations--;
                return(false);
            }

            try
            {
                if (_moveOriginatorAe == null)
                {
                    client.SendCStoreRequest(pcid, client.NextMessageID(), DicomPriority.Medium, msg);
                }
                else
                {
                    client.SendCStoreRequest(pcid, client.NextMessageID(), DicomPriority.Medium, _moveOriginatorAe,
                                             _moveOriginatorMessageId, msg);
                }
            }
            catch (DicomNetworkException)
            {
                throw;                 //This is a DicomException-derived class that we want to throw.
            }
            catch (DicomCodecException e)
            {
                Platform.Log(LogLevel.Error, e, "Unexpected exception when compressing or decompressing file before send {0}", fileToSend.Filename);

                fileToSend.SendStatus = DicomStatuses.ProcessingFailure;
                fileToSend.ExtendedFailureDescription = "Error decompressing or compressing file before send.";
                OnImageStoreCompleted(fileToSend);
                _failureSubOperations++;
                _remainingSubOperations--;
                return(false);
            }
            catch (DicomException e)
            {
                Platform.Log(LogLevel.Error, e, "Unexpected exception while sending file {0}", fileToSend.Filename);

                fileToSend.SendStatus = DicomStatuses.ProcessingFailure;
                fileToSend.ExtendedFailureDescription = "Unexpected exception while sending file.";
                OnImageStoreCompleted(fileToSend);
                _failureSubOperations++;
                _remainingSubOperations--;
                return(false);
            }

            return(true);
        }
Esempio n. 4
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);
	                }
                }
            }

            return pcid;
        }