Exemple #1
0
        /// <summary>
        /// Method for sending a DIMSE mesage.
        /// </summary>
        /// <param name="pcid"></param>
        /// <param name="command"></param>
        /// <param name="dataset"></param>
        private void SendDimse(byte pcid, DicomAttributeCollection command, DicomAttributeCollection dataset)
        {
            try
            {
                TransferSyntax ts = _assoc.GetAcceptedTransferSyntax(pcid);

                uint total =
                    command.CalculateWriteLength(TransferSyntax.ImplicitVrLittleEndian,
                                                 DicomWriteOptions.Default | DicomWriteOptions.CalculateGroupLengths);

                if (dataset != null  && !dataset.IsEmpty())
                    total += dataset.CalculateWriteLength(ts, DicomWriteOptions.Default);

                PDataTFStream pdustream;
                if (_assoc.RemoteMaximumPduLength == 0 || _assoc.RemoteMaximumPduLength > _assoc.LocalMaximumPduLength)
					pdustream = new PDataTFStream(this, pcid, _assoc.LocalMaximumPduLength, total, NetworkSettings.Default.CombineCommandDataPdu);
                else
					pdustream = new PDataTFStream(this, pcid, _assoc.RemoteMaximumPduLength, total, NetworkSettings.Default.CombineCommandDataPdu);
                pdustream.OnTick += delegate
                                        {
                                            OnSendDimseProgress(pcid, command, dataset);

                                            if (DimseMessageSending != null)
                                                DimseMessageSending(_assoc, pcid, command, dataset);
                                        };

                // Introduced lock as risk mitigation for ticket #10147.  Note that a more thorough locking
                // mechanism should be developed to work across PDU types, and also should take into account
                // if we do end up using _multiThreaded = true
                lock (_writeSyncLock)
                {
                    LogSendReceive(false, command, dataset);

                    OnSendDimseBegin(pcid, command, dataset);


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

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

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

                _assoc.TotalBytesSent += total;

                OnDimseSent(pcid, command, dataset);
            }
            catch (Exception e)
            {
                OnNetworkError(e, true);

                // TODO
                // Should we throw another exception here?  Should the user know there's an error?  They'll get
                // the error reported to them through the OnNetworkError routine, and throwing an exception here
                // might cause us to call OnNetworkError a second time, because the exception may be caught at a higher
                // level
                // Note, when fixing defect #8184, realized that throwing an exception here would cause
                // failures in the ImageServer, because there are places where we wouldn't catch the 
                // exception.  Should be careful if this is ever introduced back in.
                //throw new DicomException("Unexpected exception when sending a DIMSE message",e);
            }
        }
Exemple #2
0
        /// <summary>
        /// Method for sending a DIMSE mesage.
        /// </summary>
        /// <param name="pcid"></param>
        /// <param name="command"></param>
        /// <param name="dataset"></param>
        private void SendDimse(byte pcid, DicomAttributeCollection command, DicomAttributeCollection dataset)
        {
            try
            {
                TransferSyntax ts = _assoc.GetAcceptedTransferSyntax(pcid);

                uint total =
                    command.CalculateWriteLength(TransferSyntax.ImplicitVrLittleEndian,
                                                 DicomWriteOptions.Default | DicomWriteOptions.CalculateGroupLengths);

                if (dataset != null  && !dataset.IsEmpty())
                    total += dataset.CalculateWriteLength(ts, DicomWriteOptions.Default);

                PDataTFStream pdustream;
                if (_assoc.RemoteMaximumPduLength == 0 || _assoc.RemoteMaximumPduLength > _assoc.LocalMaximumPduLength)
					pdustream = new PDataTFStream(this, pcid, _assoc.LocalMaximumPduLength, total, NetworkSettings.Default.CombineCommandDataPdu);
                else
					pdustream = new PDataTFStream(this, pcid, _assoc.RemoteMaximumPduLength, total, NetworkSettings.Default.CombineCommandDataPdu);
                pdustream.OnTick += delegate
                                        {
                                            OnSendDimseProgress(pcid, command, dataset);

                                            if (DimseMessageSending != null)
                                                DimseMessageSending(_assoc, pcid, command, dataset);
                                        };

                LogSendReceive(false, command, dataset);

                OnSendDimseBegin(pcid, command, dataset);


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

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

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

                _assoc.TotalBytesSent += total;

                OnDimseSent(pcid, command, dataset);
            }
            catch (Exception e)
            {
                OnNetworkError(e, true);

                // TODO
                // Should we throw another exception here?  Should the user know there's an error?  They'll get
                // the error reported to them through the OnNetworkError routine, and throwing an exception here
                // might cause us to call OnNetworkError a second time, because the exception may be caught at a higher
                // level
                //throw new DicomException("Unexpected exception when sending a DIMSE message",e);
            }
        }