コード例 #1
0
        static void Main(string[] args)
        {
            // create the data source
            // note: we cannot create more than one of these right now (limitation on the unmanaged side for simplicity)
            IObservable <NativeData> source = new NativeObservable();

            // create the stream processor
            var inputStream = source
                              .Select(e => StreamEvent.CreateStart(DateTime.Now.Ticks, e))
                              .ToStreamable(
                null,
                FlushPolicy.FlushOnPunctuation,
                PeriodicPunctuationPolicy.Time((ulong)TimeSpan.FromSeconds(1).Ticks));

            // The query
            long windowSize = TimeSpan.FromSeconds(2).Ticks;
            var  query      = inputStream
                              .AlterEventDuration(windowSize)
                              // we "filter" using our unmanaged matcher
                              .Where(e => NativeSubscription.MatchData(e.Data))
                              .Select(e => e.Data);

            // Egress results and write to console
            query.ToStreamEventObservable().ForEachAsync(e => WriteEvent(e)).Wait();
        }
コード例 #2
0
        /// <summary>
        /// Creates a native subscription
        /// </summary>
        /// <param name="observable"></param>
        /// <param name="observer"></param>
        public NativeSubscription(NativeObservable observable, IObserver <NativeData> observer)
        {
            this.observer = observer;

            lock (this.sync)
            {
                this.pinnedDelegate = new NativeMethods.NativeCallback(HandleNativeEvent);
                NativeMethods.RegisterNativeCallback(this.pinnedDelegate);
            }
        }