Index: NetworkBase.cs =================================================================== --- NetworkBase.cs (revision 9475) +++ NetworkBase.cs (working copy) @@ -61,6 +61,7 @@ using ClearCanvas.Common; using ClearCanvas.Dicom.Codec; using ClearCanvas.Dicom.IO; +using System.Diagnostics; namespace ClearCanvas.Dicom.Network { @@ -1057,6 +1058,44 @@ SendDimse(presentationID, message.CommandSet, message.DataSet); } + public void SendNCreateResponse(byte presentationID, ushort messageID, DicomMessage message, DicomStatus status) + { + SendNCreateNSetNDeleteHelper(DicomCommandField.NCreateResponse, presentationID, messageID, message, status); + } + + public void SendNSetResponse(byte presentationID, ushort messageID, DicomMessage message, DicomStatus status) + { + SendNCreateNSetNDeleteHelper(DicomCommandField.NSetResponse, presentationID, messageID, message, status); + } + + public void SendNDeleteResponse(byte presentationID, ushort messageID, DicomMessage message, DicomStatus status) + { + SendNCreateNSetNDeleteHelper(DicomCommandField.NDeleteResponse, presentationID, messageID, message, status); + } + + public void SendNActionResponse(byte presentationID, ushort messageID, DicomMessage message, DicomStatus status) + { + SendNCreateNSetNDeleteHelper(DicomCommandField.NActionResponse, presentationID, messageID, message, status); + } + + private void SendNCreateNSetNDeleteHelper(DicomCommandField commandField, byte presentationID, ushort messageID, DicomMessage message, DicomStatus status) + { + message.CommandField = commandField; + message.MessageId = messageID; + message.AffectedSopClassUid = message.AffectedSopClassUid; + if (!message.CommandSet.Contains(DicomTags.Priority)) + message.Priority = DicomPriority.Medium; + + if (message.DataSet == null || message.DataSet.IsEmpty()) + message.DataSetType = 0x0101; + else + message.DataSetType = 0x202; + message.Status = status; + SendDimse(presentationID, message.CommandSet, message.DataSet); + + } + + #endregion #region Private Methods @@ -1358,6 +1397,8 @@ if (!ret) Platform.Log(LogLevel.Error, "Error with OnReceiveDimse"); + LogSendReceive(true, _dimse.Command, _dimse.Dataset); + //_assoc.TotalBytesRead += (UInt64)total; _dimse = null; @@ -1409,6 +1450,8 @@ _dimse.CommandData = null; _dimse.CommandReader = null; + LogSendReceive(true, _dimse.Command, _dimse.Dataset); + if (_dimse.IsNewDimse) { OnReceiveDimseBegin(pcid, _dimse.Command, _dimse.Dataset); @@ -1478,7 +1521,7 @@ command.CalculateWriteLength(TransferSyntax.ImplicitVrLittleEndian, DicomWriteOptions.Default | DicomWriteOptions.CalculateGroupLengths); - if (dataset != null) + if (dataset != null && !dataset.IsEmpty()) total += dataset.CalculateWriteLength(ts, DicomWriteOptions.Default); PDataTFStream pdustream; @@ -1494,6 +1537,8 @@ DimseMessageSending(_assoc, pcid, command, dataset); }; + LogSendReceive(false, command, dataset); + OnSendDimseBegin(pcid, command, dataset); @@ -1647,13 +1692,25 @@ message.CommandField = DicomCommandField.NDeleteRequest; if (!message.CommandSet.Contains(DicomTags.Priority)) message.Priority = DicomPriority.Medium; + + if (message.DataSet == null || message.DataSet.IsEmpty()) + message.DataSetType = 0x0101; + else + message.DataSetType = 0x202; - //if (message.DataSet != null && !message.DataSet.IsEmpty()) - message.DataSetType = 0x0201; - SendDimse(presentationID, message.CommandSet, message.DataSet); } #endregion + + private static void LogSendReceive(bool receive, DicomAttributeCollection metaInfo, DicomAttributeCollection dataSet) + { + //TODO: would be better if Platform.Log exposed a IsLogLevelEnabled(LogLevel) method so we can check to see if debug + // logging is enabled, so we don't waste resources if it's not. + string receiveOrSend = receive ? "Receive" : "Send"; + Platform.Log(LogLevel.Debug, receiveOrSend + " MetaInfo:\r\n" + (metaInfo != null ? metaInfo.DumpString : String.Empty)); + Platform.Log(LogLevel.Debug, receiveOrSend + " DataSet:\r\n" + (dataSet != null ? dataSet.DumpString : String.Empty)); + + } } }