Exemplo n.º 1
0
 /// <summary>Continues a browse operation with previously specified search criteria.</summary>
 /// <returns>The set of elements found.</returns>
 /// <requirements>OPC XML-DA Server or OPC Data Access Server V2.x / V3.x</requirements>
 /// <param name="position">An object containing the browse operation state information.</param>
 public TsCDaBrowseElement[] BrowseNext(ref TsCDaBrowsePosition position)
 {
     LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.DataAccess);
     if (Server == null)
     {
         throw new NotConnectedException();
     }
     return(((ITsDaServer)Server).BrowseNext(ref position));
 }
Exemplo n.º 2
0
 /// <summary>Fetches the children of a branch that meet the filter criteria.</summary>
 /// <returns>The set of elements found.</returns>
 /// <requirements>OPC XML-DA Server or OPC Data Access Server V2.x / V3.x</requirements>
 /// <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>
 public TsCDaBrowseElement[] Browse(
     OpcItem itemId,
     TsCDaBrowseFilters filters,
     out TsCDaBrowsePosition position)
 {
     LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.DataAccess);
     if (Server == null)
     {
         throw new NotConnectedException();
     }
     return(((ITsDaServer)Server).Browse(itemId, filters, out position));
 }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Browses for children of the element at the current node.
        /// </summary>
        private void Browse(TreeNode node)
        {
            try
            {
                // get the server for the current node.
                OpcServer selection = FindServer(node);

                if (!typeof(TsCDaServer).IsInstanceOfType(selection))
                {
                    return;
                }

                TsCDaServer server = (TsCDaServer)selection;

                // get the current element to use for a browse.
                TsCDaBrowseElement parent = null;
                OpcItem            itemID = null;

                if (node.Tag != null && node.Tag.GetType() == typeof(TsCDaBrowseElement))
                {
                    parent = (TsCDaBrowseElement)node.Tag;
                    itemID = new OpcItem(parent.ItemPath, parent.ItemName);
                }

                // clear the node children.
                node.Nodes.Clear();

                // add properties
                if (parent != null && parent.Properties != null)
                {
                    foreach (TsCDaItemProperty property in parent.Properties)
                    {
                        AddItemProperty(node, property);
                    }
                }

                // begin a browse.
                Technosoftware.DaAeHdaClient.Da.TsCDaBrowsePosition position = null;
                TsCDaBrowseElement[] elements = server.Browse(itemID, m_filters, out position);

                // add children.
                if (elements != null)
                {
                    foreach (TsCDaBrowseElement element in elements)
                    {
                        AddBrowseElement(node, element);
                    }

                    node.Expand();
                }

                // loop until all elements have been fetched.
                while (position != null)
                {
                    DialogResult result = MessageBox.Show(
                        "More items meeting search criteria exist. Continue browse?",
                        "Browse Items",
                        MessageBoxButtons.YesNo);

                    if (result == DialogResult.No)
                    {
                        break;
                    }

                    // fetch next batch of elements,.
                    elements = server.BrowseNext(ref position);

                    // add children.
                    if (elements != null)
                    {
                        foreach (TsCDaBrowseElement element in elements)
                        {
                            AddBrowseElement(node, element);
                        }

                        node.Expand();
                    }
                }

                // send notification that property list changed.
                if (ElementSelected != null)
                {
                    if (node.Tag.GetType() == typeof(TsCDaBrowseElement))
                    {
                        ElementSelected((TsCDaBrowseElement)node.Tag);
                    }
                    else
                    {
                        ElementSelected(null);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }