LAUREL BRIDGE

LaurelBridge.DCF.Examples.QuerySCPExtended Namespace

DICOM Connectivity Framework V3.4
The QuerySCPExtended example demonstrates how to use the DCF to implement a simple Q/R service class provider that extends the stock QRSCP, overriding methods to handle the CFindRequest, CMoveRequest, CGetRequest, and CCancelRequest DIMSE messages.
Classes

  ClassDescription
Public classOverrideQRSCP
The OverrideQRSCP class provides an alternate implementation of the QRSCP that overrides the QRSCP methods directly, instead of using the callback techniques used in the QuerySCPCallback.
Public classProgram
Basic query/retrieve service class provider example which should be run with the QuerySCU.
Public classProgramExtendedQueryServer
A class that demonstrates the callback style server for a QR SCP.
Examples

QuerySCPExtended Sample Code
public class Program
{
    /// <summary>
    /// Main entry point for QuerySCPExtended.
    /// </summary>
    /// <param name="args">Program arguments.</param>
    [STAThread]
    public static void Main(string[] args)
    {
        try
        {
            AllowedPresentationContext cFindContext = new AllowedPresentationContext(
                Uids.StudyRootQueryRetrieveInformationModelFIND,
                new List<string> { Uids.TransferSyntax.ExplicitVRLittleEndian, Uids.TransferSyntax.ImplicitVRLittleEndian });

            AllowedPresentationContext cMoveContext = new AllowedPresentationContext(
                Uids.StudyRootQueryRetrieveInformationModelMOVE,
                new List<string> { Uids.TransferSyntax.ExplicitVRLittleEndian, Uids.TransferSyntax.ImplicitVRLittleEndian });

            AllowedPresentationContext cGetContext = new AllowedPresentationContext(
                Uids.StudyRootQueryRetrieveInformationModelGET,
                new List<string> { Uids.TransferSyntax.ExplicitVRLittleEndian, Uids.TransferSyntax.ImplicitVRLittleEndian });

            AllowedPresentationContext mrStore = new AllowedPresentationContext(
                Uids.MRImageStorage,
                new List<string> { Uids.ILE });

            ExtendedQueryServer queryServer = new ExtendedQueryServer(
                new List<AllowedPresentationContext> { cFindContext, cMoveContext, cGetContext, mrStore });

            AssociationManager mgr = new AssociationManager();
            mgr.ServerTcpPort = 104;
            mgr.AssociationConfigPolicyMgr = queryServer;
            mgr.AddAssociationListener(queryServer);

            // AssociationManager.run() blocks, so start him listening for connections on a separate thread
            Thread t = new Thread(mgr.Run);
            t.Start();
            if (!mgr.WaitForRunning(2000))
            {
                throw new TimeoutException("AssociationManager did not start in an acceptable amount of time");
            }

            Console.WriteLine("listening on {0}...", mgr.ServerTcpPort);
        }
        catch (Exception e)
        {
            Console.WriteLine("Error during execution: {0}", e);
            Environment.ExitCode = 1;
        }
    }


    /// <summary>
    /// A class that demonstrates the callback style server for a QR SCP.
    /// </summary>
    /// <remarks>
    /// <para>
    /// The <see cref="IAssociationConfigPolicyManager"/> allows us to get a callback to set our
    /// session settings for the association.
    /// </para>
    /// <para>
    /// This class overrides the <see cref="AssociationListenerAdapter.BeginAssociation"/> method
    /// to install a QRSCP.
    /// </para>
    /// <para>
    /// Other <see cref="AssociationListenerAdapter"/> methods may be overridden to implement
    /// additional functionality.
    /// </para>
    /// </remarks>
    public class ExtendedQueryServer : AssociationListenerAdapter, IAssociationConfigPolicyManager
    {
        readonly IList<AllowedPresentationContext> _presentationContexts;

        /// <summary>
        /// Constructs an ExtendedQueryServer will service incoming associations.
        /// </summary>
        /// <param name="allowedPresentationContexts">The list of presentation contexts that will be allowed</param>
        public ExtendedQueryServer(IList<AllowedPresentationContext> allowedPresentationContexts)
        {
            _presentationContexts = allowedPresentationContexts;
        }

        #region IAssociationConfigPolicyManager Overrides
        /// <summary>
        /// Returns a DicomSessionSettings object to be used for the association.
        /// </summary>
        /// <param name="assoc">The AssociationAcceptor for the given association</param>
        /// <returns>The DicomSessionSettings for the given association.</returns>
        public DicomSessionSettings GetSessionSettings(AssociationAcceptor assoc)
        {
            return new DicomSessionSettings() { SessionName = String.Format("QRServer: {0}", assoc.DicomSocket.ConnectionID) };
        }
        #endregion

        #region AssociationListener Overrides
        /// <summary>
        /// Creates the QRSCP to handle the association that caused this method to be called.
        /// </summary>
        /// <param name="assoc">The AssociationAcceptor for the given association</param>
        public override void BeginAssociation(AssociationAcceptor assoc)
        {
            assoc.RegisterServiceClassProvider(new OverrideQRSCP(assoc, _presentationContexts));
        }
        #endregion
    }
}