예제 #1
0
        // Token: 0x06000046 RID: 70 RVA: 0x000033F4 File Offset: 0x000023F4
        public virtual ISubscription CreateSubscription(SubscriptionState state)
        {
            if (state == null)
            {
                throw new ArgumentNullException("state");
            }
            if (this.m_server == null)
            {
                throw new NotConnectedException();
            }
            ISubscription subscription = ((IServer)this.m_server).CreateSubscription(state);

            subscription.SetResultFilters(this.m_filters);
            SubscriptionCollection subscriptionCollection = new SubscriptionCollection();

            if (this.m_subscriptions != null)
            {
                foreach (object obj in this.m_subscriptions)
                {
                    Subscription value = (Subscription)obj;
                    subscriptionCollection.Add(value);
                }
            }
            subscriptionCollection.Add(this.CreateSubscription(subscription));
            this.m_subscriptions = subscriptionCollection;
            return(this.m_subscriptions[this.m_subscriptions.Count - 1]);
        }
예제 #2
0
        // Token: 0x06000048 RID: 72 RVA: 0x000034D4 File Offset: 0x000024D4
        public virtual void CancelSubscription(ISubscription subscription)
        {
            if (subscription == null)
            {
                throw new ArgumentNullException("subscription");
            }
            if (this.m_server == null)
            {
                throw new NotConnectedException();
            }
            if (!typeof(Subscription).IsInstanceOfType(subscription))
            {
                throw new ArgumentException("Incorrect object type.", "subscription");
            }
            if (!this.Equals(((Subscription)subscription).Server))
            {
                throw new ArgumentException("Unknown subscription.", "subscription");
            }
            SubscriptionCollection subscriptionCollection = new SubscriptionCollection();

            foreach (object obj in this.m_subscriptions)
            {
                Subscription subscription2 = (Subscription)obj;
                if (!subscription.Equals(subscription2))
                {
                    subscriptionCollection.Add(subscription2);
                }
            }
            if (subscriptionCollection.Count == this.m_subscriptions.Count)
            {
                throw new ArgumentException("Subscription not found.", "subscription");
            }
            this.m_subscriptions = subscriptionCollection;
            ((IServer)this.m_server).CancelSubscription(((Subscription)subscription).m_subscription);
        }
예제 #3
0
        //======================================================================
        // CreateSubscription

        /// <summary>
        /// Creates a new subscription.
        /// </summary>
        /// <param name="state">The initial state of the subscription.</param>
        /// <returns>The new subscription object.</returns>
        public virtual ISubscription CreateSubscription(SubscriptionState state)
        {
            if (state == null)
            {
                throw new ArgumentNullException("state");
            }
            if (m_server == null)
            {
                throw new NotConnectedException();
            }

            // create subscription on server.
            ISubscription subscription = ((IServer)m_server).CreateSubscription(state);

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

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

            if (m_subscriptions != null)
            {
                foreach (Subscription value in m_subscriptions)
                {
                    subscriptions.Add(value);
                }
            }

            subscriptions.Add(CreateSubscription(subscription));

            // save new subscription list.
            m_subscriptions = subscriptions;

            // return new subscription.
            return(m_subscriptions[m_subscriptions.Count - 1]);
        }
예제 #4
0
        // Token: 0x0600003C RID: 60 RVA: 0x00003160 File Offset: 0x00002160
        public override object Clone()
        {
            Server server = (Server)base.Clone();

            if (server.m_subscriptions != null)
            {
                SubscriptionCollection subscriptionCollection = new SubscriptionCollection();
                foreach (object obj in server.m_subscriptions)
                {
                    Subscription subscription = (Subscription)obj;
                    subscriptionCollection.Add(subscription.Clone());
                }
                server.m_subscriptions = subscriptionCollection;
            }
            return(server);
        }
예제 #5
0
        //======================================================================
        // CancelSubscription

        /// <summary>
        /// Cancels a subscription and releases all resources allocated for it.
        /// </summary>
        /// <param name="subscription">The subscription to cancel.</param>
        public virtual void CancelSubscription(ISubscription subscription)
        {
            if (subscription == null)
            {
                throw new ArgumentNullException("subscription");
            }
            if (m_server == null)
            {
                throw new NotConnectedException();
            }

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

            if (!this.Equals(((Opc.Da.Subscription)subscription).Server))
            {
                throw new ArgumentException("Unknown subscription.", "subscription");
            }

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

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

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

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

            // cancel subscription on server.
            ((IServer)m_server).CancelSubscription(((Subscription)subscription).m_subscription);
        }
예제 #6
0
        //======================================================================
        // ICloneable

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

            // clone subscriptions.
            if (clone.m_subscriptions != null)
            {
                SubscriptionCollection subscriptions = new SubscriptionCollection();

                foreach (Subscription subscription in clone.m_subscriptions)
                {
                    subscriptions.Add(subscription.Clone());
                }

                clone.m_subscriptions = subscriptions;
            }

            // return clone.
            return(clone);
        }
예제 #7
0
        // Token: 0x0600003F RID: 63 RVA: 0x000031F4 File Offset: 0x000021F4
        public override void Connect(URL url, ConnectData connectData)
        {
            base.Connect(url, connectData);
            if (this.m_subscriptions == null)
            {
                return;
            }
            SubscriptionCollection subscriptionCollection = new SubscriptionCollection();

            foreach (object obj in this.m_subscriptions)
            {
                Subscription template = (Subscription)obj;
                try
                {
                    subscriptionCollection.Add(this.EstablishSubscription(template));
                }
                catch
                {
                }
            }
            this.m_subscriptions = subscriptionCollection;
        }
예제 #8
0
        //======================================================================
        // Connection Management

        /// <summary>
        /// Connects to the server with the specified URL and credentials.
        /// </summary>
        public override void Connect(URL url, ConnectData connectData)
        {
            // connect to server.
            base.Connect(url, connectData);

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

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

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

            // save new set of subscriptions.
            m_subscriptions = subscriptions;
        }