Exemple #1
0
        public void DoAssociateRequest(CFindClient client, DicomAssociate association)
        {
            using (DicomAssociate retAssociate = new DicomAssociate(false))
            {
                if (retAssociate == null)
                {
                    client.SendAssociateReject(DicomAssociateRejectResultType.Permanent,
                                               DicomAssociateRejectSourceType.Provider1,
                                               DicomAssociateRejectReasonType.Application);
                    return;
                }

                retAssociate.MaxLength = 46726;
                retAssociate.Version   = 1;
                retAssociate.Called    = (CalledAE == null) ? association.Called : CalledAE;
                retAssociate.Calling   = (CallingAE == null) ? association.Calling : CallingAE;
                retAssociate.ApplicationContextName = (string)DicomUidType.ApplicationContextName;

                for (int i = 0; i < association.PresentationContextCount; i++)
                {
                    byte   id             = association.GetPresentationContextID(i);
                    string abstractSyntax = association.GetAbstract(id);

                    retAssociate.AddPresentationContext(id, DicomAssociateAcceptResultType.Success, abstractSyntax);
                    if (IsSupported(abstractSyntax))
                    {
                        for (int j = 0; j < association.GetTransferCount(id); j++)
                        {
                            string transferSyntax = association.GetTransfer(id, j);

                            if (IsSupported(transferSyntax))
                            {
                                retAssociate.AddTransfer(id, transferSyntax);
                                break;
                            }
                        }

                        if (retAssociate.GetTransferCount(id) == 0)
                        {
                            //
                            // Presentation id doesn't have any abstract
                            //  syntaxes therefore we will reject it.
                            //
                            retAssociate.SetResult(id, DicomAssociateAcceptResultType.AbstractSyntax);
                        }
                    }
                    else
                    {
                        retAssociate.SetResult(id, DicomAssociateAcceptResultType.AbstractSyntax);
                    }
                }

                if (association.MaxLength != 0)
                {
                    retAssociate.MaxLength = association.MaxLength;
                }

                retAssociate.ImplementClass            = ImplementationClass;
                retAssociate.ImplementationVersionName = ImplementationVersionName;

                client.SendAssociateAccept(retAssociate);
            }
        }
Exemple #2
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);
        }
Exemple #3
0
        /*
         * Performs an Association request
         */
        public void DoAssociateRequest(Client client, DicomAssociate association)
        {
            mf.Log("Client Name: " + association.Calling + " -- Receiving Associate Request.\r\n");

            // Check association
            if (association == null)
            {
                client.SendAssociateReject(DicomAssociateRejectResultType.Permanent, DicomAssociateRejectSourceType.Provider1, DicomAssociateRejectReasonType.Application);
                mf.Log("Client Name: " + association.Calling + " -- Failed in accepting the connection (Associate was null)!\r\nSending associate reject!\r\n");
                return;
            }

            // Check version
            if (association.Version != 1)
            {
                client.SendAssociateReject(DicomAssociateRejectResultType.Permanent, DicomAssociateRejectSourceType.Provider1, DicomAssociateRejectReasonType.Version);
                mf.Log("Client Name: " + association.Calling + " -- Failed in accepting the connection (Version Not supported)!\r\nSending associate reject!\r\n");
                return;
            }

            // Make sure that the client is supported
            if (!VerifyUserName(association.Calling))
            {
                client.SendAssociateReject(DicomAssociateRejectResultType.Permanent, DicomAssociateRejectSourceType.User, DicomAssociateRejectReasonType.Calling);
                mf.Log("Client Name: " + association.Calling + " -- Failed in accepting the connection (Not a valid client name)!\r\nSending associate reject!\r\n");
                return;
            }

            // Check the Called AE title (SCP)
            if (association.Called != CalledAE)
            {
                client.SendAssociateReject(DicomAssociateRejectResultType.Permanent, DicomAssociateRejectSourceType.User, DicomAssociateRejectReasonType.Called);
                mf.Log("Client Name: " + association.Calling + " -- Failed in accepting the connection (Server names are not the same)!\r\n Sending associate reject!\r\n");
                return;
            }

            // Send association back
            using (DicomAssociate retAssociate = new DicomAssociate(false))
            {
                retAssociate.MaxLength = 46726;
                retAssociate.Version   = 1;
                retAssociate.Called    = CalledAE;
                retAssociate.Calling   = (CallingAE == null) ? association.Calling : CallingAE;
                retAssociate.ApplicationContextName = (string)DicomUidType.ApplicationContextName;

                for (int i = 0; i < association.PresentationContextCount; i++)
                {
                    byte   id             = association.GetPresentationContextID(i);
                    string abstractSyntax = association.GetAbstract(id);

                    retAssociate.AddPresentationContext(id, DicomAssociateAcceptResultType.Success, abstractSyntax);
                    if (IsSupported(abstractSyntax))
                    {
                        for (int j = 0; j < association.GetTransferCount(id); j++)
                        {
                            string transferSyntax = association.GetTransfer(id, j);

                            if (IsSupported(transferSyntax))
                            {
                                retAssociate.AddTransfer(id, transferSyntax);
                                break;
                            }
                        }

                        if (retAssociate.GetTransferCount(id) == 0)
                        {
                            // Presentation id doesn't have any abstract syntaxes therefore we will reject it.
                            retAssociate.SetResult(id, DicomAssociateAcceptResultType.AbstractSyntax);
                        }
                    }
                    else
                    {
                        retAssociate.SetResult(id, DicomAssociateAcceptResultType.AbstractSyntax);
                    }
                }

                if (association.MaxLength != 0)
                {
                    retAssociate.MaxLength = association.MaxLength;
                }

                retAssociate.ImplementClass            = ImplementationClass;
                retAssociate.ImplementationVersionName = ImplementationVersionName;

                client.SendAssociateAccept(retAssociate);
                mf.Log("Client Name: " + association.Calling + " -- Sending Associate Accept.\r\n");
            }
        }