/// <summary>
        /// Removes items from a subscription.
        /// </summary>
        public virtual OpcItemResult[] RemoveItems(OpcItem[] 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 OpcItemResult[0]);
            }

            // remove items from server.
            OpcItemResult[] results = Subscription.RemoveItems(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");
            }

            // remove items from local list if successful.
            ArrayList itemList = new ArrayList();

            foreach (TsCDaItem item in daItems_)
            {
                bool removed = false;

                for (int ii = 0; ii < results.Length; ii++)
                {
                    if (item.ServerHandle.Equals(items[ii].ServerHandle))
                    {
                        removed = results[ii].Result.Succeeded();
                        break;
                    }
                }

                if (!removed)
                {
                    itemList.Add(item);
                }
            }

            // update local list.
            daItems_ = (TsCDaItem[])itemList.ToArray(typeof(TsCDaItem));

            // update the local state.
            GetState();

            // return results.
            return(results);
        }
Exemple #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);
            }
        }