Пример #1
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);
        }
Пример #2
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);
        }