예제 #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <remarks>
        /// The constructor creates a dictionary of each presentation context negotiated for the
        /// association, and the plugin that will handle it.  This is used later when incoming request
        /// messages are processed.
        /// </remarks>
        /// <param name="server">The server.</param>
        /// <param name="parameters">Association parameters for the negotiated association.</param>
        /// <param name="userParms">User parameters to be passed to the plugins called by the class.</param>
        /// <param name="verifier">Delegate to call to verify an association before its accepted.</param>
        /// <param name="complete">Delegate to call when the association is closed/complete.  Can be null.</param>
        public DicomScpHandler(DicomServer server, ServerAssociationParameters parameters, TContext userParms, DicomScp <TContext> .AssociationVerifyCallback verifier, DicomScp <TContext> .AssociationComplete complete)
        {
            _context  = userParms;
            _verifier = verifier;
            _complete = complete;

            var ep = new DicomScpExtensionPoint <TContext>();

            object[] scps = ep.CreateExtensions();

            // First set the user parms for each of the extensions before we do anything with them.
            foreach (object obj in scps)
            {
                var scp = obj as IDicomScp <TContext>;
                if (scp != null)
                {
                    scp.SetContext(_context);
                }
            }

            // Now, create a dictionary with the extension to be used for each presentation context.
            foreach (byte pcid in parameters.GetPresentationContextIDs())
            {
                if (parameters.GetPresentationContextResult(pcid) == DicomPresContextResult.Accept)
                {
                    SopClass       acceptedSop    = SopClass.GetSopClass(parameters.GetAbstractSyntax(pcid).UID);
                    TransferSyntax acceptedSyntax = parameters.GetAcceptedTransferSyntax(pcid);
                    foreach (object obj in scps)
                    {
                        var scp = obj as IDicomScp <TContext>;
                        if (scp == null)
                        {
                            continue;
                        }

                        IList <SupportedSop> sops = scp.GetSupportedSopClasses();
                        foreach (SupportedSop sop in sops)
                        {
                            if (sop.SopClass.Equals(acceptedSop))
                            {
                                if (sop.SyntaxList.Contains(acceptedSyntax))
                                {
                                    if (!_extensionList.ContainsKey(pcid))
                                    {
                                        _extensionList.Add(pcid, scp);
                                        break;
                                    }
                                    Platform.Log(LogLevel.Error, "SOP Class {0} supported by more than one extension", sop.SopClass.Name);
                                }
                            }
                        }
                    }
                }
            }

            _statsRecorder = new AssociationStatisticsRecorder(server);
        }
예제 #2
0
        /// <summary>
        /// Create the list of presentation contexts for the DICOM SCP.
        /// </summary>
        /// <remarks>
        /// The method loads the DICOM Scp plugins, and then queries them
        /// to construct a list of presentation contexts that are supported.
        /// </remarks>
        private void CreatePresentationContexts()
        {
            DicomScpExtensionPoint <TContext> ep = new DicomScpExtensionPoint <TContext>();

            object[] scps = ep.CreateExtensions();
            foreach (object obj in scps)
            {
                IDicomScp <TContext> scp = obj as IDicomScp <TContext>;
                scp.SetContext(_context);

                IList <SupportedSop> sops = scp.GetSupportedSopClasses();
                foreach (SupportedSop sop in sops)
                {
                    byte pcid = _assocParameters.FindAbstractSyntax(sop.SopClass);
                    if (pcid == 0)
                    {
                        pcid = _assocParameters.AddPresentationContext(sop.SopClass);
                    }

                    // Now add all the transfer syntaxes, if necessary
                    foreach (TransferSyntax syntax in sop.SyntaxList)
                    {
                        // Check if the syntax is registered already
                        if (0 == _assocParameters.FindAbstractSyntaxWithTransferSyntax(sop.SopClass, syntax))
                        {
                            _assocParameters.AddTransferSyntax(pcid, syntax);
                        }
                    }
                }
            }

            // Sort the presentation contexts, and put them in the order that we prefer them.
            // Favor Explicit over Implicit transfer syntaxes, lossless compression over lossy
            // compression, and lossless compressed over uncompressed.
            foreach (DicomPresContext serverContext in _assocParameters.GetPresentationContexts())
            {
                serverContext.SortTransfers(delegate(TransferSyntax s1, TransferSyntax s2)
                {
                    if (s1.Equals(s2))
                    {
                        return(0);
                    }
                    if (s1.ExplicitVr && !s2.ExplicitVr)
                    {
                        return(-1);
                    }
                    if (!s1.ExplicitVr && s2.ExplicitVr)
                    {
                        return(1);
                    }
                    if (s1.Encapsulated && s2.Encapsulated)
                    {
                        if (s1.LosslessCompressed == s2.LosslessCompressed)
                        {
                            return(0);
                        }
                        if (s1.LosslessCompressed && s2.LossyCompressed)
                        {
                            return(-1);
                        }
                        return(1);
                    }
                    if (s1.Encapsulated)
                    {
                        if (s1.LossyCompressed)
                        {
                            return(1);
                        }
                        return(-1);
                    }

                    if (s2.Encapsulated)
                    {
                        if (s2.LossyCompressed)
                        {
                            return(-1);
                        }
                        return(1);
                    }
                    return(0);
                }
                                            );
            }
        }