Ejemplo n.º 1
0
        private bool SendDimseStream(byte pcid, DcmCommand command, Stream datastream)
        {
            try {
                _disableTimeout = true;

                DicomTransferSyntax ts = _assoc.GetAcceptedTransferSyntax(pcid);

                DcmDimseProgress progress = new DcmDimseProgress();

                progress.EstimatedCommandLength = (int)command.CalculateWriteLength(DicomTransferSyntax.ImplicitVRLittleEndian, DicomWriteOptions.Default | DicomWriteOptions.CalculateGroupLengths);

                if (datastream != null)
                    progress.EstimatedDatasetLength = (int)datastream.Length - (int)datastream.Position;

                PDataTFStream pdustream = new PDataTFStream(_network, pcid, (int)_assoc.MaximumPduLength);
                pdustream.OnPduSent += delegate() {
                    progress.BytesTransfered = pdustream.BytesSent;
                    OnSendDimseProgress(pcid, command, null, progress);
                };

                lock (_socket) {
                    OnSendDimseBegin(pcid, command, null, progress);

                    DicomStreamWriter dsw = new DicomStreamWriter(pdustream);
                    dsw.Write(command, DicomWriteOptions.Default | DicomWriteOptions.CalculateGroupLengths);
                    dsw = null;

                    if (datastream != null) {
                        pdustream.IsCommand = false;
                        pdustream.Write(datastream);
                    }

                    // last pdu is automatically flushed when streaming
                    //pdustream.Flush(true);

                    OnSendDimse(pcid, command, null, progress);
                }

                return true;
            }
            catch (Exception e) {
            #if DEBUG
                Log.Error("{0} -> Error sending DIMSE: {1}", LogID, e.ToString());
            #else
                Log.Error("{0} -> Error sending DIMSE: {1}", LogID, e.Message);
            #endif
                OnNetworkError(e);
                return false;
            }
            finally {
                _disableTimeout = false;
            }
        }
Ejemplo n.º 2
0
        private bool SendDimse(byte pcid, DcmCommand command, DcmDataset dataset)
        {
            try {
                _disableTimeout = true;

                DicomTransferSyntax ts = _assoc.GetAcceptedTransferSyntax(pcid);

                if (dataset != null && ts != dataset.InternalTransferSyntax) {
                    if (ts.IsEncapsulated || dataset.InternalTransferSyntax.IsEncapsulated)
                        throw new DicomNetworkException("Unable to transcode encapsulated transfer syntax!");
                    dataset.ChangeTransferSyntax(ts, null);
                }

                DcmDimseProgress progress = new DcmDimseProgress();

                progress.EstimatedCommandLength = (int)command.CalculateWriteLength(DicomTransferSyntax.ImplicitVRLittleEndian, DicomWriteOptions.Default | DicomWriteOptions.CalculateGroupLengths);

                if (dataset != null)
                    progress.EstimatedDatasetLength = (int)dataset.CalculateWriteLength(ts, DicomWriteOptions.Default);

                PDataTFStream pdustream = new PDataTFStream(_network, pcid, (int)_assoc.MaximumPduLength);
                pdustream.OnPduSent += delegate() {
                    progress.BytesTransfered = pdustream.BytesSent;
                    OnSendDimseProgress(pcid, command, dataset, progress);
                };

                lock (_socket) {
                    OnSendDimseBegin(pcid, command, dataset, progress);

                    DicomStreamWriter dsw = new DicomStreamWriter(pdustream);
                    dsw.Write(command, DicomWriteOptions.Default | DicomWriteOptions.CalculateGroupLengths);

                    if (dataset != null) {
                        pdustream.IsCommand = false;
                        dsw.Write(dataset, DicomWriteOptions.Default);
                    }

                    // flush last pdu
                    pdustream.Flush(true);

                    OnSendDimse(pcid, command, dataset, progress);
                }

                return true;
            }
            catch (Exception e) {
            #if DEBUG
                Log.Error("{0} -> Error sending DIMSE: {1}", LogID, e.ToString());
            #else
                Log.Error("{0} -> Error sending DIMSE: {1}", LogID, e.Message);
            #endif
                OnNetworkError(e);
                return false;
            }
            finally {
                _disableTimeout = false;
            }
        }