Example #1
0
        /// <summary>
        /// Continues a browse operation with previously specified search criteria.
        /// </summary>
        /// <param name="position">An object containing the browse operation state information.</param>
        /// <returns>The set of elements found.</returns>
        public virtual TsCDaBrowseElement[] BrowseNext(ref Technosoftware.DaAeHdaClient.Da.TsCDaBrowsePosition position)
        {
            lock (this)
            {
                if (m_server == null)
                {
                    throw new NotConnectedException();
                }
                string methodName = "IOPCBrowse.Browse";

                // check for valid position object.
                if (position == null || position.GetType() != typeof(Technosoftware.DaAeHdaClient.Com.Da.BrowsePosition))
                {
                    throw new BrowseCannotContinueException();
                }

                Technosoftware.DaAeHdaClient.Com.Da.BrowsePosition pos = (Technosoftware.DaAeHdaClient.Com.Da.BrowsePosition)position;

                // check for valid continuation point.
                if (pos == null || pos.ContinuationPoint == null || pos.ContinuationPoint == "")
                {
                    throw new BrowseCannotContinueException();
                }

                // initialize arguments.
                int count        = 0;
                int moreElements = 0;

                OpcItem            itemID  = ((BrowsePosition)position).ItemID;
                TsCDaBrowseFilters filters = ((BrowsePosition)position).Filters;

                IntPtr pContinuationPoint = Marshal.StringToCoTaskMemUni(pos.ContinuationPoint);
                IntPtr pElements          = IntPtr.Zero;

                // invoke COM method.
                try
                {
                    IOPCBrowse server = BeginComCall <IOPCBrowse>(methodName, true);
                    server.Browse(
                        (itemID != null && itemID.ItemName != null) ? itemID.ItemName : "",
                        ref pContinuationPoint,
                        filters.MaxElementsReturned,
                        Technosoftware.DaAeHdaClient.Com.Da.Interop.GetBrowseFilter(filters.BrowseFilter),
                        (filters.ElementNameFilter != null) ? filters.ElementNameFilter : "",
                        (filters.VendorFilter != null) ? filters.VendorFilter : "",
                        (filters.ReturnAllProperties) ? 1 : 0,
                        (filters.ReturnPropertyValues) ? 1 : 0,
                        (filters.PropertyIDs != null) ? filters.PropertyIDs.Length : 0,
                        Technosoftware.DaAeHdaClient.Com.Da.Interop.GetPropertyIDs(filters.PropertyIDs),
                        out moreElements,
                        out count,
                        out pElements);
                }
                catch (Exception e)
                {
                    ComCallError(methodName, e);
                    throw Technosoftware.DaAeHdaClient.Com.Interop.CreateException(methodName, e);
                }
                finally
                {
                    EndComCall(methodName);
                }

                // unmarshal results.
                TsCDaBrowseElement[] elements = Technosoftware.DaAeHdaClient.Com.Da.Interop.GetBrowseElements(ref pElements, count, true);

                pos.ContinuationPoint = Marshal.PtrToStringUni(pContinuationPoint);
                Marshal.FreeCoTaskMem(pContinuationPoint);

                // check if more no results exist.
                if (moreElements == 0 && (pos.ContinuationPoint == null || pos.ContinuationPoint == ""))
                {
                    position = null;
                }

                // process results.
                ProcessResults(elements, filters.PropertyIDs);

                return(elements);
            }
        }
Example #2
0
        /// <summary>
        /// Returns the item properties for a set of items.
        /// </summary>
        /// <param name="itemIds">A list of item identifiers.</param>
        /// <param name="propertyIDs">A list of properties to fetch for each item.</param>
        /// <param name="returnValues">Whether the property values should be returned with the properties.</param>
        /// <returns>A list of properties for each item.</returns>
        public virtual TsCDaItemPropertyCollection[] GetProperties(
            OpcItem[] itemIds,
            TsDaPropertyID[] propertyIDs,
            bool returnValues)
        {
            if (itemIds == null)
            {
                throw new ArgumentNullException(nameof(itemIds));
            }

            lock (this)
            {
                if (m_server == null)
                {
                    throw new NotConnectedException();
                }
                string methodName = "IOPCBrowse.GetProperties";

                // initialize arguments.
                string[] pItemIDs = new string[itemIds.Length];

                for (int ii = 0; ii < itemIds.Length; ii++)
                {
                    pItemIDs[ii] = itemIds[ii].ItemName;
                }

                IntPtr pPropertyLists = IntPtr.Zero;

                // invoke COM method.
                try
                {
                    IOPCBrowse server = BeginComCall <IOPCBrowse>(methodName, true);
                    server.GetProperties(
                        itemIds.Length,
                        pItemIDs,
                        (returnValues) ? 1 : 0,
                        (propertyIDs != null) ? propertyIDs.Length : 0,
                        Technosoftware.DaAeHdaClient.Com.Da.Interop.GetPropertyIDs(propertyIDs),
                        out pPropertyLists);
                }
                catch (Exception e)
                {
                    ComCallError(methodName, e);
                    throw Technosoftware.DaAeHdaClient.Com.Interop.CreateException(methodName, e);
                }
                finally
                {
                    EndComCall(methodName);
                }

                // unmarshal results.
                TsCDaItemPropertyCollection[] resultLists = Technosoftware.DaAeHdaClient.Com.Da.Interop.GetItemPropertyCollections(ref pPropertyLists, itemIds.Length, true);

                // replace integer codes with qnames passed in.
                if (propertyIDs != null && propertyIDs.Length > 0)
                {
                    foreach (TsCDaItemPropertyCollection resultList in resultLists)
                    {
                        for (int ii = 0; ii < resultList.Count; ii++)
                        {
                            resultList[ii].ID = propertyIDs[ii];
                        }
                    }
                }

                // return the results.
                return(resultLists);
            }
        }
Example #3
0
        /// <summary>
        /// Fetches the children of a branch that meet the filter criteria.
        /// </summary>
        /// <param name="itemID">The identifier of branch which is the target of the search.</param>
        /// <param name="filters">The filters to use to limit the set of child elements returned.</param>
        /// <param name="position">An object used to continue a browse that could not be completed.</param>
        /// <returns>The set of elements found.</returns>
        public virtual TsCDaBrowseElement[] Browse(
            OpcItem itemID,
            TsCDaBrowseFilters filters,
            out Technosoftware.DaAeHdaClient.Da.TsCDaBrowsePosition position)
        {
            if (filters == null)
            {
                throw new ArgumentNullException(nameof(filters));
            }

            lock (this)
            {
                if (m_server == null)
                {
                    throw new NotConnectedException();
                }
                string methodName = "IOPCBrowse.Browse";

                position = null;

                // initialize arguments.
                int count        = 0;
                int moreElements = 0;

                IntPtr pContinuationPoint = IntPtr.Zero;
                IntPtr pElements          = IntPtr.Zero;

                // invoke COM method.
                try
                {
                    IOPCBrowse server = BeginComCall <IOPCBrowse>(methodName, true);
                    server.Browse(
                        (itemID != null && itemID.ItemName != null) ? itemID.ItemName : "",
                        ref pContinuationPoint,
                        filters.MaxElementsReturned,
                        Technosoftware.DaAeHdaClient.Com.Da.Interop.GetBrowseFilter(filters.BrowseFilter),
                        (filters.ElementNameFilter != null) ? filters.ElementNameFilter : "",
                        (filters.VendorFilter != null) ? filters.VendorFilter : "",
                        (filters.ReturnAllProperties) ? 1 : 0,
                        (filters.ReturnPropertyValues) ? 1 : 0,
                        (filters.PropertyIDs != null) ? filters.PropertyIDs.Length : 0,
                        Technosoftware.DaAeHdaClient.Com.Da.Interop.GetPropertyIDs(filters.PropertyIDs),
                        out moreElements,
                        out count,
                        out pElements);
                }
                catch (Exception e)
                {
                    ComCallError(methodName, e);
                    throw Technosoftware.DaAeHdaClient.Com.Interop.CreateException(methodName, e);
                }
                finally
                {
                    EndComCall(methodName);
                }

                // unmarshal results.
                TsCDaBrowseElement[] elements = Technosoftware.DaAeHdaClient.Com.Da.Interop.GetBrowseElements(ref pElements, count, true);

                string continuationPoint = Marshal.PtrToStringUni(pContinuationPoint);
                Marshal.FreeCoTaskMem(pContinuationPoint);

                // check if more results exist.
                if (moreElements != 0 || (continuationPoint != null && continuationPoint != ""))
                {
                    // allocate new browse position object.
                    position = new Technosoftware.DaAeHdaClient.Com.Da.BrowsePosition(itemID, filters, continuationPoint);
                }

                // process results.
                ProcessResults(elements, filters.PropertyIDs);

                return(elements);
            }
        }