Example #1
0
        internal static IAccessorValue createValueAccessor(IAdsConnection connection, SymbolLoaderSettings settings)
        {
            IAccessorValue        value2       = null;
            AdsValueAccessor      inner        = null;
            IAccessorValueFactory valueFactory = null;

            if (settings.SymbolsLoadMode == SymbolsLoadMode.DynamicTree)
            {
                valueFactory = new DynamicValueFactory(settings.ValueCreation);
                inner        = new AdsValueAccessor(connection, settings.ValueAccessMode, valueFactory, NotificationSettings.Default);
                value2       = new DynamicValueAccessor(inner, valueFactory, settings.ValueCreation);
            }
            else
            {
                valueFactory = new ValueFactory(settings.ValueCreation);
                inner        = new AdsValueAccessor(connection, settings.ValueAccessMode, valueFactory, NotificationSettings.Default);
                value2       = inner;
            }
            IAccessorValueFactory2 factory2 = valueFactory as IAccessorValueFactory2;

            if (valueFactory != null)
            {
                factory2.SetValueAccessor(value2);
            }
            inner.AutomaticReconnection = settings.AutomaticReconnection;
            return(value2);
        }
Example #2
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)));
        }
Example #3
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)));
        }
Example #4
0
 protected ValueAccessor(IAccessorValueFactory factory, ISession session)
 {
     if (factory == null)
     {
         throw new ArgumentNullException("factory");
     }
     this.session      = session;
     this.connection   = null;
     this.valueFactory = factory;
 }
        public DynamicValueAccessor(IAccessorValue inner, IAccessorValueFactory factory, ValueCreationMode mode) : base(factory, ((ValueAccessor)inner).Connection)
        {
            this._mode  = ValueCreationMode.Default;
            this._mode  = mode;
            this._inner = inner;
            IAccessorNotification notification = inner as IAccessorNotification;

            if (notification != null)
            {
                base._notificationSettings = notification.DefaultNotificationSettings;
            }
        }
Example #6
0
 protected ValueAccessor(IAccessorValueFactory factory, IConnection connection)
 {
     if (factory == null)
     {
         throw new ArgumentNullException("factory");
     }
     if (connection == null)
     {
         throw new ArgumentNullException("adsClient");
     }
     if (!connection.IsConnected)
     {
         throw new ClientNotConnectedException();
     }
     if (connection.Session != null)
     {
         this.session = connection.Session;
     }
     else
     {
         this.connection = connection;
     }
     this.valueFactory = factory;
 }
Example #7
0
 internal DynamicReferenceValue(IDynamicSymbol symbol, byte[] data, int offset, DateTime timeStamp, IAccessorValueFactory factory) : base(symbol, data, offset, timeStamp, factory)
 {
 }
 protected RpcNotificationAccessorBase(IAccessorValueFactory valueFactory, ISession session, INotificationSettings defaultSettings) : base(valueFactory, session)
 {
     this._notificationSettings = defaultSettings;
 }
 protected RpcNotificationAccessorBase(IAccessorValueFactory valueFactory, ISession session) : base(valueFactory, session)
 {
 }
 protected RpcNotificationAccessorBase(IAccessorValueFactory valueFactory, IConnection connection) : base(valueFactory, connection)
 {
 }
Example #11
0
 internal SymbolNotification(AdsNotificationEventArgs args, ISymbol symbol, IAccessorValueFactory valueFactory) : base(args)
 {
     this._valueFactory = valueFactory;
     this._symbol       = symbol;
 }
Example #12
0
 internal AdsValueAccessor(IAdsConnection connection, ValueAccessMode accessMethod, IAccessorValueFactory valueFactory, NotificationSettings defaultSettings) : base(valueFactory, connection, defaultSettings)
 {
     this._converter                  = new DynamicValueConverter();
     this._syncNotification           = new object();
     this._accessMethod               = ValueAccessMode.IndexGroupOffsetPreferred;
     this._notificationTable          = new AdsNotificationCache();
     this._notificationStream         = new AdsStream();
     this._address                    = connection.Address;
     this._accessMethod               = accessMethod;
     base._notificationSettings       = defaultSettings;
     connection.AdsNotification      += new AdsNotificationEventHandler(this.adsClient_AdsNotification);
     connection.AdsNotificationError += new AdsNotificationErrorEventHandler(this.adsClient_AdsNotificationError);
 }
Example #13
0
 protected AdsValueAccessorBase(IAccessorValueFactory valueFactory, ISession session, NotificationSettings settings) : base(valueFactory, session, settings)
 {
 }
Example #14
0
 protected AdsValueAccessorBase(IAccessorValueFactory valueFactory, IConnection connection, NotificationSettings settings) : base(valueFactory, connection, settings)
 {
 }