Example #1
0
        /// <summary>Connects to the server with the specified OpcUrl and credentials.</summary>
        /// <exception caption="OpcResultException Class" cref="OpcResultException">If an OPC specific error occur this exception is raised. The Result field includes then the OPC specific code.</exception>
        /// <param name="url">The network address of the remote server.</param>
        /// <param name="connectData">Any protocol configuration or user authenication information.</param>
        public override void Connect(OpcUrl url, OpcConnectData connectData)
        {
            if (_factory == null)
            {
                if (_factory == null)
                {
                    _factory = new Com.Factory();
                }
            }
            // connect to server.
            base.Connect(url, connectData);

            // all done if no subscriptions.
            if (_subscriptions == null)
            {
                return;
            }

            // create subscriptions (should only happen if server has been deserialized).
            TsCDaSubscriptionCollection subscriptions = new TsCDaSubscriptionCollection();

            foreach (TsCDaSubscription template in _subscriptions)
            {
                // create subscription for template.
                try { subscriptions.Add(EstablishSubscription(template)); }
                catch { }
            }

            // save new set of subscriptions.
            _subscriptions = subscriptions;
        }
 /// <summary>
 /// Initializes object with the specified SubscriptionCollection object.
 /// </summary>
 public TsCDaSubscriptionCollection(TsCDaSubscriptionCollection subscriptions)
 {
     if (subscriptions != null)
     {
         foreach (TsCDaSubscription subscription in subscriptions)
         {
             Add(subscription);
         }
     }
 }
Example #3
0
        ///////////////////////////////////////////////////////////////////////
        #region ICloneable Members

        /// <summary>
        /// Creates a deep copy of the object.
        /// </summary>
        public virtual object Clone()
        {
            TsCDaSubscriptionCollection clone = (TsCDaSubscriptionCollection)MemberwiseClone();

            clone._subscriptions = new ArrayList();

            foreach (TsCDaSubscription subscription in _subscriptions)
            {
                clone._subscriptions.Add(subscription.Clone());
            }

            return(clone);
        }
Example #4
0
        /// <summary>Cancels a subscription and releases all resources allocated for it.</summary>
        /// <requirements>OPC XML-DA Server or OPC Data Access Server V2.x / V3.x</requirements>
        /// <param name="subscription">The subscription to cancel.</param>
        public virtual void CancelSubscription(ITsCDaSubscription subscription)
        {
            if (subscription == null)
            {
                throw new ArgumentNullException("subscription");
            }
            if (_server == null)
            {
                throw new NotConnectedException();
            }

            // validate argument.
            if (!typeof(TsCDaSubscription).IsInstanceOfType(subscription))
            {
                throw new ArgumentException("Incorrect object type.", "subscription");
            }

            if (!Equals(((TsCDaSubscription)subscription).Server))
            {
                throw new ArgumentException("Server subscription.", "subscription");
            }

            // search for subscription in list of subscriptions.
            TsCDaSubscriptionCollection subscriptions = new TsCDaSubscriptionCollection();

            foreach (TsCDaSubscription current in _subscriptions)
            {
                if (!subscription.Equals(current))
                {
                    subscriptions.Add(current);
                    continue;
                }
            }

            // check if subscription was not found.
            if (subscriptions.Count == _subscriptions.Count)
            {
                throw new ArgumentException("Subscription not found.", "subscription");
            }

            // remove subscription from list of subscriptions.
            _subscriptions = subscriptions;

            // cancel subscription on server.
            ((ITsDaServer)_server).CancelSubscription(((TsCDaSubscription)subscription)._subscription);
        }
Example #5
0
        /// <summary>Cancels a subscription and releases all resources allocated for it.</summary>
        /// <requirements>OPC XML-DA Server or OPC Data Access Server V2.x / V3.x</requirements>
        /// <param name="subscription">The subscription to cancel.</param>
        public virtual void CancelSubscription(ITsCDaSubscription subscription)
        {
            LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.DataAccess);
            if (subscription == null)
            {
                throw new ArgumentNullException(nameof(subscription));
            }
            if (Server == null)
            {
                throw new NotConnectedException();
            }

            // validate argument.
            if (!typeof(TsCDaSubscription).IsInstanceOfType(subscription))
            {
                throw new ArgumentException(@"Incorrect object type.", nameof(subscription));
            }

            if (!Equals(((TsCDaSubscription)subscription).Server))
            {
                throw new ArgumentException(@"Server subscription.", nameof(subscription));
            }

            // search for subscription in list of subscriptions.
            TsCDaSubscriptionCollection subscriptions = new TsCDaSubscriptionCollection();

            foreach (TsCDaSubscription current in subscriptions_)
            {
                if (!subscription.Equals(current))
                {
                    subscriptions.Add(current);
                }
            }

            // check if subscription was not found.
            if (subscriptions.Count == subscriptions_.Count)
            {
                throw new ArgumentException(@"Subscription not found.", nameof(subscription));
            }

            // remove subscription from list of subscriptions.
            subscriptions_ = subscriptions;

            // cancel subscription on server.
            ((ITsDaServer)Server).CancelSubscription(((TsCDaSubscription)subscription).Subscription);
        }
Example #6
0
        /// <summary>Disconnects from the server and releases all network resources.</summary>
        public override void Disconnect()
        {
            if (_server == null)
            {
                throw new NotConnectedException();
            }

            // dispose of all subscriptions first.
            if (_subscriptions != null)
            {
                foreach (TsCDaSubscription subscription in _subscriptions)
                {
                    subscription.Dispose();
                }

                _subscriptions = null;
            }

            // disconnect from server.
            base.Disconnect();
        }
Example #7
0
        ///////////////////////////////////////////////////////////////////////
        #region Public Methods

        /// <summary>Returns an unconnected copy of the server with the same OpcUrl.</summary>
        public override object Clone()
        {
            // clone the base object.
            TsCDaServer clone = (TsCDaServer)base.Clone();

            // clone subscriptions.
            if (clone._subscriptions != null)
            {
                TsCDaSubscriptionCollection subscriptions = new TsCDaSubscriptionCollection();

                foreach (TsCDaSubscription subscription in clone._subscriptions)
                {
                    subscriptions.Add(subscription.Clone());
                }

                clone._subscriptions = subscriptions;
            }

            // return clone.
            return(clone);
        }
Example #8
0
        /// <summary>Connects to the server with the specified OpcUrl and credentials.</summary>
        /// <exception caption="OpcResultException Class" cref="OpcResultException">If an OPC specific error occur this exception is raised. The Result field includes then the OPC specific code.</exception>
        /// <param name="url">The network address of the remote server.</param>
        /// <param name="connectData">Any protocol configuration or user authentication information.</param>
        public override void Connect(OpcUrl url, OpcConnectData connectData)
        {
            LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.DataAccess);
            if (Factory == null)
            {
                if (Factory == null)
                {
                    Factory = new Com.Factory();
                }
            }
            // connect to server.
            base.Connect(url, connectData);

            // all done if no subscriptions.
            if (subscriptions_ == null)
            {
                return;
            }

            // create subscriptions (should only happen if server has been deserialized).
            TsCDaSubscriptionCollection subscriptions = new TsCDaSubscriptionCollection();

            foreach (TsCDaSubscription template in subscriptions_)
            {
                // create subscription for template.
                try
                {
                    subscriptions.Add(EstablishSubscription(template));
                }
                catch
                {
                    // Ignore exceptions here
                }
            }

            // save new set of subscriptions.
            subscriptions_ = subscriptions;
        }
Example #9
0
        /// <summary>
        /// Creates a new subscription.
        /// </summary>
        /// <returns>The new subscription object.</returns>
        /// <requirements>OPC XML-DA Server or OPC Data Access Server V2.x / V3.x</requirements>
        /// <param name="state">The initial state of the subscription.</param>
        public virtual ITsCDaSubscription CreateSubscription(TsCDaSubscriptionState state)
        {
            LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.DataAccess);
            if (state == null)
            {
                throw new ArgumentNullException(nameof(state));
            }
            if (Server == null)
            {
                throw new NotConnectedException();
            }

            // create subscription on server.
            ITsCDaSubscription subscription = ((ITsDaServer)Server).CreateSubscription(state);

            // set filters.
            subscription.SetResultFilters(filters_);

            // append new subscription to existing list.
            TsCDaSubscriptionCollection subscriptions = new TsCDaSubscriptionCollection();

            if (subscriptions_ != null)
            {
                foreach (TsCDaSubscription value in subscriptions_)
                {
                    subscriptions.Add(value);
                }
            }

            subscriptions.Add(CreateSubscription(subscription));

            // save new subscription list.
            subscriptions_ = subscriptions;

            // return new subscription.
            return(subscriptions_[subscriptions_.Count - 1]);
        }
Example #10
0
        /// <summary>
        /// Creates a new subscription.
        /// </summary>
        /// <returns>The new subscription object.</returns>
        /// <requirements>OPC XML-DA Server or OPC Data Access Server V2.x / V3.x</requirements>
        /// <param name="state">The initial state of the subscription.</param>
        public virtual ITsCDaSubscription CreateSubscription(TsCDaSubscriptionState state)
        {
            if (state == null)
            {
                throw new ArgumentNullException("state");
            }
            if (_server == null)
            {
                throw new NotConnectedException();
            }

            // create subscription on server.
            ITsCDaSubscription subscription = ((ITsDaServer)_server).CreateSubscription(state);

            // set filters.
            subscription.SetResultFilters(_filters);

            // append new subscription to existing list.
            TsCDaSubscriptionCollection subscriptions = new TsCDaSubscriptionCollection();

            if (_subscriptions != null)
            {
                foreach (TsCDaSubscription value in _subscriptions)
                {
                    subscriptions.Add(value);
                }
            }

            subscriptions.Add(CreateSubscription(subscription));

            // save new subscription list.
            _subscriptions = subscriptions;

            // return new subscription.
            return(_subscriptions[_subscriptions.Count - 1]);
        }