• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Network.RawPDU类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Dicom.Network.RawPDU的典型用法代码示例。如果您正苦于以下问题:C# RawPDU类的具体用法?C# RawPDU怎么用?C# RawPDU使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RawPDU类属于Dicom.Network命名空间,在下文中一共展示了RawPDU类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Write_AeWithNonAsciiCharacters_ShouldBeAsciified

        public void Write_AeWithNonAsciiCharacters_ShouldBeAsciified()
        {
            var notExpected = "GÖTEBORG";
            var request = new AAssociateRQ(new DicomAssociation("MALMÖ", notExpected));

            var writePdu = request.Write();

            RawPDU readPdu;
            using (var stream = new MemoryStream())
            {
                writePdu.WritePDU(stream);

                var length = (int)writePdu.Length;
                var buffer = new byte[length];
                stream.Seek(0, SeekOrigin.Begin);
                stream.Read(buffer, 0, length);
                readPdu = new RawPDU(buffer);
            }

            readPdu.Reset();
            readPdu.SkipBytes("Unknown", 10);
            var actual = readPdu.ReadString("Called AE", 16);

            Assert.NotEqual(notExpected, actual);
        }
开发者ID:GMZ,项目名称:fo-dicom,代码行数:25,代码来源:PDUTest.cs


示例2: Save_ToNonExistingDirectory_Succeeds

        public void Save_ToNonExistingDirectory_Succeeds()
        {
            var path = @".\Test Data\PDU Test";
            var name = Path.Combine(path, "assoc.pdu");
            if (Directory.Exists(path)) Directory.Delete(path, true);

            var pdu = new RawPDU(0x01);
            pdu.Save(name);

            Assert.True(File.Exists(name));
        }
开发者ID:GMZ,项目名称:fo-dicom,代码行数:11,代码来源:PDUTest.cs


示例3: Write

        /// <summary>
        /// Write PDU.
        /// </summary>
        /// <param name="pdu">PDU to write.</param>
        public void Write(RawPDU pdu)
        {
            if (null != SubItem)
            {
                pdu.Write("Item-Type", (byte)0x56);
                pdu.Write("Reserved", (byte)0x00);

                pdu.MarkLength16("Item-Length");

                pdu.Write("SOP Class UID Length", (ushort)(SopClassUid.UID.Length));
                pdu.Write("SOP Class UID", SopClassUid.UID);

                SubItem.Write(pdu);

                pdu.WriteLength16();
            }
        }
开发者ID:aerik,项目名称:fo-dicom,代码行数:21,代码来源:DicomExtendedNegotiation.cs


示例4: WriteReadAAssociateRQExtendedNegotiation

        public void WriteReadAAssociateRQExtendedNegotiation()
        {
            DicomAssociation association = new DicomAssociation("testCalling", "testCalled");
            association.ExtendedNegotiations.Add(
                new DicomExtendedNegotiation(
                    DicomUID.StudyRootQueryRetrieveInformationModelFIND,
                    new RootQueryRetrieveInfoFind(1, 1, 1, 1, null)));

            AAssociateRQ rq = new AAssociateRQ(association);

            RawPDU writePdu = rq.Write();

            RawPDU readPdu;
            using (MemoryStream stream = new MemoryStream())
            {
                writePdu.WritePDU(stream);

                int length = (int)stream.Length;
                byte[] buffer = new byte[length];
                stream.Seek(0, SeekOrigin.Begin);
                stream.Read(buffer, 0, length);
                readPdu = new RawPDU(buffer);
            }

            DicomAssociation testAssociation = new DicomAssociation();
            AAssociateRQ rq2 = new AAssociateRQ(testAssociation);
            rq2.Read(readPdu);

            Assert.True(testAssociation.ExtendedNegotiations.Count == 1);
            Assert.True(
                testAssociation.ExtendedNegotiations[0].SopClassUid
                == DicomUID.StudyRootQueryRetrieveInformationModelFIND);

            RootQueryRetrieveInfoFind info =
                testAssociation.ExtendedNegotiations[0].SubItem as RootQueryRetrieveInfoFind;
            Assert.True(null != info);
            Assert.True(
                (1 == info.DateTimeMatching) && (1 == info.FuzzySemanticMatching) && (1 == info.RelationalQueries)
                && (1 == info.TimezoneQueryAdjustment) && (false == info.EnhancedMultiFrameImageConversion.HasValue));
        }
开发者ID:aerik,项目名称:fo-dicom,代码行数:40,代码来源:PDUTest.cs


示例5: Read

		/// <summary>
		/// Reads PDV from PDU buffer
		/// </summary>
		/// <param name="raw">PDU buffer</param>
		public uint Read(RawPDU raw) {
			uint len = raw.ReadUInt32("PDV-Length");
			_pcid = raw.ReadByte("Presentation Context ID");
			byte mch = raw.ReadByte("Message Control Header");
			_value = raw.ReadBytes("PDV Value", (int)len - 2);
			_command = (mch & 0x01) != 0;
			_last = (mch & 0x02) != 0;
			return len + 4;
		}
开发者ID:dremerdt,项目名称:fo-dicom,代码行数:13,代码来源:PDU.cs


示例6: ProcessNextPDU

        private bool ProcessNextPDU()
        {
            RawPDU raw = new RawPDU(_network);

            if (raw.Type == 0x04) {
                if (_dimse == null) {
                    _dimse = new DcmDimseInfo();
                }
            }

            try {
                raw.ReadPDU();

                switch (raw.Type) {
                case 0x01: {
                        _assoc = new DcmAssociate();
                        AAssociateRQ pdu = new AAssociateRQ(_assoc);
                        pdu.Read(raw);
                        Log.Info("{0} <- Association request:\n{1}", LogID, Associate.ToString());
                        OnReceiveAssociateRequest(_assoc);
                        return true;
                    }
                case 0x02: {
                        AAssociateAC pdu = new AAssociateAC(_assoc);
                        pdu.Read(raw);
                        Log.Info("{0} <- Association accept:\n{1}", LogID, Associate.ToString());
                        OnReceiveAssociateAccept(_assoc);
                        return true;
                    }
                case 0x03: {
                        AAssociateRJ pdu = new AAssociateRJ();
                        pdu.Read(raw);
                        Log.Info("{0} <- Association reject [result: {1}; source: {2}; reason: {3}]", LogID, pdu.Result, pdu.Source, pdu.Reason);
                        OnReceiveAssociateReject(pdu.Result, pdu.Source, pdu.Reason);
                        return true;
                    }
                case 0x04: {
                        PDataTF pdu = new PDataTF();
                        pdu.Read(raw);
                        //Log.Debug("{0} <- P-Data-TF", LogID);
                        return ProcessPDataTF(pdu);
                    }
                case 0x05: {
                        AReleaseRQ pdu = new AReleaseRQ();
                        pdu.Read(raw);
                        Log.Info("{0} <- Association release request", LogID);
                        OnReceiveReleaseRequest();
                        return true;
                    }
                case 0x06: {
                        AReleaseRP pdu = new AReleaseRP();
                        pdu.Read(raw);
                        Log.Info("{0} <- Association release response", LogID);
                        OnReceiveReleaseResponse();
                        return true;
                    }
                case 0x07: {
                        AAbort pdu = new AAbort();
                        pdu.Read(raw);
                        Log.Info("{0} <- Association abort: {1} - {2}", LogID, pdu.Source, pdu.Reason);
                        OnReceiveAbort(pdu.Source, pdu.Reason);
                        return true;
                    }
                case 0xFF: {
                        return false;
                    }
                default:
                    throw new DicomNetworkException("Unknown PDU type");
                }
            } catch (SocketException) {
                throw;
            } catch (Exception e) {
            #if DEBUG
                Log.Error("{0} -> Error reading PDU [type: 0x{1:x2}]: {2}", LogID, raw.Type, e.ToString());
            #else
                Log.Error("{0} -> Error reading PDU [type: 0x{1:x2}]: {2}", LogID, raw.Type, e.Message);
            #endif
                OnNetworkError(e);
                //String file = String.Format(@"{0}\Errors\{1}.pdu",
                //    Dicom.Debug.GetStartDirectory(), DateTime.Now.Ticks);
                //Directory.CreateDirectory(Dicom.Debug.GetStartDirectory() + @"\Errors");
                //raw.Save(file);
                return false;
            }
        }
开发者ID:JeanLedesma,项目名称:mdcm,代码行数:85,代码来源:DcmNetworkBase.cs


示例7: EndReadPDU

        private void EndReadPDU(IAsyncResult result)
        {
            try {
                byte[] buffer = (byte[])result.AsyncState;

                int count = _network.EndRead(result);
                if (count == 0) {
                    // disconnected
                    CloseConnection(0);
                    return;
                }

                _readLength -= count;

                if (_readLength > 0) {
                    _network.BeginRead(buffer, buffer.Length - _readLength, _readLength, EndReadPDU, buffer);
                    return;
                }

                var raw = new RawPDU(buffer);

                switch (raw.Type) {
                case 0x01: {
                        Association = new DicomAssociation();
                        var pdu = new AAssociateRQ(Association);
                        pdu.Read(raw);
                        LogID = Association.CallingAE;
                        Logger.Log(LogLevel.Info, "{0} <- Association request:\n{1}", LogID, Association.ToString());
                        if (this is IDicomServiceProvider)
                            (this as IDicomServiceProvider).OnReceiveAssociationRequest(Association);
                        break;
                    }
                case 0x02: {
                        var pdu = new AAssociateAC(Association);
                        pdu.Read(raw);
                        LogID = Association.CalledAE;
                        Logger.Log(LogLevel.Info, "{0} <- Association accept:\n{1}", LogID, Association.ToString());
                        if (this is IDicomServiceUser)
                            (this as IDicomServiceUser).OnReceiveAssociationAccept(Association);
                        break;
                    }
                case 0x03: {
                        var pdu = new AAssociateRJ();
                        pdu.Read(raw);
                        Logger.Log(LogLevel.Info, "{0} <- Association reject [result: {1}; source: {2}; reason: {3}]", LogID, pdu.Result, pdu.Source, pdu.Reason);
                        if (this is IDicomServiceUser)
                            (this as IDicomServiceUser).OnReceiveAssociationReject(pdu.Result, pdu.Source, pdu.Reason);
                        break;
                    }
                case 0x04: {
                        var pdu = new PDataTF();
                        pdu.Read(raw);
                        if (Options.LogDataPDUs)
                            Logger.Info("{0} <- {1}", LogID, pdu);
                        _processQueue.Queue(ProcessPDataTF, pdu);
                        break;
                    }
                case 0x05: {
                        var pdu = new AReleaseRQ();
                        pdu.Read(raw);
                        Logger.Log(LogLevel.Info, "{0} <- Association release request", LogID);
                        if (this is IDicomServiceProvider)
                            (this as IDicomServiceProvider).OnReceiveAssociationReleaseRequest();
                        break;
                    }
                case 0x06: {
                        var pdu = new AReleaseRP();
                        pdu.Read(raw);
                        Logger.Log(LogLevel.Info, "{0} <- Association release response", LogID);
                        if (this is IDicomServiceUser)
                            (this as IDicomServiceUser).OnReceiveAssociationReleaseResponse();
                        CloseConnection(0);
                        break;
                    }
                case 0x07: {
                        var pdu = new AAbort();
                        pdu.Read(raw);
                        Logger.Log(LogLevel.Info, "{0} <- Abort: {1} - {2}", LogID, pdu.Source, pdu.Reason);
                        if (this is IDicomServiceProvider)
                            (this as IDicomServiceProvider).OnReceiveAbort(pdu.Source, pdu.Reason);
                        else if (this is IDicomServiceUser)
                            (this as IDicomServiceUser).OnReceiveAbort(pdu.Source, pdu.Reason);
                        CloseConnection(0);
                        break;
                    }
                case 0xFF: {
                        break;
                    }
                default:
                    throw new DicomNetworkException("Unknown PDU type");
                }

                BeginReadPDUHeader();
            } catch (IOException e) {
                int error = 0;
                if (e.InnerException is SocketException) {
                    error = (e.InnerException as SocketException).ErrorCode;
                    Logger.Error("Socket error while reading PDU: {0} [{1}]", (e.InnerException as SocketException).SocketErrorCode, (e.InnerException as SocketException).ErrorCode);
                } else if (!(e.InnerException is ObjectDisposedException))
                    Logger.Error("IO exception while reading PDU: {0}", e.ToString());
//.........这里部分代码省略.........
开发者ID:vdrm,项目名称:fo-dicom,代码行数:101,代码来源:DicomService.cs


示例8: Write

        /// <summary>
        /// Writes A-ASSOCIATE-RQ to PDU buffer
        /// </summary>
        /// <returns>PDU buffer</returns>
        public RawPDU Write()
        {
            RawPDU pdu = new RawPDU((byte)0x01);

            pdu.Write("Version", (ushort)0x0001);
            pdu.Write("Reserved", 0x00, 2);
            pdu.Write("Called AE", _assoc.CalledAE, 16, ' ');
            pdu.Write("Calling AE", _assoc.CallingAE, 16, ' ');
            pdu.Write("Reserved", 0x00, 32);

            // Application Context
            pdu.Write("Item-Type", (byte)0x10);
            pdu.Write("Reserved", (byte)0x00);
            pdu.MarkLength16("Item-Length");
            pdu.Write("Application Context Name", DicomUID.DICOMApplicationContextName.UID);
            pdu.WriteLength16();

            foreach (DcmPresContext pc in _assoc.GetPresentationContexts()) {
                // Presentation Context
                pdu.Write("Item-Type", (byte)0x20);
                pdu.Write("Reserved", (byte)0x00);
                pdu.MarkLength16("Item-Length");
                pdu.Write("Presentation Context ID", (byte)pc.ID);
                pdu.Write("Reserved", (byte)0x00, 3);

                // Abstract Syntax
                pdu.Write("Item-Type", (byte)0x30);
                pdu.Write("Reserved", (byte)0x00);
                pdu.MarkLength16("Item-Length");
                pdu.Write("Abstract Syntax UID", pc.AbstractSyntax.UID);
                pdu.WriteLength16();

                // Transfer Syntax
                foreach (DicomTransferSyntax ts in pc.GetTransfers()) {
                    pdu.Write("Item-Type", (byte)0x40);
                    pdu.Write("Reserved", (byte)0x00);
                    pdu.MarkLength16("Item-Length");
                    pdu.Write("Transfer Syntax UID", ts.UID.UID);
                    pdu.WriteLength16();
                }

                pdu.WriteLength16();
            }

            // User Data Fields
            pdu.Write("Item-Type", (byte)0x50);
            pdu.Write("Reserved", (byte)0x00);
            pdu.MarkLength16("Item-Length");

            // Maximum PDU
            pdu.Write("Item-Type", (byte)0x51);
            pdu.Write("Reserved", (byte)0x00);
            pdu.Write("Item-Length", (ushort)0x0004);
            pdu.Write("Max PDU Length", (uint)_assoc.MaximumPduLength);

            // Implementation Class UID
            pdu.Write("Item-Type", (byte)0x52);
            pdu.Write("Reserved", (byte)0x00);
            pdu.MarkLength16("Item-Length");
            pdu.Write("Implementation Class UID", Implementation.ClassUID.UID);
            pdu.WriteLength16();

            // Asynchronous Operations Negotiation
            if (_assoc.NegotiateAsyncOps) {
                pdu.Write("Item-Type", (byte)0x53);
                pdu.Write("Reserved", (byte)0x00);
                pdu.Write("Item-Length", (ushort)0x0004);
                pdu.Write("Asynchronous Operations Invoked", (ushort)_assoc.AsyncOpsInvoked);
                pdu.Write("Asynchronous Operations Performed", (ushort)_assoc.AsyncOpsPerformed);
            }

            // Implementation Version
            pdu.Write("Item-Type", (byte)0x55);
            pdu.Write("Reserved", (byte)0x00);
            pdu.MarkLength16("Item-Length");
            pdu.Write("Implementation Version", Implementation.Version);
            pdu.WriteLength16();

            pdu.WriteLength16();

            return pdu;
        }
开发者ID:hide1980,项目名称:mdcm,代码行数:86,代码来源:PDU.cs


示例9: Read

        /// <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);
                }
            }
        }
开发者ID:hide1980,项目名称:mdcm,代码行数:83,代码来源:PDU.cs


示例10: EndReadPDU

		private void EndReadPDU(IAsyncResult result) {
			try {
				byte[] buffer = (byte[])result.AsyncState;

				int count = _network.EndRead(result);
				if (count == 0) {
					// disconnected
					CloseConnection(null);
					return;
				}

				_readLength -= count;

				if (_readLength > 0) {
					_network.BeginRead(buffer, buffer.Length - _readLength, _readLength, EndReadPDU, buffer);
					return;
				}

				var raw = new RawPDU(buffer);

				switch (raw.Type) {
				case 0x01: {
						Association = new DicomAssociation();
						var pdu = new AAssociateRQ(Association);
						pdu.Read(raw);
						LogID = Association.CallingAE;
						if (Options.UseRemoteAEForLogName)
							Logger = LogManager.Default.GetLogger(LogID);
						Logger.Info("{callingAE} <- Association request:\n{association}", LogID, Association.ToString());
						if (this is IDicomServiceProvider)
							(this as IDicomServiceProvider).OnReceiveAssociationRequest(Association);
						break;
					}
				case 0x02: {
						var pdu = new AAssociateAC(Association);
						pdu.Read(raw);
						LogID = Association.CalledAE;
						Logger.Info("{calledAE} <- Association accept:\n{assocation}", LogID, Association.ToString());
						if (this is IDicomServiceUser)
							(this as IDicomServiceUser).OnReceiveAssociationAccept(Association);
						break;
					}
				case 0x03: {
						var pdu = new AAssociateRJ();
						pdu.Read(raw);
						Logger.Info("{logId} <- Association reject [result: {pduResult}; source: {pduSource}; reason: {pduReason}]", LogID, pdu.Result, pdu.Source, pdu.Reason);
						if (this is IDicomServiceUser)
							(this as IDicomServiceUser).OnReceiveAssociationReject(pdu.Result, pdu.Source, pdu.Reason);
						break;
					}
				case 0x04: {
						var pdu = new PDataTF();
						pdu.Read(raw);
						if (Options.LogDataPDUs)
							Logger.Info("{logId} <- {@pdu}", LogID, pdu);
						_processQueue.Queue(ProcessPDataTF, pdu);
						break;
					}
				case 0x05: {
						var pdu = new AReleaseRQ();
						pdu.Read(raw);
						Logger.Info("{logId} <- Association release request", LogID);
						if (this is IDicomServiceProvider)
							(this as IDicomServiceProvider).OnReceiveAssociationReleaseRequest();
						break;
					}
				case 0x06: {
						var pdu = new AReleaseRP();
						pdu.Read(raw);
						Logger.Info("{logId} <- Association release response", LogID);
						if (this is IDicomServiceUser)
							(this as IDicomServiceUser).OnReceiveAssociationReleaseResponse();
						CloseConnection(null);
						break;
					}
				case 0x07: {
						var pdu = new AAbort();
						pdu.Read(raw);
						Logger.Info("{logId} <- Abort: {pduSource} - {pduReason}", LogID, pdu.Source, pdu.Reason);
						if (this is IDicomServiceProvider)
							(this as IDicomServiceProvider).OnReceiveAbort(pdu.Source, pdu.Reason);
						else if (this is IDicomServiceUser)
							(this as IDicomServiceUser).OnReceiveAbort(pdu.Source, pdu.Reason);
						CloseConnection(null);
						break;
					}
				case 0xFF: {
						break;
					}
				default:
					throw new DicomNetworkException("Unknown PDU type");
				}

				BeginReadPDUHeader();
			} catch (IOException e) {
				if (e.InnerException is SocketException) {
					Logger.Error("Socket error while reading PDU: {socketErrorCode} [{errorCode}]", (e.InnerException as SocketException).SocketErrorCode, (e.InnerException as SocketException).ErrorCode);
				} else if (!(e.InnerException is ObjectDisposedException))
					Logger.Error("IO exception while reading PDU: {@error}", e);

//.........这里部分代码省略.........
开发者ID:dremerdt,项目名称:fo-dicom,代码行数:101,代码来源:DicomService.cs


示例11: Write

		/// <summary>
		/// Writes A-ASSOCIATE-AC to PDU buffer
		/// </summary>
		/// <returns>PDU buffer</returns>
		public RawPDU Write() {
			RawPDU pdu = new RawPDU((byte)0x02);

			pdu.Write("Version", (ushort)0x0001);
			pdu.Write("Reserved", 0x00, 2);
			pdu.Write("Called AE", _assoc.CalledAE, 16, ' ');
			pdu.Write("Calling AE", _assoc.CallingAE, 16, ' ');
			pdu.Write("Reserved", 0x00, 32);

			// Application Context
			pdu.Write("Item-Type", (byte)0x10);
			pdu.Write("Reserved", (byte)0x00);
			pdu.MarkLength16("Item-Length");
			pdu.Write("Application Context Name", DicomUID.DICOMApplicationContextName.UID);
			pdu.WriteLength16();

			foreach (var pc in _assoc.PresentationContexts) {
				// Presentation Context
				pdu.Write("Item-Type", (byte)0x21);
				pdu.Write("Reserved", (byte)0x00);
				pdu.MarkLength16("Item-Length");
				pdu.Write("Presentation Context ID", (byte)pc.ID);
				pdu.Write("Reserved", (byte)0x00);
				pdu.Write("Result", (byte)pc.Result);
				pdu.Write("Reserved", (byte)0x00);

				// Transfer Syntax
				pdu.Write("Item-Type", (byte)0x40);
				pdu.Write("Reserved", (byte)0x00);
				pdu.MarkLength16("Item-Length");
				pdu.Write("Transfer Syntax UID", pc.AcceptedTransferSyntax.UID.UID);
				pdu.WriteLength16();

				pdu.WriteLength16();
			}

			// User Data Fields
			pdu.Write("Item-Type", (byte)0x50);
			pdu.Write("Reserved", (byte)0x00);
			pdu.MarkLength16("Item-Length");

			// Maximum PDU
			pdu.Write("Item-Type", (byte)0x51);
			pdu.Write("Reserved", (byte)0x00);
			pdu.Write("Item-Length", (ushort)0x0004);
			pdu.Write("Max PDU Length", (uint)_assoc.MaximumPDULength);

			// Implementation Class UID
			pdu.Write("Item-Type", (byte)0x52);
			pdu.Write("Reserved", (byte)0x00);
			pdu.MarkLength16("Item-Length");
			pdu.Write("Implementation Class UID", DicomImplementation.ClassUID.UID);
			pdu.WriteLength16();

			// Asynchronous Operations Negotiation
			if (_assoc.MaxAsyncOpsInvoked != 1 || _assoc.MaxAsyncOpsPerformed != 1) {
				pdu.Write("Item-Type", (byte)0x53);
				pdu.Write("Reserved", (byte)0x00);
				pdu.Write("Item-Length", (ushort)0x0004);
				pdu.Write("Asynchronous Operations Invoked", (ushort)_assoc.MaxAsyncOpsInvoked);
				pdu.Write("Asynchronous Operations Performed", (ushort)_assoc.MaxAsyncOpsPerformed);
			}

			// Implementation Version
			pdu.Write("Item-Type", (byte)0x55);
			pdu.Write("Reserved", (byte)0x00);
			pdu.MarkLength16("Item-Length");
			pdu.Write("Implementation Version", DicomImplementation.Version);
			pdu.WriteLength16();

			pdu.WriteLength16();

			return pdu;
		}
开发者ID:dremerdt,项目名称:fo-dicom,代码行数:78,代码来源:PDU.cs


示例12: Write

        /// <summary>
        /// Writes A-ASSOCIATE-RQ to PDU buffer
        /// </summary>
        /// <returns>PDU buffer</returns>
        public RawPDU Write()
        {
            RawPDU pdu = new RawPDU((byte)0x01);

            pdu.Write("Version", (ushort)0x0001);
            pdu.Write("Reserved", 0x00, 2);
            pdu.Write("Called AE", _assoc.CalledAE, 16, ' ');
            pdu.Write("Calling AE", _assoc.CallingAE, 16, ' ');
            pdu.Write("Reserved", 0x00, 32);

            // Application Context
            pdu.Write("Item-Type", (byte)0x10);
            pdu.Write("Reserved", (byte)0x00);
            pdu.MarkLength16("Item-Length");
            pdu.Write("Application Context Name", DicomUID.DICOMApplicationContextName.UID);
            pdu.WriteLength16();

            foreach (var pc in _assoc.PresentationContexts)
            {
                // Presentation Context
                pdu.Write("Item-Type", (byte)0x20);
                pdu.Write("Reserved", (byte)0x00);
                pdu.MarkLength16("Item-Length");
                pdu.Write("Presentation Context ID", (byte)pc.ID);
                pdu.Write("Reserved", (byte)0x00, 3);

                // Abstract Syntax
                pdu.Write("Item-Type", (byte)0x30);
                pdu.Write("Reserved", (byte)0x00);
                pdu.MarkLength16("Item-Length");
                pdu.Write("Abstract Syntax UID", pc.AbstractSyntax.UID);
                pdu.WriteLength16();

                // Transfer Syntax
                foreach (DicomTransferSyntax ts in pc.GetTransferSyntaxes())
                {
                    pdu.Write("Item-Type", (byte)0x40);
                    pdu.Write("Reserved", (byte)0x00);
                    pdu.MarkLength16("Item-Length");
                    pdu.Write("Transfer Syntax UID", ts.UID.UID);
                    pdu.WriteLength16();
                }

                pdu.WriteLength16();
            }

            // User Data Fields
            pdu.Write("Item-Type", (byte)0x50);
            pdu.Write("Reserved", (byte)0x00);
            pdu.MarkLength16("Item-Length");

            // Maximum PDU
            pdu.Write("Item-Type", (byte)0x51);
            pdu.Write("Reserved", (byte)0x00);
            pdu.Write("Item-Length", (ushort)0x0004);
            pdu.Write("Max PDU Length", (uint)_assoc.MaximumPDULength);

            // Implementation Class UID
            pdu.Write("Item-Type", (byte)0x52);
            pdu.Write("Reserved", (byte)0x00);
            pdu.MarkLength16("Item-Length");
            pdu.Write("Implementation Class UID", DicomImplementation.ClassUID.UID);
            pdu.WriteLength16();

            // Asynchronous Operations Negotiation
            if (_assoc.MaxAsyncOpsInvoked != 1 || _assoc.MaxAsyncOpsPerformed != 1)
            {
                pdu.Write("Item-Type", (byte)0x53);
                pdu.Write("Reserved", (byte)0x00);
                pdu.Write("Item-Length", (ushort)0x0004);
                pdu.Write("Asynchronous Operations Invoked", (ushort)_assoc.MaxAsyncOpsInvoked);
                pdu.Write("Asynchronous Operations Performed", (ushort)_assoc.MaxAsyncOpsPerformed);
            }

            foreach (var pc in _assoc.PresentationContexts)
            {
                if (pc.UserRole.HasValue || pc.ProviderRole.HasValue)
                {
                    pdu.Write("Item-Type", (byte)0x54);
                    pdu.Write("Reserved", (byte)0x00);
                    pdu.MarkLength16("Item-Length");
                    pdu.MarkLength16("UID-Length");
                    pdu.Write("Abstract Syntax UID", pc.AbstractSyntax.UID);
                    pdu.WriteLength16();
                    pdu.Write("SCU Role", pc.UserRole.GetValueOrDefault() ? (byte)1 : (byte)0);
                    pdu.Write("SCP Role", pc.ProviderRole.GetValueOrDefault() ? (byte)1 : (byte)0);
                    pdu.WriteLength16();
                }
            }

            // Implementation Version
            pdu.Write("Item-Type", (byte)0x55);
            pdu.Write("Reserved", (byte)0x00);
            pdu.MarkLength16("Item-Length");
            pdu.Write("Implementation Version", DicomImplementation.Version);
            pdu.WriteLength16();
//.........这里部分代码省略.........
开发者ID:aerik,项目名称:fo-dicom,代码行数:101,代码来源:PDU.cs


示例13: Read

        /// <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)
//.........这里部分代码省略.........
开发者ID:aerik,项目名称:fo-dicom,代码行数:101,代码来源:PDU.cs


示例14: ReadAndProcessPDUs

        private async void ReadAndProcessPDUs()
        {
            try
            {
                while (this.IsConnected)
                {
                    // Read PDU header
                    _readLength = 6;

                    var buffer = new byte[6];
                    var count = await this._network.ReadAsync(buffer, 0, 6).ConfigureAwait(false);

                    do
                    {
                        if (count == 0)
                        {
                            // disconnected
                            this.CloseConnection(null);
                            return;
                        }

                        this._readLength -= count;
                        if (this._readLength > 0)
                        {
                            count =
                                await
                                this._network.ReadAsync(buffer, 6 - this._readLength, this._readLength)
                                    .ConfigureAwait(false);
                        }
                    }
                    while (this._readLength > 0);

                    var length = BitConverter.ToInt32(buffer, 2);
                    length = Endian.Swap(length);

                    this._readLength = length;

                    Array.Resize(ref buffer, length + 6);

                    count = await this._network.ReadAsync(buffer, 6, length).ConfigureAwait(false);

                    // Read PDU
                    do
                    {
                        if (count == 0)
                        {
                            // disconnected
                            this.CloseConnection(null);
                            return;
                        }

                        this._readLength -= count;
                        if (this._readLength > 0)
                        {
                            count =
                                await
                                this._network.ReadAsync(buffer, buffer.Length - this._readLength, this._readLength)
                                    .ConfigureAwait(false);
                        }
                    }
                    while (this._readLength > 0);

                    var raw = new RawPDU(buffer);

                    switch (raw.Type)
                    {
                        case 0x01:
                            {
                                Association = new DicomAssociation();
                                var pdu = new AAssociateRQ(Association);
                                pdu.Read(raw);
                                LogID = Association.CallingAE;
                                if (Options.UseRemoteAEForLogName) Logger = LogManager.GetLogger(LogID);
                                Logger.Info(
                                    "{callingAE} <- Association request:\n{association}",
                                    LogID,
                                    Association.ToString());
                                if (this is IDicomServiceProvider) (this as IDicomServiceProvider).OnReceiveAssociationRequest(Association);
                                break;
                            }
                        case 0x02:
                            {
                                var pdu = new AAssociateAC(Association);
                                pdu.Read(raw);
                                LogID = Association.CalledAE;
                                Logger.Info(
                                    "{calledAE} <- Association accept:\n{assocation}",
                                    LogID,
                                    Association.ToString());
                                if (this is IDicomServiceUser) (this as IDicomServiceUser).OnReceiveAssociationAccept(Association);
                                break;
                            }
                        case 0x03:
                            {
                                var pdu = new AAssociateRJ();
                                pdu.Read(raw);
                                Logger.Info(
                                    "{logId} <- Association reject [result: {pduResult}; source: {pduSource}; reason: {pduReason}]",
                                    LogID,
                                    pdu.Result,
//.........这里部分代码省略.........
开发者ID:gustavosaita,项目名称:fo-dicom,代码行数:101,代码来源:DicomService.cs


示例15: SendRawPDU

 private void SendRawPDU(RawPDU pdu)
 {
     try {
         lock (_socket) {
             _disableTimeout = true;
             pdu.WritePDU(_network);
             _disableTimeout = false;
         }
     }
     catch (Exception e) {
     #if DEBUG
         Log.Error("{0} -> Error sending PDU [type: 0x{1:x2}]: {2}", LogID, pdu.Type, e.ToString());
     #else
         Log.Error("{0} -> Error sending PDU [type: 0x{1:x2}]: {2}", LogID, pdu.Type, e.Message);
     #endif
         OnNetworkError(e);
     }
 }
开发者ID:JeanLedesma,项目名称:mdcm,代码行数:18,代码来源:DcmNetworkBase.cs


示例16: Create

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DigitalPlatform.Stop类代码示例发布时间:2022-05-24
下一篇:
C# Network.DcmStatus类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap