/// <summary>
 ///     Determines if an item is valid (could it be added without error). Also returns information about the item such as
 ///     canonical datatype. Does not affect the group in any way.
 /// </summary>
 /// <param name="itemDefinitions">The list of item definitions.</param>
 /// <param name="blobUpdate">
 ///     If set to <c>true</c> (and the server supports Blobs) the server should return updated Blobs
 ///     in results, otherwise the server will not return Blobs.
 /// </param>
 /// <returns>
 ///     Array of item results.
 /// </returns>
 public OpcDaItemResult[] ValidateItems(IList <OpcDaItemDefinition> itemDefinitions, bool blobUpdate = false)
 {
     OPCITEMDEF[]      pItemArray = ArrayHelpers.CreateOPITEMDEFs(itemDefinitions);
     HRESULT[]         ppErrors;
     OPCITEMRESULT[]   opcDaItemResults = As <OpcItemMgt>().ValidateItems(pItemArray, blobUpdate, out ppErrors);
     OpcDaItemResult[] results          = CreateItemResults(itemDefinitions, pItemArray, opcDaItemResults, ppErrors, false);
     return(results);
 }
        /// <summary>
        ///     Add one or more items to the group.
        /// </summary>
        /// <param name="itemDefinitions">The list of item definitions.</param>
        /// <returns>
        ///     Array of item results.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">itemDefinitions</exception>
        public OpcDaItemResult[] AddItems(IList <OpcDaItemDefinition> itemDefinitions)
        {
            if (itemDefinitions == null)
            {
                throw new ArgumentNullException("itemDefinitions");
            }
            if (itemDefinitions.Count == 0)
            {
                return(new OpcDaItemResult[0]);
            }

            OPCITEMDEF[] pItemArray = ArrayHelpers.CreateOPITEMDEFs(itemDefinitions);

            HRESULT[]       ppErrors;
            OPCITEMRESULT[] opcDaItemResults = As <OpcItemMgt>().AddItems(pItemArray, out ppErrors);

            OpcDaItemResult[] results = CreateItemResults(itemDefinitions, pItemArray, opcDaItemResults, ppErrors, true);

            var addedItems = new List <OpcDaItem>(itemDefinitions.Count);

            foreach (OpcDaItemResult result in results)
            {
                OpcDaItem item = result.Item;
                if (result.Error.Succeeded && item != null)
                {
                    _items.Add(item);
                    addedItems.Add(item);
                }
            }

            // Set client handles to index of items
            UpdateClientHandles();

            OnItemsChanged(new OpcDaItemsChangedEventArgs(addedItems.ToArray(), null, null));
            return(results);
        }