Simple StreamInsight Application

This shows a simple StreamInsight application that can leverage the different hosting models and features for StreamInsight. It is built using input and output adapters from the StreamInsight Samples and a custom host application.

C# (113.5 KB)
 
 
 
 
 
4 Star
(1)
1,490 times
Add to favorites
3/9/2012
E-mail Twitter del.icio.us Digg Facebook
//*********************************************************
//
//  Copyright (c) J Sawyer. All rights reserved.
//  This code is licensed under the Apache 2.0 License.
//  THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OR
//  CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,
//  INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES
//  OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
//  PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.ComplexEventProcessing;

namespace DevBiker.SimpleSIApp
{
    /// <summary>
    /// Enum for the query's current state.
    /// </summary>
    public enum QueryState
    {
        /// <summary>
        /// The query has been suspended
        /// </summary>
        Suspended,
        /// <summary>
        /// The query is in the process of stopping
        /// </summary>
        Stopping,
        /// <summary>
        /// The query is running and processing events
        /// </summary>
        Running,
        /// <summary>
        /// The query has been aborted due to an error
        /// </summary>
        Aborted,
        /// <summary>
        /// The state cannot be determined or the query has been deleted
        /// </summary>
        Unknown
    }

    /// <summary>
    /// Class with extension methods for Queries.
    /// </summary>
    public static class QueryExtensionMethods
    {
        /// <summary>
        /// Returns the diagnostic view for the query.
        /// </summary>
        /// <param name="query">Query object </param>
        /// <returns>The Diagnostic view for the query.</returns>
        public static DiagnosticView GetDiagnosticView(this Query query)
        {
            DiagnosticView diagnosticView =
                query.Application.Server.GetDiagnosticView(query.Name);
            return diagnosticView;
        }

        /// <summary>
        /// Returns the current state of the query
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public static QueryState GetQueryState(this Query query)
        {
            QueryState queryState = QueryState.Unknown;
            try
            {
                DiagnosticView diagnosticView = query.GetDiagnosticView();
                if (!Enum.TryParse<QueryState>(
                    diagnosticView[DiagnosticViewProperty.QueryState].ToString(), true, out queryState))
                {
                    queryState = QueryState.Unknown;
                }
            }
            catch (ManagementException)
            { }
            return queryState;
        }
    }

}