ClearCanvas.Dicom.Network.NetworkBase.SendDimseDataSetStream C# (CSharp) Method

SendDimseDataSetStream() private method

Method for sending a DIMSE mesage.
private SendDimseDataSetStream ( byte pcid, DicomAttributeCollection command, Stream dataset ) : void
pcid byte
command DicomAttributeCollection
dataset Stream
return void
		private void SendDimseDataSetStream(byte pcid, DicomAttributeCollection command, Stream dataset)
		{
			try
			{
				TransferSyntax ts = _assoc.GetAcceptedTransferSyntax(pcid);

				PDataTFStream pdustream;
				if (_assoc.RemoteMaximumPduLength == 0 || _assoc.RemoteMaximumPduLength > _assoc.LocalMaximumPduLength)
					pdustream = new PDataTFStream(this, pcid, _assoc.LocalMaximumPduLength, NetworkSettings.Default.CombineCommandDataPdu);
				else
					pdustream = new PDataTFStream(this, pcid, _assoc.RemoteMaximumPduLength, NetworkSettings.Default.CombineCommandDataPdu);
				pdustream.OnTick += delegate
				{
					if (DimseMessageSending != null)
						DimseMessageSending(_assoc, pcid, command, null);
				};

				// 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, null);

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

					if (dataset != null)
					{
						pdustream.IsCommand = false;

						pdustream.Write(dataset);
					}

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

				_assoc.TotalBytesSent += (ulong)pdustream.BytesWritten;

				OnDimseSent(pcid, command, null);
			}
			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);
			}
		}