Continuous LINQ
by Kevin Hoffman 


Listing One: 

public static class ContinuousQueryExtension
{
        #region Where
        public static ContinuousCollection<T> Where<T>(
            this ContinuousCollection<T> source, Func<T, bool> filterFunc) where T: IEquatable<T>
        {
            Trace.WriteLine("Filtering Observable Collection.");
            ContinuousCollection<T> output = new ContinuousCollection<T>();
            FilteringViewAdapter<T> fva = 
              new FilteringViewAdapter<T>(source, output, filterFunc);

            return output;            
        }
        #endregion
        #region OrderBy
        public static ContinuousCollection<TSource> OrderBy<TSource, TKey>(
            this ContinuousCollection<TSource> source, Func<TSource, TKey> keySelector)
            where TSource : IEquatable<TSource>
            where TKey : IComparable
        {
            Trace.WriteLine("Ordering Observable Collection (Ascending).");
            ContinuousCollection<TSource> output = new ContinuousCollection<TSource>();
            SortingViewAdapter<TSource, TKey> sva = new SortingViewAdapter<TSource, TKey>(
                source, output,
                new FuncComparer<TSource, TKey>(keySelector, false));
            return output;                      
        }
        #endregion
        #region OrderByDescending
        public static ContinuousCollection<TSource> OrderByDescending<TSource, TKey>(
            this ContinuousCollection<TSource> source, Func<TSource, TKey> keySelector)
            where TSource : IEquatable<TSource>
            where TKey : IComparable
        {
            Trace.WriteLine("Ordering Observable Collection (Descending).");
            ContinuousCollection<TSource> output = new ContinuousCollection<TSource>();
            SortingViewAdapter<TSource, TKey> sva = new SortingViewAdapter<TSource, TKey>(
                source, output,
                new FuncComparer<TSource, TKey>(keySelector, true));
            return output;             
        }
        #endregion
}


Listing Two

public void SubscribeToSymbol(MarketSymbol symbol)
{
    if (!ModelRoot.Current.SubscribedSymbols.Contains(symbol))
    {
        ModelRoot.Current.SubscribedSymbols.Add(symbol);
        MarketDataBook newBook = new MarketDataBook(); // WPF Window
        newBook.Symbol = symbol;
        newBook.AskTicks =
            from tick in ModelRoot.Current.MarketData
            where tick.Side == TickSide.Ask &&
                  tick.Symbol == symbol
            orderby tick.Price descending
            select tick; // SELL
        newBook.BidTicks =
            from tick in ModelRoot.Current.MarketData
            where tick.Side == TickSide.Bid &&
                  tick.Symbol == symbol
            orderby tick.Price
            select tick; // BUY
        _monitorBooks.Add(symbol, newBook);
    }
}

2


