Ejemplo n.º 1
0
        /// <summary>
        ///     Limit the output of the query.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="esperQuery">The esper query.</param>
        /// <param name="whenExpression">the expression that returns true to trigger output</param>
        /// <returns>clause</returns>
        public static EsperQuery <T> OutputLimit <T>(
            this EsperQuery <T> esperQuery,
            Expression whenExpression)
        {
            var parentObjectModel = esperQuery.ObjectModel;
            var deriveObjectModel = parentObjectModel.ShallowCopy();

            deriveObjectModel.OutputLimitClause = OutputLimitClause.Create(whenExpression);
            return(new EsperQuery <T>(esperQuery.ServiceProvider, deriveObjectModel));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Groups the results of the expression.
        /// </summary>
        /// <typeparam name="TSource">The type of the source.</typeparam>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <param name="esperQuery">The esper query.</param>
        /// <param name="keySelectionExpression">The key selection expression.</param>
        /// <returns></returns>
        public static EsperQuery <TSource> GroupBy <TSource, TKey>(
            this EsperQuery <TSource> esperQuery,
            Expression <Func <TSource, TKey> > keySelectionExpression)
        {
            var parentObjectModel = esperQuery.ObjectModel;
            var deriveObjectModel = parentObjectModel.ShallowCopy();

            // Adapt or set the where clause according to the expression contents
            using (ScopedInstance <EPStatementObjectModel> .Set(deriveObjectModel)) {
                var sodaExpression = LinqToSoda.LinqToSodaExpression(keySelectionExpression);
                deriveObjectModel.GroupByClause = GroupByClause.Create(sodaExpression);
                return(new EsperQuery <TSource>(esperQuery.ServiceProvider, deriveObjectModel));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Adds the property.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="esperQuery">The esper query.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="expression">The expression.</param>
        /// <returns></returns>
        public static EsperQuery <T> AddProperty <T>(
            this EsperQuery <T> esperQuery,
            string propertyName,
            Expression <Func <object> > expression)
        {
            var parentObjectModel = esperQuery.ObjectModel;
            var deriveObjectModel = parentObjectModel.ShallowCopy();

            using (ScopedInstance <EPStatementObjectModel> .Set(deriveObjectModel)) {
                deriveObjectModel.SelectClause.Add(
                    LinqToSoda.LinqToSodaExpression(expression),
                    propertyName);
                return(new EsperQuery <T>(esperQuery.ServiceProvider, deriveObjectModel));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Selects the specified "item" from the esper query.
        /// </summary>
        /// <typeparam name="T1">The type of the 1.</typeparam>
        /// <typeparam name="T2">The type of the 2.</typeparam>
        /// <param name="esperQuery">The esper query.</param>
        /// <param name="expression">The expression.</param>
        /// <returns></returns>
        public static DisposableObservableCollection <T2> Select <T1, T2>(
            this EsperQuery <T1> esperQuery,
            Expression <Func <T1, T2> > expression)
        {
            var transform = expression.Compile();

            esperQuery.Compile();
            if (typeof(T1) == typeof(T2))
            {
                return(esperQuery.Statement.AsObservableCollection <T2>(true));
            }

            return(new CascadeObservableCollection <T1, T2>(
                       esperQuery.Statement.AsObservableCollection <T1>(true),
                       transform,
                       true));
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Constrains the specified esper query.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="esperQuery">The esper query.</param>
        /// <param name="expression">The expression.</param>
        /// <returns></returns>
        public static EsperQuery <T> Where <T>(
            this EsperQuery <T> esperQuery,
            Expression <Func <T, bool> > expression)
        {
            var parentObjectModel = esperQuery.ObjectModel;
            var deriveObjectModel = parentObjectModel.ShallowCopy();

            // Adapt or set the where clause according to the expression contents
            using (ScopedInstance <EPStatementObjectModel> .Set(deriveObjectModel)) {
                var sodaExpression = LinqToSoda.LinqToSodaExpression(expression);
                deriveObjectModel.WhereClause = deriveObjectModel.WhereClause == null
                    ? sodaExpression
                    : Expressions.And(deriveObjectModel.WhereClause, sodaExpression);
                deriveObjectModel.FromClause.Streams[0].StreamName =
                    expression.Parameters[0].Name;

                return(new EsperQuery <T>(esperQuery.ServiceProvider, deriveObjectModel));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Joins the specified outer.
        /// </summary>
        /// <typeparam name="TOuter">The type of the outer.</typeparam>
        /// <typeparam name="TInner">The type of the inner.</typeparam>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <param name="outer">The outer.</param>
        /// <param name="inner">The inner.</param>
        /// <param name="outerKeySelector">The outer key selector.</param>
        /// <param name="innerKeySelector">The inner key selector.</param>
        /// <param name="resultSelector">The result selector.</param>
        /// <returns></returns>
        public static EsperQuery <TResult> Join <TOuter, TInner, TKey, TResult>(
            this EsperQuery <TOuter> outer,
            EsperQuery <TInner> inner,
            Expression <Func <TOuter, TKey> > outerKeySelector,
            Expression <Func <TInner, TKey> > innerKeySelector,
            Expression <Func <TOuter, TInner, TResult> > resultSelector)
        {
            var parentObjectModel = outer.ObjectModel;
            var deriveObjectModel = new EPStatementObjectModel();

            using (ScopedInstance <EPStatementObjectModel> .Set(deriveObjectModel)) {
                deriveObjectModel.Annotations = parentObjectModel.Annotations;

                var innerKey = LinqToSoda.LinqToSodaExpression(innerKeySelector);
                var outerKey = LinqToSoda.LinqToSodaExpression(outerKeySelector);

                deriveObjectModel.FromClause = new FromClause(
                    outer.ObjectModel.FromClause.Streams.Concat(
                        inner.ObjectModel.FromClause.Streams)
                    .ToArray());

                var parametersArray = resultSelector.Parameters.ToArray();
                for (var ii = 0; ii < parametersArray.Length; ii++)
                {
                    deriveObjectModel.FromClause.Streams[ii].StreamName =
                        parametersArray[ii].Name;
                }

                deriveObjectModel.FromClause.OuterJoinQualifiers = new List <OuterJoinQualifier>();
                deriveObjectModel.FromClause.OuterJoinQualifiers.Add(
                    new OuterJoinQualifier(
                        OuterJoinType.LEFT,
                        outerKey,
                        innerKey,
                        new PropertyValueExpressionPair[0]));

                deriveObjectModel.SelectClause = LinqToSoda.LinqToSelectClause(resultSelector);

                var toEPL = deriveObjectModel.ToEPL();

                return(new EsperQuery <TResult>(outer.ServiceProvider, deriveObjectModel));
            }
        }