Beispiel #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);
            }
        }
Beispiel #2
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);
            }
        }