StreamLink.NET
Caplin.StreamLink.Subscription.Container Namespace
StreamLink.NETCaplin.StreamLink.Subscription.Container
Contains interfaces, classes and enums related to containers. Defines the key interfaces IContainerSubscription and IContainerSubscriptionListener in addition to the IContainerEvent, IContainerElement, IContainerSubscriptionParameters interfaces.
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 found within a container on the Liberator. A number of IContainerElement will be part of updates related to IContainerSubscription

IContainerEvent

The interface implemented by an event object relating to a container within the Liberator.

The interface provides access to information about the container such as the container Size in addition to information about the containers initial structure and subsequent structure changes via the AddedElements and RemovedElements properties.


IContainerSubscription

Represents a subscription to a container on the Liberator.


IContainerSubscriptionListener
Interface to be implemented by any object wishing to subscribe for container events.

IContainerSubscriptionParameters
Subscription parameters for Containers

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
    }
}

It is also possible to create a container subscription and pass in parameters. Parameters can be used to define the elements within the container that the user wishes to receive updates for.

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 varying types (Record, News, Page etc.). To receive updates for the elements the user is interested in a listener must be set on the subscription. In the following example the set IRecordSubscriptionListener will be informed of all events on container elements that are records. For more information see IRecordSubscriptionListener.

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();
        }
    }
}

In addition to setting listeners for different subject types it is also possible to set parameters for each type. This is done when creating the IContainerSubscriptionParameters.

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();
        }
    }
}