Beispiel #1
0
 public static void Send(AbstractDIMSEBase dimse, Association asc, PresentationContext pContext = null)
 {
     if (asc.State != NetworkState.TRANSPORT_CONNECTION_OPEN)
     {
         asc.OutboundMessages.Enqueue(dimse);
         AssociationMessenger.SendRequest(asc, dimse.AffectedSOPClassUID);
     }
     else
     {
         asc.Logger.Log("--> DIMSE" + dimse.GetLogString());
         dimse.LogData(asc);
         var stream = asc.Stream;
         pContext =
             pContext ?? asc.PresentationContexts.First(a => a.AbstractSyntax == dimse.AffectedSOPClassUID);
         var pds = GetPDataTFs(dimse, pContext, asc.UserInfo.MaxPDULength);
         if (pds.Count > 0 && stream.CanWrite)
         {
             foreach (var pd in pds)
             {
                 var message = pd.Write();
                 stream.Write(message, 0, message.Length);
             }
         }
     }
 }
Beispiel #2
0
 public static void Send(AbstractDIMSEBase dimse, Association asc, PresentationContext pContext = null)
 {
     if (asc.State != NetworkState.TRANSPORT_CONNECTION_OPEN)
     {
         asc.OutboundMessages.Enqueue(dimse);
         AssociationMessenger.SendRequest(asc, dimse.AffectedSOPClassUID);
     }
     else if (!asc.IsClientConnected)
     {
         //Connection lost
         asc.Logger.Log("TCP connection has been lost. Ending association");
     }
     else
     {
         asc.Logger.Log("--> DIMSE" + dimse.GetLogString());
         dimse.LogData(asc);
         pContext = pContext ?? asc.PresentationContexts.First(a => a.AbstractSyntax == dimse.AffectedSOPClassUID);
         var maxPDU = asc.UserInfo.MaxPDULength;
         WriteDimseToStream(dimse, asc.Stream, pContext, maxPDU);
         if (dimse is AbstractDIMSEResponse && !(dimse is NEventReportResponse))
         {
             asc.State = NetworkState.AWAITING_RELEASE;
         }
         else if (dimse is NEventReportResponse)
         {
             AssociationMessenger.SendReleaseRequest(asc);
         }
         else
         {
             asc.State = NetworkState.ASSOCIATION_ESTABLISHED_WAITING_ON_DATA;
         }
     }
 }
Beispiel #3
0
        public static void WriteDimseToStream(AbstractDIMSEBase dimse, Stream stream, PresentationContext pContext, int maxPDULength = 16384)
        {
            var pds = GetPDataTFs(dimse, pContext, maxPDULength);

            if (pds.Count > 0 && stream.CanWrite)
            {
                foreach (var pd in pds)
                {
                    var message = pd.Write();
                    stream.Write(message, 0, message.Length);
                }
            }
        }
Beispiel #4
0
 public static void LogData(this AbstractDIMSEBase dimse, Association asc)
 {
     if (dimse is AbstractDIMSE)
     {
         var abd = dimse as AbstractDIMSE;
         if (abd.HasData)
         {
             foreach (var el in abd.Data.Elements)
             {
                 asc.Logger.Log(el);
             }
             asc.Logger.Log("");//Space
         }
     }
 }
Beispiel #5
0
 public static void Send(AbstractDIMSEBase dimse, Association asc, PresentationContext pContext = null)
 {
     if (asc.State != NetworkState.TRANSPORT_CONNECTION_OPEN)
     {
         asc.OutboundMessages.Enqueue(dimse);
         AssociationMessenger.SendRequest(asc, dimse.AffectedSOPClassUID);
     }
     else
     {
         asc.Logger.Log("--> DIMSE" + dimse.GetLogString());
         dimse.LogData(asc);
         pContext = pContext ?? asc.PresentationContexts.First(a => a.AbstractSyntax == dimse.AffectedSOPClassUID);
         var maxPDU = asc.UserInfo.MaxPDULength;
         WriteDimseToStream(dimse, asc.Stream, pContext, maxPDU);
     }
 }
Beispiel #6
0
        public static List <PDataTF> GetPDataTFs(AbstractDIMSEBase dimse, PresentationContext pContext, int maxPDULength = 16384)
        {
            var list       = new List <PDataTF>();
            var commandEls = dimse.Elements;

            list.Add(new PDataTF(new DICOMObject(dimse.Elements), true, true, pContext));

            var dataDIMSE = dimse as AbstractDIMSE;

            if (dataDIMSE != null && dataDIMSE.Data != null)
            {
                List <byte[]> chunks = GetChunks(dataDIMSE.Data, maxPDULength, pContext);
                chunks
                .Select((c, i) => new PDataTF(c, i == chunks.Count - 1, false, pContext))
                .ToList()
                .ForEach(list.Add);
            }
            return(list);
        }
Beispiel #7
0
 public static void LogData(this AbstractDIMSEBase dimse, Association asc)
 {
     if (dimse is AbstractDIMSE)
     {
         var abd = dimse as AbstractDIMSE;
         if (abd.HasData)
         {
             if (abd.Data == null)
             {
                 asc.Logger.LogInformation("Expected data but no data present!");
             }
             else
             {
                 foreach (var el in abd.Data.Elements)
                 {
                     asc.Logger.LogInformation(el.ToString());
                 }
                 asc.Logger.LogInformation(""); //Space
             }
         }
     }
 }
Beispiel #8
0
        public static List <PDataTF> GetPDataTFs(AbstractDIMSEBase dimse, Association asc, PresentationContext pContext = null)
        {
            pContext = pContext ?? asc.PresentationContexts.First(a => a.AbstractSyntax == dimse.AffectedSOPClassUID);
            var list       = new List <PDataTF>();
            var commandEls = dimse.Elements;

            list.Add(new PDataTF(new DICOMObject(dimse.Elements), true, true, pContext));

            var dataDIMSE = dimse as AbstractDIMSE;

            if (dataDIMSE != null && dataDIMSE.Data != null)
            {
                List <byte[]> chunks = GetChunks(dataDIMSE.Data, asc.UserInfo.MaxPDULength, asc);
                chunks
                .Select(
                    (c, i) =>
                    new PDataTF(c, i == chunks.Count - 1, false,
                                asc.PresentationContexts.First(a => a.AbstractSyntax == dimse.AffectedSOPClassUID)))
                .ToList()
                .ForEach(list.Add);
            }
            return(list);
        }