protected override void OnReceiveAssociateRequest(DcmAssociate association) { association.NegotiateAsyncOps = false; LogID = association.CallingAE; _config = Config.Instance.FindPrinter(association.CalledAE); if (_config == null) { SendAssociateReject(DcmRejectResult.Permanent, DcmRejectSource.ServiceUser, DcmRejectReason.CalledAENotRecognized); return; } foreach (DcmPresContext pc in association.GetPresentationContexts()) { if (pc.AbstractSyntax == DicomUID.VerificationSOPClass || pc.AbstractSyntax == DicomUID.BasicColorPrintManagementMetaSOPClass || pc.AbstractSyntax == DicomUID.BasicGrayscalePrintManagementMetaSOPClass || pc.AbstractSyntax == DicomUID.PrinterSOPClass || //pc.AbstractSyntax == DicomUID.PrinterConfigurationRetrieval || //pc.AbstractSyntax == DicomUID.PrintJob || pc.AbstractSyntax == DicomUID.BasicFilmSessionSOPClass || pc.AbstractSyntax == DicomUID.BasicFilmBoxSOPClass || pc.AbstractSyntax == DicomUID.BasicGrayscaleImageBoxSOPClass || pc.AbstractSyntax == DicomUID.BasicColorImageBoxSOPClass) { pc.SetResult(DcmPresContextResult.Accept); } else { pc.SetResult(DcmPresContextResult.RejectAbstractSyntaxNotSupported); } } SendAssociateAccept(association); }
public void Apply(DcmAssociate associate) { foreach (DcmPresContext pc in associate.GetPresentationContexts()) { if (pc.Result == DcmPresContextResult.Proposed) { if (AbstractSyntaxes.Contains(pc.AbstractSyntax.UID)) { IList <DicomTransferSyntax> txs = pc.GetTransfers(); for (int i = 0; i < txs.Count; i++) { if (TransferSyntaxes.Contains(txs[i].UID.UID)) { if (!DicomUID.IsImageStorage(pc.AbstractSyntax) && DicomTransferSyntax.IsImageCompression(txs[i])) { continue; } pc.SetResult(DcmPresContextResult.Accept, txs[i]); break; } } if (pc.Result != DcmPresContextResult.Accept) { pc.SetResult(DcmPresContextResult.RejectTransferSyntaxesNotSupported); } } else { pc.SetResult(DcmPresContextResult.RejectAbstractSyntaxNotSupported); } } } }
/// <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 (DcmPresContext pc in _assoc.GetPresentationContexts()) { // 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", 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); }
protected override void OnReceiveAssociateRequest(DcmAssociate association) { Timer = Stopwatch.StartNew(); association.NegotiateAsyncOps = false; LogID = association.CallingAE; Console.WriteLine("{0} Received Association Request from AE:{1} -> {2}", DateTime.Now, association.CallingAE, association.CalledAE ); _flagAnonymousAccess = _flagAnonymousAccess || IsAnonymizedAE(association.CallingAE); foreach (DcmPresContext pc in association.GetPresentationContexts()) { HandleEchoAssociationRequest(pc); if (Settings.Default.DoAllowFind) { HandleFindAssociationRequest(pc); HandleMoveAssociationRequest(pc); } } if( Settings.Default.DoAllowStore ) HandleStoreAssociationRequest(association); SendAssociateAccept(association); }