示例#1
0
        public async Task CStoreRequestSend_VideoFileServerSupportsMPEG4_TransferSuccessful()
        {
            string fileName = TestData.Resolve("test_720.dcm");
            var    success  = false;
            var    handle   = new ManualResetEventSlim();

            var port = Ports.GetNext();

            using var server = DicomServerFactory.Create <VideoCStoreProvider>(port);
            server.Logger    = _logger.IncludePrefix("VideoCStoreProvider");

            var request = new DicomCStoreRequest(fileName)
            {
                OnResponseReceived = (req, rsp) =>
                {
                    success = req.Dataset.InternalTransferSyntax.Equals(
                        DicomTransferSyntax.Lookup(DicomUID.MPEG4HP41)) &&
                              rsp.Status == DicomStatus.Success;
                    handle.Set();
                }
            };

            var client = DicomClientFactory.Create("localhost", port, false, "STORESCU", "STORESCP");

            client.Logger = _logger.IncludePrefix("DicomClient");

            await client.AddRequestAsync(request).ConfigureAwait(false);

            await client.SendAsync().ConfigureAwait(false);

            handle.Wait(10000);

            Assert.True(success);
        }
示例#2
0
        public void OldCStoreRequestSend_VideoFileServerSupportsMPEG4_TransferSuccessful()
        {
            const string fileName = @"Test Data/test_720.dcm";
            var          success  = false;
            var          handle   = new ManualResetEventSlim();

            var port = Ports.GetNext();

            using (DicomServer.Create <VideoCStoreProvider>(port))
            {
                var request = new DicomCStoreRequest(fileName);
                request.OnResponseReceived = (req, rsp) =>
                {
                    success = req.Dataset.InternalTransferSyntax.Equals(
                        DicomTransferSyntax.Lookup(DicomUID.MPEG4HP41)) &&
                              rsp.Status == DicomStatus.Success;
                    handle.Set();
                };

                var client = new Network.DicomClient();
                client.AddRequest(request);
                client.Send("localhost", port, false, "STORESCU", "STORESCP");
                handle.Wait(10000);

                Assert.True(success);
            }
        }
        public void LookupReturnsKnownTransferSyntax()
        {
            var ts = DicomTransferSyntax.Lookup(DicomUID.ImplicitVRLittleEndian);

            Assert.NotNull(ts);
            Assert.Equal(DicomUID.ImplicitVRLittleEndian, ts.UID);
        }
        public void LookupThrowsOnInvalidUidType()
        {
            var uid = DicomUID.ComputedRadiographyImageStorage;

            Assert.Throws <DicomDataException>(
                () => DicomTransferSyntax.Lookup(uid)
                );
        }
        public void LookupReturnsAdHocTransferSyntax()
        {
            var uid = new DicomUID("0", "testing", DicomUidType.TransferSyntax);

            var ts = DicomTransferSyntax.Lookup(uid);

            Assert.NotNull(ts);
            Assert.Equal(uid, ts.UID);

            //  Lookup must not auto-register, as it is invoked from DicomServer.
            //  auto-registration may cause DoS by sending crafted transfer syntaxes repeatedly,
            //  which causes internal static dictionary to hold all the transfer syntaxes.
            Assert.Null(DicomTransferSyntax.Query(uid));
        }
        /// <summary>
        /// Converts list of SOP Class UIDs to list of DicomTransferSyntax.
        /// DicomTransferSyntax.Parse internally throws DicomDataException if UID is invalid.
        /// </summary>
        /// <param name="uids">list of SOP Class UIDs</param>
        /// <returns>Array of DicomTransferSyntax or <c>null</c> if <c>uids</c> is null or empty.</returns>
        /// <exception cref="Dicom.DicomDataException">Thrown in the specified UID is not a transfer syntax type.</exception>
        public static DicomTransferSyntax[] ToDicomTransferSyntaxArray(this IEnumerable <string> uids)
        {
            if (uids.IsNullOrEmpty())
            {
                return(null);
            }

            var dicomTransferSyntaxes = new List <DicomTransferSyntax>();

            foreach (var uid in uids)
            {
                dicomTransferSyntaxes.Add(DicomTransferSyntax.Lookup(DicomUID.Parse(uid)));
            }
            return(dicomTransferSyntaxes.ToArray());
        }
示例#7
0
        /// <summary>
        /// Reads A-ASSOCIATE-AC from PDU buffer
        /// </summary>
        /// <param name="raw">PDU buffer</param>
        public void Read(RawPDU raw)
        {
            uint   l = raw.Length;
            ushort c = 0;

            raw.ReadUInt16("Version");
            raw.SkipBytes("Reserved", 2);
            raw.SkipBytes("Reserved", 16);
            raw.SkipBytes("Reserved", 16);
            raw.SkipBytes("Reserved", 32);
            l -= 68;

            while (l > 0)
            {
                byte type = raw.ReadByte("Item-Type");
                l -= 1;

                if (type == 0x10)
                {
                    // Application Context
                    raw.SkipBytes("Reserved", 1);
                    c = raw.ReadUInt16("Item-Length");
                    raw.SkipBytes("Value", (int)c);
                    l -= 3 + (uint)c;
                }
                else

                if (type == 0x21)
                {
                    // Presentation Context
                    raw.ReadByte("Reserved");
                    ushort pl = raw.ReadUInt16("Presentation Context Item-Length");
                    byte   id = raw.ReadByte("Presentation Context ID");
                    raw.ReadByte("Reserved");
                    byte res = raw.ReadByte("Presentation Context Result/Reason");
                    raw.ReadByte("Reserved");
                    l  -= (uint)pl + 3;
                    pl -= 4;

                    // Presentation Context Transfer Syntax
                    raw.ReadByte("Presentation Context Item-Type (0x40)");
                    raw.ReadByte("Reserved");
                    ushort tl = raw.ReadUInt16("Presentation Context Item-Length");
                    string tx = raw.ReadString("Presentation Context Syntax UID", tl);
                    pl -= (ushort)(tl + 4);

                    _assoc.SetPresentationContextResult(id, (DcmPresContextResult)res);
                    _assoc.SetAcceptedTransferSyntax(id, DicomTransferSyntax.Lookup(tx));
                }
                else

                if (type == 0x50)
                {
                    // User Information
                    raw.ReadByte("Reserved");
                    ushort il = raw.ReadUInt16("User Information Item-Length");
                    l -= (uint)(il + 3);
                    while (il > 0)
                    {
                        byte ut = raw.ReadByte("User Item-Type");
                        raw.ReadByte("Reserved");
                        ushort ul = raw.ReadUInt16("User Item-Length");
                        il -= (ushort)(ul + 4);
                        if (ut == 0x51)
                        {
                            _assoc.MaximumPduLength = raw.ReadUInt32("Max PDU Length");
                        }
                        else if (ut == 0x52)
                        {
                            _assoc.ImplementationClass = DicomUID.Lookup(raw.ReadString("Implementation Class UID", ul));
                        }
                        else if (ut == 0x53)
                        {
                            _assoc.AsyncOpsInvoked   = raw.ReadUInt16("Asynchronous Operations Invoked");
                            _assoc.AsyncOpsPerformed = raw.ReadUInt16("Asynchronous Operations Performed");
                        }
                        else if (ut == 0x55)
                        {
                            _assoc.ImplementationVersion = raw.ReadString("Implementation Version", ul);
                        }
                        else
                        {
                            raw.SkipBytes("User Item Value", (int)ul);
                        }
                    }
                }

                else
                {
                    raw.SkipBytes("Reserved", 1);
                    ushort il = raw.ReadUInt16("User Item-Length");
                    raw.SkipBytes("Unknown User Item", il);
                    l -= (uint)(il + 3);
                }
            }
        }
示例#8
0
        /// <summary>
        /// Reads A-ASSOCIATE-RQ from PDU buffer
        /// </summary>
        /// <param name="raw">PDU buffer</param>
        public void Read(RawPDU raw)
        {
            uint l = raw.Length;

            raw.ReadUInt16("Version");
            raw.SkipBytes("Reserved", 2);
            _assoc.CalledAE  = raw.ReadString("Called AE", 16);
            _assoc.CallingAE = raw.ReadString("Calling AE", 16);
            raw.SkipBytes("Reserved", 32);
            l -= 2 + 2 + 16 + 16 + 32;

            while (l > 0)
            {
                byte type = raw.ReadByte("Item-Type");
                raw.SkipBytes("Reserved", 1);
                ushort il = raw.ReadUInt16("Item-Length");

                l -= 4 + (uint)il;

                if (type == 0x10)
                {
                    // Application Context
                    raw.SkipBytes("Application Context", il);
                }
                else

                if (type == 0x20)
                {
                    // Presentation Context
                    byte id = raw.ReadByte("Presentation Context ID");
                    raw.SkipBytes("Reserved", 3);
                    il -= 4;

                    while (il > 0)
                    {
                        byte pt = raw.ReadByte("Presentation Context Item-Type");
                        raw.SkipBytes("Reserved", 1);
                        ushort pl = raw.ReadUInt16("Presentation Context Item-Length");
                        string sx = raw.ReadString("Presentation Context Syntax UID", pl);
                        if (pt == 0x30)
                        {
                            _assoc.AddPresentationContext(id, DicomUID.Lookup(sx));
                        }
                        else if (pt == 0x40)
                        {
                            _assoc.AddTransferSyntax(id, DicomTransferSyntax.Lookup(sx));
                        }
                        il -= (ushort)(4 + pl);
                    }
                }
                else

                if (type == 0x50)
                {
                    // User Information
                    while (il > 0)
                    {
                        byte ut = raw.ReadByte("User Information Item-Type");
                        raw.SkipBytes("Reserved", 1);
                        ushort ul = raw.ReadUInt16("User Information Item-Length");
                        il -= (ushort)(4 + ul);
                        if (ut == 0x51)
                        {
                            _assoc.MaximumPduLength = raw.ReadUInt32("Max PDU Length");
                        }
                        else if (ut == 0x52)
                        {
                            _assoc.ImplementationClass = new DicomUID(raw.ReadString("Implementation Class UID", ul), "Implementation Class UID", DicomUidType.Unknown);
                        }
                        else if (ut == 0x55)
                        {
                            _assoc.ImplementationVersion = raw.ReadString("Implementation Version", ul);
                        }
                        else if (ut == 0x53)
                        {
                            _assoc.AsyncOpsInvoked   = raw.ReadUInt16("Asynchronous Operations Invoked");
                            _assoc.AsyncOpsPerformed = raw.ReadUInt16("Asynchronous Operations Performed");
                        }
                        else if (ut == 0x54)
                        {
                            raw.SkipBytes("SCU/SCP Role Selection", ul);

                            /*
                             * ushort rsul = raw.ReadUInt16();
                             * if ((rsul + 4) != ul) {
                             *      throw new DicomNetworkException("SCU/SCP role selection length (" + ul + " bytes) does not match uid length (" + rsul + " + 4 bytes)");
                             * }
                             * raw.ReadChars(rsul);	// Abstract Syntax
                             * raw.ReadByte();		// SCU role
                             * raw.ReadByte();		// SCP role
                             */
                        }
                        else
                        {
                            Debug.Log.Error("Unhandled user item: 0x{0:x2} ({1} + 4 bytes)", ut, ul);
                            raw.SkipBytes("Unhandled User Item", ul);
                        }
                    }
                }
            }
        }