/// <summary>
        /// Adds items to the subscription.
        /// </summary>
        public virtual TsCDaItemResult[] AddItems(TsCDaItem[] items)
        {
            LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.DataAccess);
            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }

            // check if there is nothing to do.
            if (items.Length == 0)
            {
                return(new TsCDaItemResult[0]);
            }

            // add items.
            TsCDaItemResult[] results = Subscription.AddItems(items);

            if (results == null || results.Length == 0)
            {
                throw new OpcResultException(new OpcResult(OpcResult.E_FAIL.Code, OpcResult.FuncCallType.SysFuncCall, null), "The browse operation cannot continue");
            }

            // update locale item list.
            ArrayList itemList = new ArrayList();

            if (daItems_ != null)
            {
                itemList.AddRange(daItems_);
            }

            for (int ii = 0; ii < results.Length; ii++)
            {
                // check for failure.
                if (results[ii].Result.Failed())
                {
                    continue;
                }

                // create locale copy of the item.
                // item name, item path and client handle may not be returned by server.
                TsCDaItem item = new TsCDaItem(results[ii])
                {
                    ItemName = items[ii].ItemName, ItemPath = items[ii].ItemPath, ClientHandle = items[ii].ClientHandle
                };

                itemList.Add(item);
            }

            // save the new item list.
            daItems_ = (TsCDaItem[])itemList.ToArray(typeof(TsCDaItem));

            // update the local state.
            GetState();

            // return results.
            return(results);
        }
Exemplo n.º 2
0
        private void TestMI_Click(object sender, System.EventArgs e)
        {
            try
            {
                TsCDaServer server = (TsCDaServer)m_server;

                TsCDaItem[] items = new TsCDaItem[100];

                for (int ii = 0; ii < items.Length; ii++)
                {
                    items[ii] = new TsCDaItem();

                    items[ii].ItemName     = "Static/ArrayTypes/Object[]";
                    items[ii].ItemPath     = "DA30";
                    items[ii].ClientHandle = ii;
                }

                TsCDaSubscriptionState state = new TsCDaSubscriptionState();

                state.Active     = true;
                state.UpdateRate = 1000;

                ITsCDaSubscription subscription = server.CreateSubscription(state);
                Thread.Sleep(100);

                TsCDaItemResult[] results = subscription.AddItems(items);
                Thread.Sleep(100);

                subscription.RemoveItems(results);
                Thread.Sleep(100);

                server.CancelSubscription(subscription);
                Thread.Sleep(100);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }