LAUREL BRIDGE

LaurelBridge.DCF.Examples.VerificationSCPExtended Namespace

DICOM Connectivity Framework V3.4
The VerificationSCPExtended example demonstrates how to use the DCF to implement a simple Verification (Echo) service class provider that extends the stock VerificationSCP, overriding methods to handle the CEchoRequest DIMSE messages.
Classes

  ClassDescription
Public classProgram
Basic verification service class provider example which should be run with the VerificationSCU.
Public classProgramExtendedVerificationServer
ExtendedVerificationServer handles associations by creating a custom Verification SCP that extends VerificationSCP to handle the C-ECHO requests on the association.
Examples

VerificationSCPExtended Sample Code
public class Program
{
    /// <summary>
    /// Main entry point for VerificationSCPExtended.
    /// </summary>
    /// <param name="args">Program arguments.</param>
    [STAThread]
    public static void Main(string[] args)
    {
        Console.Title = "LaurelBridge.DCF.Examples.VerificationSCPExtended";
        try
        {
            // Create an ExtendedVerificationServer that listens for associations on port 106
            ExtendedVerificationServer extendedVerificationServer = new ExtendedVerificationServer(106);
            extendedVerificationServer.BeginListening();
            Console.WriteLine("listening on {0}...", 106);
        }
        catch (Exception e)
        {
            Console.WriteLine("Error during execution: {0}", e);
            Environment.ExitCode = 1;
        }
    }

    /// <summary>
    /// ExtendedVerificationServer handles associations by creating a custom Verification SCP that extends VerificationSCP to handle the C-ECHO requests on the association.
    /// </summary>
    public class ExtendedVerificationServer : AssociationListenerAdapter, IAssociationConfigPolicyManager
    {
        private readonly AssociationManager _manager;
        private readonly IList<AllowedPresentationContext> _presentationContexts;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="port">Server port</param>
        public ExtendedVerificationServer(int port)
            : this(port, null)
        {
        }

        /// <summary>
        /// Constructor with allowed presentation contexts.
        /// </summary>
        /// <param name="port">Server port</param>
        /// <param name="allowedPresentationContexts">list of allowed presentation contexts</param>
        public ExtendedVerificationServer(int port, IList<AllowedPresentationContext> allowedPresentationContexts)
        {
            _presentationContexts = allowedPresentationContexts;
            _manager = new AssociationManager();
            _manager.ServerTcpPort = port;
            _manager.AddAssociationListener(this);
        }

        /// <summary>
        /// Start listening for associations via the AssociationManager.
        /// </summary>
        public void BeginListening()
        {
            Thread t = new Thread(_manager.Run);
            t.Start();
            if (!_manager.WaitForRunning(2000))
            {
                throw new TimeoutException("AssociationManager did not start in an acceptable amount of time");
            }
        }

        /// <summary>
        /// Stop receiving any new associations.
        /// </summary>
        public void Stop()
        {
            _manager.Stop();
        }

        #region IAssociationConfigPolicyManager implementation
        /// <summary>
        /// Get the session settings for the AssociationAcceptor.
        /// </summary>
        /// <param name="assoc">the AssociationAcceptor</param>
        /// <returns>the session settings</returns>
        public DicomSessionSettings GetSessionSettings(AssociationAcceptor assoc)
        {
            return new DicomSessionSettings();
        }
        #endregion

        #region AssociationListenerAdapter overrides
        /// <summary>
        /// Callback for beginning the association.
        /// </summary>
        /// <param name="assoc">the AssociationAcceptor</param>
        public override void BeginAssociation(AssociationAcceptor assoc)
        {
            assoc.RegisterServiceClassProvider(new MyVerificationScp(assoc, _presentationContexts));
        }
        #endregion
    }

    /// <summary>
    /// MyVerificationScp overrides the VerificationSCP's CEchoRq method, which is called anytime a C-ECHO request DIMSE message is received.
    /// </summary>
    class MyVerificationScp : Dicom.Verification.VerificationSCP
    {
        public MyVerificationScp(AssociationAcceptor acceptor, IList<AllowedPresentationContext> allowedPresentationContexts)
            : base(acceptor, allowedPresentationContexts, null)
        {
        }

        public override CEchoResponse CEchoRq(CEchoRequest request)
        {
            CEchoResponse response = new CEchoResponse(request);

            Console.WriteLine("MyVerificationScp: cEcho request from {0} to port {1}",
                Acceptor.AssociationInfo.CallingTitle, Acceptor.AssociationInfo.CalledPresentationAddress);

            return response;
        }
    }
}