Esempio n. 1
0
 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);
             }
         }
     }
 }
Esempio n. 2
0
		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);
		}
Esempio n. 3
0
        public static DcmAssociateProfile Find(DcmAssociate associate, bool matchImplentation)
        {
            List <DcmAssociateProfile> candidates = new List <DcmAssociateProfile>();

            foreach (DcmAssociateProfile profile in Profiles)
            {
                if (!Wildcard.Match(profile.CalledAE, associate.CalledAE) || !Wildcard.Match(profile.CallingAE, associate.CallingAE))
                {
                    continue;
                }
                if (matchImplentation &&
                    (!Wildcard.Match(profile.RemoteImplUID, associate.ImplementationClass.UID) ||
                     !Wildcard.Match(profile.RemoteVersion, associate.ImplementationVersion)))
                {
                    continue;
                }
                candidates.Add(profile);
            }
            if (candidates.Count > 0)
            {
                candidates.Sort(delegate(DcmAssociateProfile p1, DcmAssociateProfile p2) {
                    return(p1.GetWeight(matchImplentation) - p2.GetWeight(matchImplentation));
                });
                return(candidates[0]);
            }
            return(GenericStorage);
        }
Esempio n. 4
0
        protected override void OnConnected()
        {
            DcmAssociate associate = new DcmAssociate();

            byte pcid = associate.AddPresentationContext(DicomUID.VerificationSOPClass);
            associate.AddTransferSyntax(pcid, DicomTransferSyntax.ImplicitVRLittleEndian);

            associate.CalledAE = CalledAE;
            associate.CallingAE = CallingAE;
            associate.MaximumPduLength = MaxPduSize;

            SendAssociateRequest(associate);
        }
Esempio n. 5
0
 /// <summary>
 /// A DICOM Application Entity (which includes the Upper Layer service-user) 
 /// that desires to establish an association shall issue an A-ASSOCIATE request 
 /// primitive. The called AE is identified by parameters of the request 
 /// primitive. The requestor shall not issue any primitives except an A-ABORT 
 /// request primitive until it receives an A-ASSOCIATE confirmation primitive.
 /// </summary>
 /// <param name="associate"></param>
 protected void SendAssociateRequest(DcmAssociate associate)
 {
     _assoc = associate;
     Log.Info("{0} -> Association request:\n{1}", LogID, Associate.ToString());
     AAssociateRQ pdu = new AAssociateRQ(_assoc);
     SendRawPDU(pdu.Write());
 }
Esempio n. 6
0
 /// <summary>
 /// The called AE shall accept or reject the association by sending an A-ASSOCIATE 
 /// response primitive with an appropriate Result parameter. The Upper layer 
 /// service-provider shall issue an A-ASSOCIATE confirmation primitive having the 
 /// same Result parameter. The Result Source parameter shall be assigned the 
 /// symbolic value of “UL service-user.”
 /// </summary>
 /// <param name="associate"></param>
 protected void SendAssociateAccept(DcmAssociate associate)
 {
     Log.Info("{0} -> Association accept:\n{1}", LogID, Associate.ToString());
     AAssociateAC pdu = new AAssociateAC(_assoc);
     SendRawPDU(pdu.Write());
 }
Esempio n. 7
0
 protected virtual void OnReceiveAssociateRequest(DcmAssociate association)
 {
     throw new NotImplementedException();
 }
Esempio n. 8
0
        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;
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Initializes new A-ASSOCIATE-AC
 /// </summary>
 /// <param name="assoc">Association parameters</param>
 public AAssociateAC(DcmAssociate assoc)
 {
     _assoc = assoc;
 }
Esempio n. 10
0
 /// <summary>
 /// Initializes new A-ASSOCIATE-RQ
 /// </summary>
 /// <param name="assoc">Association parameters</param>
 public AAssociateRQ(DcmAssociate assoc)
 {
     _assoc = assoc;
 }
Esempio n. 11
0
        protected override void OnConnected()
        {
            DcmAssociate associate = new DcmAssociate();

            byte pcid = associate.AddPresentationContext(DicomUID.PrinterSOPClass);
            associate.AddTransferSyntax(pcid, DicomTransferSyntax.ExplicitVRLittleEndian);
            associate.AddTransferSyntax(pcid, DicomTransferSyntax.ImplicitVRLittleEndian);

            pcid = associate.AddPresentationContext(DicomUID.BasicGrayscalePrintManagementMetaSOPClass);
            associate.AddTransferSyntax(pcid, DicomTransferSyntax.ExplicitVRLittleEndian);
            associate.AddTransferSyntax(pcid, DicomTransferSyntax.ImplicitVRLittleEndian);

            pcid = associate.AddPresentationContext(DicomUID.BasicColorPrintManagementMetaSOPClass);
            associate.AddTransferSyntax(pcid, DicomTransferSyntax.ExplicitVRLittleEndian);
            associate.AddTransferSyntax(pcid, DicomTransferSyntax.ImplicitVRLittleEndian);

            associate.CalledAE = CalledAE;
            associate.CallingAE = CallingAE;
            associate.MaximumPduLength = MaxPduSize;

            SendAssociateRequest(associate);
        }
Esempio n. 12
0
 private static void HandleStoreAssociationRequest(DcmAssociate association)
 {
     DcmAssociateProfile profile = DcmAssociateProfile.Find(association, true);
     profile.Apply(association);
 }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
File: PDU.cs Progetto: hide1980/mdcm
 /// <summary>
 /// Initializes new A-ASSOCIATE-RQ
 /// </summary>
 /// <param name="assoc">Association parameters</param>
 public AAssociateRQ(DcmAssociate assoc)
 {
     _assoc = assoc;
 }
Esempio n. 15
0
File: PDU.cs Progetto: hide1980/mdcm
 /// <summary>
 /// Initializes new A-ASSOCIATE-AC
 /// </summary>
 /// <param name="assoc">Association parameters</param>
 public AAssociateAC(DcmAssociate assoc)
 {
     _assoc = assoc;
 }
Esempio n. 16
0
 protected override void OnReceiveAssociateAccept(DcmAssociate association)
 {
     PerformQueryOrRelease();
 }
Esempio n. 17
0
 protected override void OnReceiveAssociateAccept(DcmAssociate association)
 {
     byte pcid = association.FindAbstractSyntax(DicomUID.VerificationSOPClass);
     SendCEchoRequest(pcid, NextMessageID(), Priority);
 }
Esempio n. 18
0
 /// <summary>
 /// A DICOM Application Entity (which includes the Upper Layer service-user) 
 /// that desires to establish an association shall issue an A-ASSOCIATE request 
 /// primitive. The called AE is identified by parameters of the request 
 /// primitive. The requestor shall not issue any primitives except an A-ABORT 
 /// request primitive until it receives an A-ASSOCIATE confirmation primitive.
 /// </summary>
 /// <param name="associate"></param>
 protected void SendAssociateRequest(DcmAssociate associate)
 {
     _assoc = associate;
     if (UseRemoteAeForLogName) {
         LogID = Associate.CalledAE;
         Log = LogManager.GetLogger(LogID);
     }
     Log.Info("{0} -> Association request:\n{1}", LogID, Associate.ToString());
     AAssociateRQ pdu = new AAssociateRQ(_assoc);
     SendRawPDU(pdu.Write());
 }