Пример #1
0
        public override PresentationContextCollection GetPresentationContext( )
        {
            PresentationContextCollection pc = new PresentationContextCollection();
            PresentationContext           p;

            try
            {
                string VerificationClass;

                VerificationClass = DicomUidType.VerificationClass;

                // Check to make sure the Presentation Context isn't already in the collection
                p = FindPresentationContext(VerificationClass, pc);
                if (p == null)
                {
                    p = new PresentationContext();

                    p.AbstractSyntax = VerificationClass;
                    pc.Add(p);
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
            }
            return(pc);
        }
Пример #2
0
        /// <summary>
        /// Creates presentation contexts to be used in an A-ASSOCIATE-AC that are based on the
        /// presentation contexts of this instance.
        /// </summary>
        /// <remarks>
        /// The following holds for the returned presentation contexts:
        /// - All requested presentation contexts with an abstract syntax contained in the supplied
        ///   SOP classes will be accepted (have result field 0). The rest will be rejected
        ///   (have result field 3).
        /// - For each accepted requested presentation context, the first proposed transfer syntax
        ///   will be used.
        /// </remarks>
        /// <param name="sopClasses">The SOP Classes to accept.</param>
        /// <returns>The created presentation contexts.</returns>
        public PresentationContextCollection CreatePresentationContextsForAssociateAc(SopClasses sopClasses)
        {
            PresentationContextCollection presentationContextsForAssociateAc = new PresentationContextCollection();

            PresentationContextCollection presentationContexts = PresentationContexts;

            foreach (PresentationContext presentationContextInAssociateRq in presentationContexts)
            {
                String abstractSyntaxInAssociateRq = presentationContextInAssociateRq.AbstractSyntax;

                PresentationContext presentationContextForAssociateAc = null;

                if (sopClasses.List.Contains(abstractSyntaxInAssociateRq))
                {
                    presentationContextForAssociateAc = new PresentationContext
                                                            (presentationContextInAssociateRq.AbstractSyntax,
                                                            0,
                                                            presentationContextInAssociateRq.TransferSyntaxes[0]);
                }
                else
                {
                    presentationContextForAssociateAc = new PresentationContext
                                                            (presentationContextInAssociateRq.AbstractSyntax,
                                                            3,
                                                            "");
                }

                presentationContextForAssociateAc.SetId(presentationContextInAssociateRq.ID);

                presentationContextsForAssociateAc.Add(presentationContextForAssociateAc);
            }

            return(presentationContextsForAssociateAc);
        }
Пример #3
0
        public override PresentationContextCollection GetPresentationContext()
        {
            PresentationContextCollection pc = new PresentationContextCollection();
            PresentationContext           p;

            p = new PresentationContext();
            p.AbstractSyntax = DicomUidType.PatientRootQueryFind;
            p.TransferSyntaxList.Add(DicomUidType.ImplicitVRLittleEndian);
            pc.Add(p);

            p = new PresentationContext();
            p.AbstractSyntax = DicomUidType.StudyRootQueryFind;
            p.TransferSyntaxList.Add(DicomUidType.ImplicitVRLittleEndian);
            pc.Add(p);

            p = new PresentationContext();
            p.AbstractSyntax = DicomUidType.StudyRootQueryMove;
            p.TransferSyntaxList.Add(DicomUidType.ImplicitVRLittleEndian);
            pc.Add(p);

            p = new PresentationContext();
            p.AbstractSyntax = DicomUidType.VerificationClass;
            p.TransferSyntaxList.Add(DicomUidType.ImplicitVRLittleEndian);
            pc.Add(p);

            p = new PresentationContext();
            p.AbstractSyntax = DicomUidType.PatientRootQueryMove;
            p.TransferSyntaxList.Add(DicomUidType.ImplicitVRLittleEndian);
            pc.Add(p);

            return(pc);
        }
Пример #4
0
        /// <summary>
        /// Creates presentation contexts to be used in an A-ASSOCIATE-AC that are based on the
        /// presentation contexts of this instance.
        /// </summary>
        /// <remarks>
        /// The following holds for the returned presentation contexts:<br></br>
        /// - All requested presentation contexts with an abstract syntax not contained in the supplied
        ///   SOP classes will be rejected (have result field 3).<br></br>
        /// - For each other requested presentation contex that has an abstract syntax contained in
        ///   the supplied SOP classes, do the following:<br></br>
        ///   1)<br></br>
        ///   Check if one or more of the requested transfer syntaxes is present in the first supplied
        ///   TransferSyntaxes instance. If this is the case, use the requested transfer syntax that is
        ///   requested before the other ones in the accepted presentation context counterpart (has
        ///   result field 0).<br></br>
        ///   2)<br></br>
        ///   If no requested transfer syntaxes was present, try this with the second supplied
        ///   TransferSyntaxes instance.<br></br>
        ///   3) If no requested transfer syntaxes was present is in any supplied TransferSyntaxes
        ///   instance, reject the presentation context with result 4.<br></br>
        ///
        ///   Note that a difference exists between supplying one TransferSyntaxes instance with all
        ///   transfer syntaxes to accept and supplying multiple TransferSyntaxes instances each containing
        ///   only one transfer syntax. In the first case, the preference (order of proposed transfer
        ///   syntaxes) of the SCU will be used, in the second case the preference of the caller of this
        ///   method will be used.
        /// </remarks>
        /// <param name="sopClasses">The SOP Classes to accept.</param>
        /// <param name="transferSyntaxesList">The transfer syntaxes to accept.</param>
        /// <returns>The created presentation contexts.</returns>
        public PresentationContextCollection CreatePresentationContextsForAssociateAc(SopClasses sopClasses, params TransferSyntaxes[] transferSyntaxesList)
        {
            PresentationContextCollection presentationContextsForAssociateAc = new PresentationContextCollection();

            PresentationContextCollection presentationContexts = PresentationContexts;

            foreach (PresentationContext presentationContextInAssociateRq in presentationContexts)
            {
                String abstractSyntaxInAssociateRq = presentationContextInAssociateRq.AbstractSyntax;

                PresentationContext presentationContextForAssociateAc = null;

                if (sopClasses.List.Contains(abstractSyntaxInAssociateRq))
                {
                    String transferSyntaxForAssociateAc = DetermineTransferSyntaxToAccept
                                                              (presentationContextInAssociateRq.TransferSyntaxes,
                                                              transferSyntaxesList);

                    if (transferSyntaxForAssociateAc.Length == 0)
                    {
                        presentationContextForAssociateAc = new PresentationContext
                                                                (presentationContextInAssociateRq.AbstractSyntax,
                                                                4,
                                                                "");
                    }
                    else
                    {
                        presentationContextForAssociateAc = new PresentationContext
                                                                (presentationContextInAssociateRq.AbstractSyntax,
                                                                0,
                                                                transferSyntaxForAssociateAc);
                    }
                }
                else
                {
                    presentationContextForAssociateAc = new PresentationContext
                                                            (presentationContextInAssociateRq.AbstractSyntax,
                                                            3,
                                                            "");
                }

                presentationContextForAssociateAc.SetId(presentationContextInAssociateRq.ID);

                presentationContextsForAssociateAc.Add(presentationContextForAssociateAc);
            }

            return(presentationContextsForAssociateAc);
        }
Пример #5
0
 private PresentationContext FindPresentationContext(string StorageClass, PresentationContextCollection pc)
 {
     foreach (PresentationContext pCtxt in pc)
     {
         try
         {
             if (pCtxt.AbstractSyntax == StorageClass)
             {
                 return(pCtxt);
             }
         }
         catch (Exception ex)
         {
             System.Windows.Forms.MessageBox.Show(ex.ToString());
         }
     }
     return(null);
 }
Пример #6
0
        //
        // - Methods -
        //

        /// <summary>
        /// Creates presentation contexts to be used in an A-ASSOCIATE-AC that are based on the
        /// presentation contexts of this instance.
        /// </summary>
        /// <remarks>
        /// The following holds for the returned presentation contexts:
        /// - All requested presentation contexts will be accepted (have result field 0).
        /// - For each requested presentation context, the first proposed transfer syntax will be used.
        /// </remarks>
        /// <returns>The created presentation contexts.</returns>
        public PresentationContextCollection CreatePresentationContextsForAssociateAc()
        {
            PresentationContextCollection presentationContextsForAssociateAc = new PresentationContextCollection();

            PresentationContextCollection presentationContexts = PresentationContexts;

            foreach (PresentationContext presentationContextInAssociateRq in presentationContexts)
            {
                PresentationContext presentationContextForAssociateAc = new PresentationContext
                                                                            (presentationContextInAssociateRq.AbstractSyntax,
                                                                            0,
                                                                            presentationContextInAssociateRq.TransferSyntaxes[0]);

                presentationContextForAssociateAc.SetId(presentationContextInAssociateRq.ID);

                presentationContextsForAssociateAc.Add(presentationContextForAssociateAc);
            }

            return(presentationContextsForAssociateAc);
        }
Пример #7
0
        public DicomAssociate BuildAssociation(string CalledTitle, string CallingTitle)
        {
            PresentationContextCollection contexts = GetPresentationContext();
            DicomAssociate association             = new DicomAssociate(true);

            association.Called         = CalledTitle;
            association.Calling        = CallingTitle;
            association.MaxLength      = 46726;
            association.ImplementClass = ImplementationClass;

            byte pid = 1;
            bool addedImplicitVRLittleEndian = false;

            if (PresentationContextType == 0)
            {
                // One presentation context contains all transfer syntaxes
                foreach (PresentationContext pc in contexts)
                {
                    association.AddPresentationContext(pid, 0, pc.AbstractSyntax);
                    addedImplicitVRLittleEndian = false;
                    foreach (string transfersyntax in pc.TransferSyntaxList)
                    {
                        association.AddTransfer(pid, transfersyntax);
                        if (transfersyntax == DicomUidType.ImplicitVRLittleEndian)
                        {
                            addedImplicitVRLittleEndian = true;
                        }
                    }
                    if (!addedImplicitVRLittleEndian)
                    {
                        association.AddTransfer(pid, DicomUidType.ImplicitVRLittleEndian);
                    }
                    pid += 2;
                }
            }
            else
            {
                // Separate presentation context for each transfer syntax
                foreach (PresentationContext pc in contexts)
                {
                    addedImplicitVRLittleEndian = false;
                    foreach (string transfersyntax in pc.TransferSyntaxList)
                    {
                        association.AddPresentationContext(pid, 0, pc.AbstractSyntax);
                        association.AddTransfer(pid, transfersyntax);
                        if (transfersyntax == DicomUidType.ImplicitVRLittleEndian)
                        {
                            addedImplicitVRLittleEndian = true;
                        }
                        pid += 2;
                    }
                    if (!addedImplicitVRLittleEndian)
                    {
                        association.AddPresentationContext(pid, 0, pc.AbstractSyntax);
                        association.AddTransfer(pid, DicomUidType.ImplicitVRLittleEndian);
                        pid += 2;
                    }
                }
            }



            return(association);
        }
Пример #8
0
        /// <summary>
        /// Method to handle the workflow after receiving an Associate Request.
        /// </summary>
        /// <param name="associateRq">Associate Request message.</param>
        public override void AfterHandlingAssociateRequest(AssociateRq associateRq)
        {
            if (IsMessageHandled == false)
            {
                // determine which workflow to follow
                switch (_scpRespondToAssociateRequest)
                {
                case ScpRespondToAssociateRequestEnum.WithAssociateAccept:
                {
                    // send an associate accept with the supported transfer syntaxes.
                    PresentationContextCollection presentationContextsForAssociateAc = new PresentationContextCollection();
                    foreach (PresentationContext reqtedPC in associateRq.PresentationContexts)
                    {
                        String abstractSyntaxInAssociateRq = reqtedPC.AbstractSyntax;

                        PresentationContext presentationContextForAssociateAc = null;

                        if (sopList.Contains(abstractSyntaxInAssociateRq))
                        {
                            String transferSyntaxForAssociateAc = null;
                            this.Options.LocalAeTitle  = associateRq.CalledAETitle;
                            this.Options.RemoteAeTitle = associateRq.CallingAETitle;
                            if (reqtedPC.AbstractSyntax == "1.2.840.10008.1.20.1")
                            {
                                transferSyntaxForAssociateAc = DetermineTransferSyntaxToAccept
                                                                   (reqtedPC.TransferSyntaxes, tsCommitList);
                            }
                            else
                            {
                                transferSyntaxForAssociateAc = DetermineTransferSyntaxToAccept
                                                                   (reqtedPC.TransferSyntaxes, tsStoreList);
                            }

                            if (transferSyntaxForAssociateAc.Length == 0)
                            {
                                presentationContextForAssociateAc = new PresentationContext
                                                                        (reqtedPC.AbstractSyntax,
                                                                        4,
                                                                        "");
                            }
                            else
                            {
                                presentationContextForAssociateAc = new PresentationContext
                                                                        (reqtedPC.AbstractSyntax,
                                                                        0,
                                                                        transferSyntaxForAssociateAc);
                            }
                        }
                        else
                        {
                            presentationContextForAssociateAc = new PresentationContext
                                                                    (reqtedPC.AbstractSyntax,
                                                                    3,
                                                                    "");
                        }

                        presentationContextsForAssociateAc.Add(presentationContextForAssociateAc);
                    }

                    SendAssociateAc(presentationContextsForAssociateAc);
                    isAssociated = true;
                    break;
                }

                case ScpRespondToAssociateRequestEnum.WithAssociateReject:
                    // send an associate reject with the given parameters
                    SendAssociateRj(_rejectResult, _rejectSource, _rejectReason);
                    break;

                case ScpRespondToAssociateRequestEnum.WithAbort:
                default:
                    // send an abort request with the given parameters
                    SendAbort(_abortSource, _abortReason);
                    break;
                }

                // message has now been handled
                IsMessageHandled = true;
            }
        }