示例#1
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 ISubscription CreateSubscription(Opc.Da.SubscriptionState state)
        {
            if (state == null)
            {
                throw new ArgumentNullException("state");
            }

            lock (this)
            {
                Opc.Da.SubscriptionState copy = (Opc.Da.SubscriptionState)state.Clone();

                // assign unique handle.
                copy.ServerHandle = m_nextHandle++;

                // assign name.
                if (copy.Name == null || copy.Name.Length == 0)
                {
                    copy.Name = String.Format("Subscription{0,2:00}", copy.ServerHandle);
                }

                // create subscription.
                Subscription subscription = new Subscription(m_cache, this, copy);

                // save reference.
                m_subscriptions[copy.ServerHandle] = subscription;

                // return new subscription.
                return(subscription);
            }
        }