/// <summary>
 /// Initializes object with default values.
 /// </summary>
 public TsCAeSubscription(TsCAeServer server, ITsCAeSubscription subscription, TsCAeSubscriptionState state)
 {
     server_       = server ?? throw new ArgumentNullException(nameof(server));
     subscription_ = subscription ?? throw new ArgumentNullException(nameof(subscription));
     state_        = (TsCAeSubscriptionState)state.Clone();
     name_         = state.Name;
 }
Example #2
0
        ///////////////////////////////////////////////////////////////////////
        #region Constructors, Destructor, Initialization

        /// <summary>
        /// Initializes object with default values.
        /// </summary>
        public TsCAeSubscription(TsCAeServer server, ITsCAeSubscription subscription, TsCAeSubscriptionState state)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }
            if (subscription == null)
            {
                throw new ArgumentNullException("subscription");
            }

            _server       = server;
            _subscription = subscription;
            _state        = (Ae.TsCAeSubscriptionState)state.Clone();
            _name         = state.Name;
        }
        /// <summary>
        /// Establishes a subscription based on the template provided.
        /// </summary>
        private TsCAeSubscription EstablishSubscription(TsCAeSubscription template)
        {
            ITsCAeSubscription remoteServer = null;

            try
            {
                // create remote object.
                remoteServer = ((ITsCAeServer)Server).CreateSubscription(template.State);

                if (remoteServer == null)
                {
                    return(null);
                }

                // create wrapper.
                TsCAeSubscription subscription = new TsCAeSubscription(this, remoteServer, template.State);

                // set filters.
                subscription.SetFilters(template.Filters);

                // set attributes.
                IDictionaryEnumerator enumerator = template.Attributes.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    if (enumerator.Key != null)
                    {
                        subscription.SelectReturnedAttributes(
                            (int)enumerator.Key,
                            ((TsCAeSubscription.AttributeCollection)enumerator.Value).ToArray());
                    }
                }

                // return new subscription
                return(subscription);
            }
            catch
            {
                if (remoteServer != null)
                {
                    remoteServer.Dispose();
                }
            }

            // return null.
            return(null);
        }
        /// <summary>
        /// Creates a new event subscription.
        /// </summary>
        /// <param name="state">The initial state for the subscription.</param>
        /// <returns>The new subscription object.</returns>
        public ITsCAeSubscription CreateSubscription(Ae.TsCAeSubscriptionState state)
        {
            if (_server == null)
            {
                throw new NotConnectedException();
            }

            // create remote object.
            ITsCAeSubscription subscription = ((ITsCAeServer)_server).CreateSubscription(state);

            if (subscription != null)
            {
                // create wrapper.
                Ae.TsCAeSubscription wrapper = new Ae.TsCAeSubscription(this, subscription, state);
                _subscriptions.Add(wrapper);
                return(wrapper);
            }

            // should never happen.
            return(null);
        }
        /// <summary>
        /// Creates a new event subscription.
        /// </summary>
        /// <param name="state">The initial state for the subscription.</param>
        /// <returns>The new subscription object.</returns>
        public ITsCAeSubscription CreateSubscription(TsCAeSubscriptionState state)
        {
            LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.AlarmsConditions);
            if (Server == null)
            {
                throw new NotConnectedException();
            }

            // create remote object.
            ITsCAeSubscription subscription = ((ITsCAeServer)Server).CreateSubscription(state);

            if (subscription != null)
            {
                // create wrapper.
                var wrapper = new TsCAeSubscription(this, subscription, state);
                subscriptions_.Add(wrapper);
                return(wrapper);
            }

            // should never happen.
            return(null);
        }