Example #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);
            }
        }
Example #2
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");
            }
        }