Esempio n. 1
0
        public static IObservable <SymbolNotification> WhenNotification(this IAdsConnection client, ISymbolCollection symbols, NotificationSettings settings)
        {
            if (symbols == null)
            {
                throw new ArgumentNullException("symbols");
            }
            ISymbol local1 = Enumerable.FirstOrDefault <ISymbol>(symbols);

            if (local1 == null)
            {
                throw new ArgumentOutOfRangeException("Symbols list is empty!", "symbols");
            }
            IValueSymbol symbol = local1 as IValueSymbol;

            if (symbol == null)
            {
                throw new ArgumentOutOfRangeException("Symbols in list are not IValueSymbol", "symbols");
            }
            IAccessorValueFactory      valueFactory = symbol.ValueAccessor.ValueFactory;
            IDisposableSymbolHandleBag bag          = null;
            object userData = new object();

            return(Observable.Where <SymbolNotification>(Observable.Select <EventPattern <AdsNotificationEventArgs>, SymbolNotification>(Observable.Where <EventPattern <AdsNotificationEventArgs> >(Observable.FromEventPattern <AdsNotificationEventHandler, AdsNotificationEventArgs>(delegate(AdsNotificationEventHandler h) {
                client.AdsNotification += h;
                bag = new DisposableNotificationHandleBag(client, symbols, settings, userData);
            }, delegate(AdsNotificationEventHandler h) {
                bag.Dispose();
                bag = null;
                client.AdsNotification -= h;
            }), ev => bag.Contains((uint)ev.get_EventArgs().NotificationHandle)), ev => new SymbolNotification(ev.get_EventArgs(), bag.GetSymbol((uint)ev.get_EventArgs().NotificationHandle), valueFactory)), s => symbols.Contains(s.Symbol)));
        }
Esempio n. 2
0
        public static IObservable <SymbolNotification> WhenNotification(this IAdsConnection client, ISymbol symbol, NotificationSettings settings)
        {
            if (symbol == null)
            {
                throw new ArgumentNullException("symbol");
            }
            if (symbol == null)
            {
                throw new ArgumentOutOfRangeException("Symbol is not an IValueSymbol", "symbol");
            }
            List <ISymbol> symbols = new List <ISymbol> {
                symbol
            };
            IDisposableSymbolHandleBag bag = null;
            IAccessorValueFactory      fac = ((IAccessorValue)(symbol as IValueSymbol).ValueAccessor).ValueFactory;
            object userData = new object();

            return(Observable.Select <EventPattern <AdsNotificationEventArgs>, SymbolNotification>(Observable.Where <EventPattern <AdsNotificationEventArgs> >(Observable.FromEventPattern <AdsNotificationEventHandler, AdsNotificationEventArgs>(delegate(AdsNotificationEventHandler h) {
                client.AdsNotification += h;
                bag = new DisposableNotificationHandleBag(client, symbols, settings, userData);
            }, delegate(AdsNotificationEventHandler h) {
                bag.Dispose();
                bag = null;
                client.AdsNotification -= h;
            }), ev => bag.Contains((uint)ev.get_EventArgs().NotificationHandle)), ev => new SymbolNotification(ev.get_EventArgs(), bag.GetSymbol((uint)ev.get_EventArgs().NotificationHandle), fac)));
        }