StreamLink.NET
Caplin.StreamLink.Subscription.Container Namespace
StreamLink.NETCaplin.StreamLink.Subscription.Container
Contains interfaces, classes, and enums related to the Container SubjectType. Defines the key interfaces concerning the subscription to a container and the elements within it (IContainerSubscription, IContainerSubscriptionListener, and IContainerElement), the interface that provides access to the parameters used to request containers (IContainerSubscriptionParameters), and the interface for handling container events (IContainerEvent).
Declaration Syntax
C#Visual BasicVisual C++
namespace Caplin.StreamLink.Subscription.Container
Namespace Caplin.StreamLink.Subscription.Container
namespace Caplin.StreamLink.Subscription.Container
Types
All TypesInterfaces
IconTypeDescription
IContainerElement
Represents an element in a container on the Liberator. When updates are received for an IContainerSubscription, one or more IContainerElements within the container will have been updated.

IContainerEvent

Provides information about a subscribed container and the latest changes to its structure.


IContainerSubscription

Represents a subscription to a container on the Liberator.


IContainerSubscriptionListener
The IContainerSubscriptionListener interface allows applications to receive events raised for a container subscription.

IContainerSubscriptionParameters
Provides access to the parameters used for a subscription to a container on the Liberator.

Remarks

Container subscriptions are created through the IStreamLinkProvider interface using one of the CreateContainerSubscription(IContainerSubscriptionListener, String) methods. In all cases an IContainerSubscriptionListener must be passed, along with the subject of the container being subscribed to.

CopyC#
using System;
using System.Collections.Generic;
using System.Text;
using Caplin.StreamLink;
using Caplin.StreamLink.Authentication;
using Caplin.StreamLink.Subscription.Container;
using Caplin.StreamLink.Subscription.Record;
using StreamLinkExamples.Record;

namespace StreamLinkExamples.Container
{
    public class CreateContainerSubscriptionBasic
    {
        /// <summary>
        /// Create a subscription to a container.
        /// </summary>
        public static void CreateContainerSubscriptionBasicExample()
        {
            StreamLink myStreamLink = new StreamLink();
            myStreamLink.CredentialsProvider = new PasswordCredentialsProvider("admin", "admin");

            IContainerSubscriptionListener subscriptionListener = new ExampleContainerSubscriptionListener();

            IContainerSubscription subscription =
                myStreamLink.StreamLinkProvider.CreateContainerSubscription(subscriptionListener,
                                                                         "/DEMO/CONTAINER/DCONT");

            subscription.Subscribe();

            myStreamLink.StreamLinkProvider.Connect();
        }
    }
}

The object implementing IContainerSubscriptionListener will then be informed of all subscription status, error and container data events. (Also see ISubscriptionListener.)

CopyC#
using System;
using System.Collections.Generic;
using System.Text;
using Caplin.StreamLink.Subscription.Container;
using Caplin.StreamLink.Subscription;

namespace StreamLinkExamples.Container
{
    /// <summary>
    /// Basic example of an object implementing the IContainerSubscriptionListener
    /// interfance and querying the update objects for information.
    /// </summary>
    public class ExampleContainerSubscriptionListener: IContainerSubscriptionListener
    {
        #region IContainerSubscriptionListener Members

        /// <summary>
        /// Process the container change event.
        /// </summary>
        public void ContainerUpdated(ISubscription subscription, IContainerEvent ev)
        {
            // Process update
            string msg = "Received container structure change event for " +
                         ev.Subject + Environment.NewLine;

            msg += "Size:" + ev.Size + Environment.NewLine;
            msg += "Added constituents:" + Environment.NewLine;

            foreach (IContainerElement elem in ev.AddedElements)
            {
                msg += elem.Subject + " Type: " + elem.SubjectType +
                    Environment.NewLine;
            }
            msg += "Removed consitutents: " + Environment.NewLine;
            foreach (IContainerElement elem in ev.RemovedElements)
            {
                msg += elem.Subject + " Type: " + elem.SubjectType +
                    Environment.NewLine;
            }
            Console.WriteLine(msg);
        }

        #endregion

        #region ISubscriptionListener Members

        /// <summary>
        /// Subscription Ended Callback. For 'not found', 'read denied' etc.
        /// </summary>
        public void SubscriptionErrorReceived(ISubscription subscription,
                                              ISubscriptionErrorEvent ev)
        {
            Console.WriteLine("Subscription Status Update " + ev.Subject +
                               " Error: " + ev.Error.ToString());
        }

        /// <summary>
        /// Status Callback
        /// </summary>
        public void SubscriptionStatusUpdated(ISubscription subscription,
                                              ISubscriptionStatusEvent ev)
        {
            Console.WriteLine("Subscription Status Update " + ev.Subject +
                              " Status: " + ev.Status.ToString() +
                              " " + ev.Message);
        }

        #endregion
    }
}

When creating a container subscription you can supply parameters defining the elements within the container that the application wishes to receive updates for. Parameters are created through the relevant factory methods of the ParametersFactory interface available through the ParametersFactory property of IStreamLinkProvider. The factory method returns an IContainerSubscriptionParameters object, which is passed to one of the CreateContainerSubscription methods of IStreamLinkProvider.

CopyC#
using System;
using System.Collections.Generic;
using System.Text;
using Caplin.StreamLink;
using Caplin.StreamLink.Authentication;
using Caplin.StreamLink.Subscription.Container;
using Caplin.StreamLink.Subscription.Record;
using StreamLinkExamples.Record;

namespace StreamLinkExamples.Container
{
    public class CreateContainerSubscriptionWithStartIndexAndCount
    {
        /// <summary>
        /// Create a subscription to a container, passing in container subscription parameters
        /// object which defines we are subscribing to the first 10 elements within the container
        /// </summary>
        public static void CreateContainerSubscriptionWithStartIndexAndCountExample()
        {
            StreamLink myStreamLink = new StreamLink();
            myStreamLink.CredentialsProvider = new PasswordCredentialsProvider("admin", "admin");

            IContainerSubscriptionListener subscriptionListener = new ExampleContainerSubscriptionListener();

            // Subscribe from the 1st element within the container.
            int containerStartIndex = 0;

            // Subscribe to 10 elements in the container.
            int containerElementCount = 10;

            IContainerSubscriptionParameters parameters =
                myStreamLink.StreamLinkProvider.ParametersFactory.CreateContainerSubscriptionParameters(
                    containerStartIndex, containerElementCount);

            IContainerSubscription subscription =
                myStreamLink.StreamLinkProvider.CreateContainerSubscription(subscriptionListener,
                                                                         "/DEMO/CONTAINER/DCONT",
                                                                         parameters);

            subscription.Subscribe();

            myStreamLink.StreamLinkProvider.Connect();
        }
    }
}

The elements within a container may be of various SubjectTypes (Record, News, Page, and so on). To receive updates for the elements the application is interested in, set a listener on the subscription. In the following example the IRecordSubscriptionListener will be informed of all events on container elements that are records. For more information see IRecordSubscriptionListener. The example also sets an IContainerSubscriptionListener that is informed of all events relating to the container itself.

CopyC#
using System;
using System.Collections.Generic;
using System.Text;
using Caplin.StreamLink;
using Caplin.StreamLink.Authentication;
using Caplin.StreamLink.Subscription.Container;
using Caplin.StreamLink.Subscription.Record;
using StreamLinkExamples.Record;

namespace StreamLinkExamples.Container
{
    public class CreateContainerSubscriptionWithRecordSubscriptionListener
    {
        /// <summary>
        /// Create a subscription to a container and set a IRecordSubscriptionListener that
        /// will be informed of all Record container element updates.
        /// </summary>
        public static void CreateContainerSubscriptionWithRecordSubscriptionListenerExample()
        {
            StreamLink myStreamLink = new StreamLink();
            myStreamLink.CredentialsProvider = new PasswordCredentialsProvider("admin", "admin");

            IContainerSubscriptionListener subscriptionListener = new ExampleContainerSubscriptionListener();
            IRecordSubscriptionListener recordSubscriptionListener = new ExampleRecordSubscriptionListener();

            IContainerSubscription subscription =
                myStreamLink.StreamLinkProvider.CreateContainerSubscription(subscriptionListener,
                                                                         "/DEMO/CONTAINER/DCONT");

            // Set the record subscription listener prior to subscribing to ensure
            // that all updates are received.
            subscription.RecordSubscriptionListener = recordSubscriptionListener;

            subscription.Subscribe();

            myStreamLink.StreamLinkProvider.Connect();
        }
    }
}

You can also set parameters for the elements in the container. The following example illustrates how this is done for the record elements in a container.

A CreateRecordSubscriptionParameters() method of the ParametersFactory is called, specifying a filter ("Bid>10"). The IRecordSubscriptionParameters returned by the ParametersFactory is then passed to a CreateContainerSubscriptionParameters() method of the factory to get an IContainerSubscriptionParameters. When the container is subscribed to using this IContainerSubscriptionParameters, the record filter will apply to all records in the container, so the Liberator will only supply updates where the Bid field is greater than 10.

CopyC#
using System;
using System.Collections.Generic;
using System.Text;
using Caplin.StreamLink;
using Caplin.StreamLink.Authentication;
using Caplin.StreamLink.Subscription.Container;
using Caplin.StreamLink.Subscription.Record;
using StreamLinkExamples.Record;

namespace StreamLinkExamples.Container
{
    public class CreateContainerSubscriptionWithRecordSubscriptionParameters
    {
        /// <summary>
        /// Create a subscription to a container, passing in container subscription parameters
        /// object which includes a IRecordSubscriptionParameters which filters all record updates
        /// within the container.
        /// </summary>
        public static void CreateContainerSubscriptionWithRecordSubscriptionParametersExample()
        {
            StreamLink myStreamLink = new StreamLink();
            myStreamLink.CredentialsProvider = new PasswordCredentialsProvider("admin", "admin");

            IContainerSubscriptionListener subscriptionListener = new ExampleContainerSubscriptionListener();
            IRecordSubscriptionListener recordSubscriptionListener = new ExampleRecordSubscriptionListener();

            // Filter any container element records by Bid>10
            IRecordSubscriptionParameters recordSubscriptionParameters =
                myStreamLink.StreamLinkProvider.ParametersFactory.CreateRecordSubscriptionParameters("Bid>10");

            // Create container parameters passing record parameters for the record filter
            IContainerSubscriptionParameters parameters =
                myStreamLink.StreamLinkProvider.ParametersFactory.CreateContainerSubscriptionParameters(
                    recordSubscriptionParameters);

            IContainerSubscription subscription =
                myStreamLink.StreamLinkProvider.CreateContainerSubscription(subscriptionListener,
                                                                         "/DEMO/CONTAINER/DCONT",
                                                                         parameters);

            // Set the record subscription listener prior to subscribing to ensure
            // that all filtered updates are received.
            subscription.RecordSubscriptionListener = recordSubscriptionListener;

            subscription.Subscribe();

            myStreamLink.StreamLinkProvider.Connect();
        }
    }
}