Exemplo n.º 1
0
        /// <summary>
        /// Is called when an image store is started.
        /// </summary>
        /// <param name="storageInstance">The storage instance.</param>
        protected virtual void OnImageStoreStarted(StorageInstance storageInstance)
        {
            EventHandler <StorageInstance> tempHandler = ImageStoreStarted;

            if (tempHandler != null)
            {
                tempHandler(this, storageInstance);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Fail the remaining SOP Instances for sending.
        /// </summary>
        private void FailRemaining(DicomStatus status)
        {
            while (_fileListIndex < _storageInstanceList.Count)
            {
                StorageInstance fileToSend = _storageInstanceList[_fileListIndex];

                OnImageStoreStarted(fileToSend);

                fileToSend.SendStatus = status;

                _failureSubOperations++;
                _remainingSubOperations--;

                fileToSend.ExtendedFailureDescription = "The association was aborted.";

                OnImageStoreCompleted(fileToSend);

                _fileListIndex++;
            }
        }
Exemplo n.º 3
0
        private void LogError(StorageInstance instance, StorageInstance msg, DicomStatus dicomStatus)
        {
            if (dicomStatus == DicomStatuses.SOPClassNotSupported)
            {
                var log = new StringBuilder();

                log.AppendLine(string.Format("Unable to transfer SOP {0} in study {1}. Remote device does not accept {2} in {3} transfer syntax",
                                             instance.SopInstanceUid, instance.StudyInstanceUid, msg.SopClass, msg.TransferSyntax));

                if (instance.TransferSyntax.Encapsulated)
                {
                    var codecExists = DicomCodecRegistry.GetCodec(instance.TransferSyntax) != null;

                    log.AppendLine(codecExists
                                       ? string.Format("Note: codec is available for {0} but remote device does not support it?", instance.TransferSyntax)
                                       : string.Format("Note: codec is NOT available for {0}", instance.TransferSyntax));
                }

                Platform.Log(LogLevel.Error, log.ToString());
            }
        }
Exemplo n.º 4
0
        private void SendFilePresentationContext(DicomClient client, byte pcid, StorageInstance fileToSend)
        {
            fileToSend.SentMessageId = client.NextMessageID();

            fileToSend.ParseMetaInfo();

            using (var fs = fileToSend.StreamOpener.Open())
            {
                // Seek to the Dataset
                fs.Seek(fileToSend.MetaInfoFileLength, SeekOrigin.Begin);

                if (_moveOriginatorAe == null)
                {
                    client.SendCStoreRequest(pcid, fileToSend.SentMessageId, DicomPriority.Medium, null, 0, fileToSend.SopInstanceUid,
                                             fileToSend.SopClass.Uid, fs);
                }
                else
                {
                    client.SendCStoreRequest(pcid, fileToSend.SentMessageId, DicomPriority.Medium, _moveOriginatorAe, _moveOriginatorMessageId, fileToSend.SopInstanceUid,
                                             fileToSend.SopClass.Uid, fs);
                }
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Adds the specified storage instanceto <see cref="StorageInstanceList"/>.
 /// </summary>
 /// <param name="storageInstance">The storage instance.</param>
 public void AddStorageInstance(StorageInstance storageInstance)
 {
     StorageInstanceList.Add(storageInstance);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of <see cref="ImageStoreEventArgs"/>.
 /// </summary>
 /// <param name="storageInstance"></param>
 public ImageStoreEventArgs(StorageInstance storageInstance)
 {
     StorageInstance = storageInstance;
 }
Exemplo n.º 7
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);

            try
            {
                // Check to see if image does not exist or is corrupted
                if (fileToSend.SendStatus == DicomStatuses.ProcessingFailure)
                {
                    _failureSubOperations++;
                    _remainingSubOperations--;
                    OnImageStoreCompleted(fileToSend);
                    return(false);
                }
            }
            catch (DicomException e)
            {
                Platform.Log(LogLevel.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, out msg);

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

                    LogError(fileToSend, fileToSend, DicomStatuses.SOPClassNotSupported);

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

                try
                {
                    if (msg != null)
                    {
                        SendOnPresentationContext(client, association, pcid, fileToSend, msg);
                    }
                    else
                    {
                        SendFilePresentationContext(client, pcid, fileToSend);
                    }
                }
                catch (DicomCodecUnsupportedSopException e)
                {
                    if (msg != null && !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.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)
            {
                Platform.Log(LogLevel.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);
        }
Exemplo n.º 8
0
        private void SendOnPresentationContext(DicomClient client, ClientAssociationParameters association, byte pcid, StorageInstance fileToSend, DicomMessage msg)
        {
            var presContext = association.GetPresentationContext(pcid);

            if (msg.TransferSyntax.Encapsulated &&
                presContext.AcceptedTransferSyntax.Encapsulated &&
                !msg.TransferSyntax.Equals(presContext.AcceptedTransferSyntax))
            {
                // Compressed in different syntaxes, decompress here first, ChangeTransferSyntax does not convert syntaxes properly in this case.
                msg.ChangeTransferSyntax(TransferSyntax.ExplicitVrLittleEndian);
            }

            fileToSend.SentMessageId = client.NextMessageID();

            if (_moveOriginatorAe == null)
            {
                client.SendCStoreRequest(pcid, fileToSend.SentMessageId, DicomPriority.Medium, msg);
            }
            else
            {
                client.SendCStoreRequest(pcid, fileToSend.SentMessageId, DicomPriority.Medium, _moveOriginatorAe,
                                         _moveOriginatorMessageId, msg);
            }
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
 /// <summary>
 /// Is called when an image store is started.
 /// </summary>
 /// <param name="storageInstance">The storage instance.</param>
 protected virtual void OnImageStoreStarted(StorageInstance storageInstance)
 {
     EventsHelper.Fire(ImageStoreStarted, this, new ImageStoreEventArgs(storageInstance));
 }
Exemplo n.º 11
0
 /// <summary>
 /// Adds the specified storage instanceto <see cref="StorageInstanceList"/>.
 /// </summary>
 /// <param name="storageInstance">The storage instance.</param>
 public void AddStorageInstance(StorageInstance storageInstance)
 {
     StorageInstanceList.Add(storageInstance);
     _totalSubOperations = _storageInstanceList.Count;
 }