Event and State Viewer

This sample demonstrates how to subscribe to events and state, how to monitor the connection state, how to track and display the current state, and how to display events.

The application consists of three tabs:

Event and State Viewer

The sample demonstrates

Simplified example

async Task SampleAsync()
{
    // TODO: Initialize SDK environment and login

    var loginSettings = LoginSettingsCache.GetLoginSettings(EnvironmentManager.Instance.MasterSite);

    // Create event receiver and session
    var eventReveiver = new EventReceiver();
    var session = EventsAndStateSession.Create(loginSettings, eventReveiver);

    // Add subscription
    var subscription = new[]
        {
            new SubscriptionRule(
                Modifier.Include,
                new ResourceTypes(new[]{ "cameras" }),
                SourceIds.Any,
                new EventTypes(new[]{ KnownStatusEvents.CommunicationStarted, KnownStatusEvents.CommunicationStopped }))
        };
    await session.AddSubscriptionAsync(subscription, default);

    // Send initial state as events, if needed
    await _session.SendAllStatefulEventsAsync(default);

    // TODO: Run application

    // Dispose session to close the connection
    session.Dispose();
}

class EventReceiver : IEventReceiver
{
    public async Task OnConnectionStateChangedAsync(ConnectionState newState)
    {
        // TODO: Handle connection state change
    }

    public async Task OnEventsReceivedAsync(IEnumerable<Event> events)
    {
        // TODO: Handle events
    }
}

Using

Environment

Visual Studio C# project