コード例 #1
0
        public void SetResult_TwoArgumentAcceptTransferSyntaxNull_Throws()
        {
            var context   = new DicomPresentationContext(0x03, DicomUID.RTPlanStorage);
            var exception = Record.Exception(() => context.SetResult(DicomPresentationContextResult.Accept, null));

            Assert.IsType <DicomNetworkException>(exception);
        }
コード例 #2
0
        public void SetResult_OneArgumentNotAcceptNoTransferSyntax_DoesNotThrow()
        {
            var context   = new DicomPresentationContext(0x03, DicomUID.RTPlanStorage);
            var exception = Record.Exception(() => context.SetResult(DicomPresentationContextResult.RejectNoReason));

            Assert.Null(exception);
        }
コード例 #3
0
        public void SetResult_TwoArgumentNotAcceptTransferSyntaxNull_DoesNotThrow()
        {
            var context   = new DicomPresentationContext(0x03, DicomUID.RTPlanStorage);
            var exception = Record.Exception(() => context.SetResult(DicomPresentationContextResult.RejectAbstractSyntaxNotSupported, null));

            Assert.Null(exception);
        }
コード例 #4
0
        public void AcceptedTransferSyntax_ResultNotSet_IsNull()
        {
            var context = new DicomPresentationContext(0x05, DicomUID.EnhancedMRImageStorage);

            context.AddTransferSyntax(DicomTransferSyntax.JPEGLSLossless);
            Assert.Null(context.AcceptedTransferSyntax);
        }
コード例 #5
0
        public void SetResult_FirstAcceptThenReject_ClearsAcceptedTransferSyntax()
        {
            var context = new DicomPresentationContext(0x07, DicomUID.CTImageStorage);

            context.SetResult(DicomPresentationContextResult.Accept, DicomTransferSyntax.JPEGProcess1);
            context.SetResult(DicomPresentationContextResult.RejectTransferSyntaxesNotSupported);

            Assert.Null(context.AcceptedTransferSyntax);
        }
コード例 #6
0
        public void SetResult_TwoArguments_AcceptedTransferSyntaxOnlyRequiredOnAcceptNullOtherwise(
            DicomPresentationContextResult result,
            DicomTransferSyntax acceptedSyntax)
        {
            var context = new DicomPresentationContext(0x01, DicomUID.Verification);

            context.SetResult(result, acceptedSyntax);

            Assert.Equal(result == DicomPresentationContextResult.Accept ? acceptedSyntax : null,
                         context.AcceptedTransferSyntax);
        }
コード例 #7
0
        /// <summary>
        /// Get presentation context valid for C-GET requests for the specified <paramref name="abstractSyntax"/>.
        /// </summary>
        /// <param name="abstractSyntax">Abstract syntax for which presentation context should be generated.</param>
        /// <param name="transferSyntaxes">Supported transfer syntaxes. If <code>null</code> or empty, <see cref="DicomTransferSyntax.ImplicitVRLittleEndian"/> is
        /// added as default transfer syntax.</param>
        /// <returns>Presentation context valid for C-GET requests for the specified <paramref name="abstractSyntax"/>.</returns>
        public static DicomPresentationContext GetScpRolePresentationContext(
            DicomUID abstractSyntax,
            params DicomTransferSyntax[] transferSyntaxes)
        {
            var pc = new DicomPresentationContext(0, abstractSyntax, false, true);

            if (transferSyntaxes != null && transferSyntaxes.Length > 0)
            {
                foreach (var transferSyntax in transferSyntaxes)
                {
                    pc.AddTransferSyntax(transferSyntax);
                }
            }
            else
            {
                pc.AddTransferSyntax(DicomTransferSyntax.ImplicitVRLittleEndian);
            }

            return(pc);
        }
コード例 #8
0
        public void DicomCGetRequest_PickCTImagesInStudy_OnlyCTImagesRetrieved()
        {
            var client = new DicomClient();

            var pc = DicomPresentationContext.GetScpRolePresentationContext(DicomUID.CTImageStorage);

            client.AdditionalPresentationContexts.Add(pc);

            var counter = 0;
            var locker  = new object();

            client.OnCStoreRequest = request =>
            {
                lock (locker)
                {
                    ++counter;
                }

                return(new DicomCStoreResponse(request, DicomStatus.Success));
            };

            var get = new DicomCGetRequest("1.2.840.113619.2.55.3.2609388324.145.1222836278.84");

            var handle = new ManualResetEventSlim();

            get.OnResponseReceived = (request, response) =>
            {
                if (response.Remaining == 0)
                {
                    handle.Set();
                }
            };
            client.AddRequest(get);
            client.Send("localhost", 11112, false, "SCU", "COMMON");
            handle.Wait();

            Assert.Equal(140, counter);
        }
コード例 #9
0
        public void DicomCGetRequest_OneImageInSeries_Received()
        {
            var client = new DicomClient();

            var pcs = DicomPresentationContext.GetScpRolePresentationContextsFromStorageUids(
                DicomStorageCategory.Image,
                DicomTransferSyntax.ExplicitVRLittleEndian,
                DicomTransferSyntax.ImplicitVRLittleEndian,
                DicomTransferSyntax.ImplicitVRBigEndian);

            client.AdditionalPresentationContexts.AddRange(pcs);

            DicomDataset dataset = null;

            client.OnCStoreRequest = request =>
            {
                dataset = request.Dataset;
                return(new DicomCStoreResponse(request, DicomStatus.Success));
            };

            var get = new DicomCGetRequest(
                "1.2.840.113619.2.1.1.322987881.621.736170080.681",
                "1.2.840.113619.2.1.2411.1031152382.365.736169244");

            var handle = new ManualResetEventSlim();

            get.OnResponseReceived = (request, response) =>
            {
                handle.Set();
            };
            client.AddRequest(get);
            client.Send("localhost", 11112, false, "SCU", "COMMON");
            handle.Wait();

            Assert.Equal("RT ANKLE", dataset.Get <string>(DicomTag.StudyDescription));
        }
コード例 #10
0
ファイル: PDU.cs プロジェクト: dremerdt/fo-dicom
		/// <summary>
		/// Reads A-ASSOCIATE-RQ from PDU buffer
		/// </summary>
		/// <param name="raw">PDU buffer</param>
		public void Read(RawPDU raw) {
			uint l = raw.Length - 6;

			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) {
								var pc = new DicomPresentationContext(id, DicomUID.Parse(sx));
								_assoc.PresentationContexts.Add(pc);
							} else if (pt == 0x40) {
								var pc = _assoc.PresentationContexts[id];
								pc.AddTransferSyntax(DicomTransferSyntax.Parse(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.RemoteImplemetationClassUID = new DicomUID(raw.ReadString("Implementation Class UID", ul), "Implementation Class UID", DicomUidType.Unknown);
								} else if (ut == 0x55) {
									_assoc.RemoteImplementationVersion = raw.ReadString("Implementation Version", ul);
								} else if (ut == 0x53) {
									_assoc.MaxAsyncOpsInvoked = raw.ReadUInt16("Asynchronous Operations Invoked");
									_assoc.MaxAsyncOpsPerformed = 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);
								}
							}
						}
			}
		}
コード例 #11
0
ファイル: PDU.cs プロジェクト: aerik/fo-dicom
        /// <summary>
        /// Reads A-ASSOCIATE-RQ from PDU buffer
        /// </summary>
        /// <param name="raw">PDU buffer</param>
        public void Read(RawPDU raw)
        {
            uint l = raw.Length - 6;

            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)
                        {
                            var pc = new DicomPresentationContext(id, DicomUID.Parse(sx));
                            _assoc.PresentationContexts.Add(pc);
                        }
                        else if (pt == 0x40)
                        {
                            var pc = _assoc.PresentationContexts[id];
                            pc.AddTransferSyntax(DicomTransferSyntax.Parse(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.RemoteImplementationClassUID =
                                new DicomUID(
                                    raw.ReadString("Implementation Class UID", ul),
                                    "Implementation Class UID",
                                    DicomUidType.Unknown);
                        }
                        else if (ut == 0x55)
                        {
                            _assoc.RemoteImplementationVersion = raw.ReadString("Implementation Version", ul);
                        }
                        else if (ut == 0x53)
                        {
                            _assoc.MaxAsyncOpsInvoked = raw.ReadUInt16("Asynchronous Operations Invoked");
                            _assoc.MaxAsyncOpsPerformed = raw.ReadUInt16("Asynchronous Operations Performed");
                        }
                        else if (ut == 0x54)
                        {
                            var asul = raw.ReadUInt16("Abstract Syntax Item-Length");
                            var syntax = raw.ReadString("Abstract Syntax UID", asul);
                            var userRole = raw.ReadByte("SCU role");
                            var providerRole = raw.ReadByte("SCP role");
                            var pc =
                                _assoc.PresentationContexts.FirstOrDefault(
                                    context => context.AbstractSyntax.UID.Equals(syntax));
                            if (pc != null)
                            {
                                pc.UserRole = userRole == 0x01;
                                pc.ProviderRole = providerRole == 0x01;
                            }
                        }
                        else if (ut == 0x56)
                        {
                            _assoc.ExtendedNegotiations.Add(DicomExtendedNegotiation.Create(raw, ul));
                        }
                        else
                        {
                            raw.SkipBytes("Unhandled User Item", ul);
                        }
                    }
                }
            }
        }
コード例 #12
0
ファイル: DicomService.cs プロジェクト: sczx888/fo-dicom
        private void SendNextMessage()
        {
            DicomMessage msg;

            lock (_lock) {
                if (_msgQueue.Count == 0)
                {
                    if (_pending.Count == 0)
                    {
                        OnSendQueueEmpty();
                    }
                    return;
                }

                if (_sending)
                {
                    return;
                }

                if (Association.MaxAsyncOpsInvoked > 0 && _pending.Count >= Association.MaxAsyncOpsInvoked)
                {
                    return;
                }

                _sending = true;

                msg = _msgQueue.Dequeue();
            }

            Logger.Log(LogLevel.Info, "{0} -> {1}", LogID, msg);

            if (msg is DicomRequest)
            {
                _pending.Add(msg as DicomRequest);
            }

            DicomPresentationContext pc = null;

            if (msg is DicomCStoreRequest)
            {
                pc = Association.PresentationContexts.FirstOrDefault(x => x.Result == DicomPresentationContextResult.Accept && x.AbstractSyntax == msg.AffectedSOPClassUID && x.AcceptedTransferSyntax == (msg as DicomCStoreRequest).TransferSyntax);
                if (pc == null)
                {
                    pc = Association.PresentationContexts.FirstOrDefault(x => x.Result == DicomPresentationContextResult.Accept && x.AbstractSyntax == msg.AffectedSOPClassUID);
                }
            }
            else
            {
                pc = Association.PresentationContexts.FirstOrDefault(x => x.Result == DicomPresentationContextResult.Accept && x.AbstractSyntax == msg.AffectedSOPClassUID);
            }

            if (pc == null)
            {
                throw new DicomNetworkException("No accepted presentation context found for abstract syntax: {0}", msg.AffectedSOPClassUID);
            }

            var dimse = new Dimse();

            dimse.Message             = msg;
            dimse.PresentationContext = pc;

            dimse.Stream = new PDataTFStream(this, pc.ID, (int)Association.MaximumPDULength);

            var writer = new DicomWriter(DicomTransferSyntax.ImplicitVRLittleEndian, DicomWriteOptions.Default, new StreamByteTarget(dimse.Stream));

            dimse.Walker = new DicomDatasetWalker(msg.Command);
            dimse.Walker.BeginWalk(writer, OnEndSendCommand, dimse);
        }
コード例 #13
0
 public DicomCEchoResponse OnCEchoRequest(DicomCEchoRequest request, DicomPresentationContext presentationContext)
 {
     return(new DicomCEchoResponse(request, DicomStatus.Success));
 }
コード例 #14
0
        private void SendNextMessage()
        {
            DicomMessage msg;

            lock (_lock) {
                if (_msgQueue.Count == 0)
                {
                    if (_pending.Count == 0)
                    {
                        OnSendQueueEmpty();
                    }
                    return;
                }

                if (_sending)
                {
                    return;
                }

                if (Association.MaxAsyncOpsInvoked > 0 && _pending.Count >= Association.MaxAsyncOpsInvoked)
                {
                    return;
                }

                _sending = true;

                msg = _msgQueue.Dequeue();
            }

            if (msg is DicomRequest)
            {
                _pending.Add(msg as DicomRequest);
            }

            DicomPresentationContext pc = null;

            if (msg is DicomCStoreRequest)
            {
                pc = Association.PresentationContexts.FirstOrDefault(x => x.Result == DicomPresentationContextResult.Accept && x.AbstractSyntax == msg.SOPClassUID && x.AcceptedTransferSyntax == (msg as DicomCStoreRequest).TransferSyntax);
                if (pc == null)
                {
                    pc = Association.PresentationContexts.FirstOrDefault(x => x.Result == DicomPresentationContextResult.Accept && x.AbstractSyntax == msg.SOPClassUID);
                }
            }
            else
            {
                pc = Association.PresentationContexts.FirstOrDefault(x => x.Result == DicomPresentationContextResult.Accept && x.AbstractSyntax == msg.SOPClassUID);
            }

            if (pc == null)
            {
                pc = msg.PresentationContext;
            }

            if (pc == null)
            {
                _pending.Remove(msg as DicomRequest);

                try {
                    if (msg is DicomCStoreRequest)
                    {
                        (msg as DicomCStoreRequest).PostResponse(this, new DicomCStoreResponse(msg as DicomCStoreRequest, DicomStatus.SOPClassNotSupported));
                    }
                    else if (msg is DicomCEchoRequest)
                    {
                        (msg as DicomCEchoRequest).PostResponse(this, new DicomCEchoResponse(msg as DicomCEchoRequest, DicomStatus.SOPClassNotSupported));
                    }
                    else if (msg is DicomCFindRequest)
                    {
                        (msg as DicomCFindRequest).PostResponse(this, new DicomCFindResponse(msg as DicomCFindRequest, DicomStatus.SOPClassNotSupported));
                    }
                    else if (msg is DicomCMoveRequest)
                    {
                        (msg as DicomCMoveRequest).PostResponse(this, new DicomCMoveResponse(msg as DicomCMoveRequest, DicomStatus.SOPClassNotSupported));
                    }

                    //TODO: add N services
                } catch {
                }

                Logger.Error("No accepted presentation context found for abstract syntax: {0}", msg.SOPClassUID);
                lock (_lock)
                    _sending = false;
                SendNextMessage();
                return;
            }

            var dimse = new Dimse();

            dimse.Message             = msg;
            dimse.PresentationContext = pc;

            // force calculation of command group length as required by standard
            msg.Command.RecalculateGroupLengths();

            if (msg.HasDataset)
            {
                // remove group lengths as recommended in PS 3.5 7.2
                //
                //	2. It is recommended that Group Length elements be removed during storage or transfer
                //	   in order to avoid the risk of inconsistencies arising during coercion of data
                //	   element values and changes in transfer syntax.
                msg.Dataset.RemoveGroupLengths();

                if (msg.Dataset.InternalTransferSyntax != dimse.PresentationContext.AcceptedTransferSyntax)
                {
                    msg.Dataset = msg.Dataset.ChangeTransferSyntax(dimse.PresentationContext.AcceptedTransferSyntax);
                }
            }

            Logger.Info("{0} -> {1}", LogID, msg.ToString(Options.LogDimseDatasets));

            dimse.Stream = new PDataTFStream(this, pc.ID, Association.MaximumPDULength);

            var writer = new DicomWriter(DicomTransferSyntax.ImplicitVRLittleEndian, DicomWriteOptions.Default, new StreamByteTarget(dimse.Stream));

            dimse.Walker = new DicomDatasetWalker(msg.Command);

            if (dimse.Message.HasDataset)
            {
                dimse.Walker.BeginWalk(writer, OnEndSendCommand, dimse);
            }
            else
            {
                dimse.Walker.BeginWalk(writer, OnEndSendMessage, dimse);
            }
        }
コード例 #15
0
        /// <summary>
        /// Reads A-ASSOCIATE-RQ from PDU buffer
        /// </summary>
        /// <param name="raw">PDU buffer</param>
        public void Read(RawPDU raw)
        {
            var l = raw.Length - 6;

            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)
            {
                var type = raw.ReadByte("Item-Type");
                raw.SkipBytes("Reserved", 1);
                var 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
                    var id = raw.ReadByte("Presentation Context ID");
                    raw.SkipBytes("Reserved", 3);
                    il -= 4;

                    while (il > 0)
                    {
                        var pt = raw.ReadByte("Presentation Context Item-Type");
                        raw.SkipBytes("Reserved", 1);
                        var pl = raw.ReadUInt16("Presentation Context Item-Length");
                        var sx = raw.ReadString("Presentation Context Syntax UID", pl);
                        if (pt == 0x30)
                        {
                            var pc = new DicomPresentationContext(id, DicomUID.Parse(sx));
                            _assoc.PresentationContexts.Add(pc);
                        }
                        else if (pt == 0x40)
                        {
                            var pc = _assoc.PresentationContexts[id];
                            pc.AddTransferSyntax(DicomTransferSyntax.Parse(sx));
                        }
                        il -= (ushort)(4 + pl);
                    }
                }
                else if (type == 0x50)
                {
                    // User Information
                    while (il > 0)
                    {
                        var ut = raw.ReadByte("User Information Item-Type");
                        raw.SkipBytes("Reserved", 1);
                        var 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.RemoteImplementationClassUID =
                                new DicomUID(
                                    raw.ReadString("Implementation Class UID", ul),
                                    "Implementation Class UID",
                                    DicomUidType.Unknown);
                        }
                        else if (ut == 0x55)
                        {
                            _assoc.RemoteImplementationVersion = raw.ReadString("Implementation Version", ul);
                        }
                        else if (ut == 0x53)
                        {
                            _assoc.MaxAsyncOpsInvoked   = raw.ReadUInt16("Asynchronous Operations Invoked");
                            _assoc.MaxAsyncOpsPerformed = raw.ReadUInt16("Asynchronous Operations Performed");
                        }
                        else if (ut == 0x54)
                        {
                            var asul         = raw.ReadUInt16("Abstract Syntax Item-Length");
                            var syntax       = raw.ReadString("Abstract Syntax UID", asul);
                            var userRole     = raw.ReadByte("SCU role");
                            var providerRole = raw.ReadByte("SCP role");
                            var pc           =
                                _assoc.PresentationContexts.FirstOrDefault(
                                    context => context.AbstractSyntax.UID.Equals(syntax));
                            if (pc != null)
                            {
                                pc.UserRole     = userRole == 0x01;
                                pc.ProviderRole = providerRole == 0x01;
                            }
                        }
                        else if (ut == 0x56)
                        {
                            _assoc.ExtendedNegotiations.Add(DicomExtendedNegotiation.Create(raw, ul));
                        }
                        else
                        {
#if !NET35
                            if (HandlePDUBytes != null)
                            {
                                HandlePDUBytes(raw.ReadBytes("Unhandled User Item", ul));
                            }
                            else
                            {
                                raw.SkipBytes("Unhandled User Item", ul);
                            }
#else
                            raw.SkipBytes("Unhandled User Item", ul);
#endif
                        }
                    }
                }
            }
        }
コード例 #16
0
ファイル: Program.cs プロジェクト: raysearchlabs/fo-dicom
			public DicomCStoreResponse OnCStoreRequest(DicomCStoreRequest request, DicomPresentationContext presentationContext) {
				var studyUid = request.Dataset.Get<string>(DicomTag.StudyInstanceUID);
				var instUid = request.SOPInstanceUID.UID;

				var path = Path.GetFullPath(Program.StoragePath);
				path = Path.Combine(path, studyUid);

				if (!Directory.Exists(path))
					Directory.CreateDirectory(path);

				path = Path.Combine(path, instUid) + ".dcm";

				request.File.Save(path);

				return new DicomCStoreResponse(request, DicomStatus.Success);
			}
コード例 #17
0
ファイル: Program.cs プロジェクト: raysearchlabs/fo-dicom
			public DicomCEchoResponse OnCEchoRequest(DicomCEchoRequest request, DicomPresentationContext presentationContext) {
				return new DicomCEchoResponse(request, DicomStatus.Success);
			}
コード例 #18
0
ファイル: Program.cs プロジェクト: raysearchlabs/fo-dicom
			public void OnCStoreRequestException(string tempFileName, Exception e, DicomPresentationContext presentationContext) {
				// let library handle logging and error response
			}
コード例 #19
0
ファイル: PDU.cs プロジェクト: imanabu/fo-dicom
        /// <summary>
        /// Reads A-ASSOCIATE-RQ from PDU buffer
        /// </summary>
        /// <param name="raw">PDU buffer</param>
        public void Read(RawPDU raw)
        {
            uint l = raw.Length - 6;

            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)
                        {
                            var pc = new DicomPresentationContext(id, DicomUID.Parse(sx));
                            _assoc.PresentationContexts.Add(pc);
                        }
                        else if (pt == 0x40)
                        {
                            var pc = _assoc.PresentationContexts[id];
                            pc.AddTransferSyntax(DicomTransferSyntax.Parse(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.RemoteImplemetationClassUID = new DicomUID(raw.ReadString("Implementation Class UID", ul), "Implementation Class UID", DicomUidType.Unknown);
                        }
                        else if (ut == 0x55)
                        {
                            _assoc.RemoteImplementationVersion = raw.ReadString("Implementation Version", ul);
                        }
                        else if (ut == 0x53)
                        {
                            _assoc.MaxAsyncOpsInvoked   = raw.ReadUInt16("Asynchronous Operations Invoked");
                            _assoc.MaxAsyncOpsPerformed = 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);
                        }
                    }
                }
            }
        }
コード例 #20
0
        /// <summary>
        /// Get presentation context valid for C-GET requests for the specified <paramref name="abstractSyntax"/>.
        /// </summary>
        /// <param name="abstractSyntax">Abstract syntax for which presentation context should be generated.</param>
        /// <param name="transferSyntaxes">Supported transfer syntaxes. If <code>null</code> or empty, <see cref="DicomTransferSyntax.ImplicitVRLittleEndian"/> is 
        /// added as default transfer syntax.</param>
        /// <returns>Presentation context valid for C-GET requests for the specified <paramref name="abstractSyntax"/>.</returns>
        public static DicomPresentationContext GetScpRolePresentationContext(
            DicomUID abstractSyntax,
            params DicomTransferSyntax[] transferSyntaxes)
        {
            var pc = new DicomPresentationContext(0, abstractSyntax, false, true);

            if (transferSyntaxes != null && transferSyntaxes.Length > 0)
            {
                foreach (var transferSyntax in transferSyntaxes)
                {
                    pc.AddTransferSyntax(transferSyntax);
                }
            }
            else
            {
                pc.AddTransferSyntax(DicomTransferSyntax.ImplicitVRLittleEndian);
            }

            return pc;
        }