Пример #1
0
        /// <summary>
        /// Метод для поиска всех тегов на ОРС сервере
        /// </summary>
        /// <param name="itemName"></param>
        public void Browse(string itemName = "")
        {
            var itemIdentifier = new Opc.ItemIdentifier();

            itemIdentifier.ItemName = itemName;

            var browseFilters = new Opc.Da.BrowseFilters();

            browseFilters.BrowseFilter = browseFilter.all;

            var browsePosition = new Opc.Da.BrowsePosition(itemIdentifier, browseFilters);

            BrowseElement[] browseElements = serverHandle.Browse(itemIdentifier, browseFilters, out browsePosition);

            if (browseElements != null)
            {
                foreach (BrowseElement element in browseElements)
                {
                    if (element.IsItem)
                    {
                        Console.WriteLine("Item name : {0}", element.ItemName);
                    }
                    else
                    {
                        Console.WriteLine();
                        Console.WriteLine("Group name : {0}", element.ItemName);
                        Browse(element.ItemName);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Вспомогательный метод для инициализации списка тегов с сервера.
        /// Вызывается при соединении с сервером
        /// </summary>
        /// <param name="itemName"></param>
        void InitTagList(string itemName = "")
        {
            var itemIdentifier = new Opc.ItemIdentifier();

            itemIdentifier.ItemName = itemName;

            var browseFilters = new Opc.Da.BrowseFilters();

            browseFilters.BrowseFilter = browseFilter.all;

            var browsePosition = new Opc.Da.BrowsePosition(itemIdentifier, browseFilters);

            BrowseElement[] browseElements = serverHandle.Browse(itemIdentifier, browseFilters, out browsePosition);

            if (browseElements != null)
            {
                foreach (BrowseElement element in browseElements)
                {
                    if (element.IsItem)
                    {
                        var item = new Opc.Da.Item
                        {
                            ItemName = element.ItemName
                        };
                        tagList.Add(item);
                    }
                    else
                    {
                        InitTagList(element.ItemName);
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Метод рекурсивного поиска тегов в UA структурах и добавление их в disoveredTags
        /// </summary>
        /// <param name="id">объект который надо просканировать</param>
        private int Browse(Opc.ItemIdentifier id = null)
        {
            try
            {
                var filters = new Opc.Da.BrowseFilters {
                    BrowseFilter = Opc.Da.browseFilter.all
                };
                Opc.Da.BrowsePosition pos = null;
                var elements = server.Browse(id, filters, out pos);
                if (elements != null)
                {
                    foreach (Opc.Da.BrowseElement element in elements)
                    {
                        if (element.IsItem)
                        {
                            _tags.Add(new Opc.Da.Item {
                                ItemName = element.ItemName
                            });
                        }
                        if (element.HasChildren)
                        {
                            Browse(new Opc.ItemIdentifier(element.ItemPath, element.ItemName));
                        }
                    }
                }

                return(0);
            }


            catch (Exception ex)
            {
                return(-1);
            }
        }
Пример #4
0
 // Token: 0x06000049 RID: 73 RVA: 0x000035E4 File Offset: 0x000025E4
 public BrowseElement[] Browse(ItemIdentifier itemID, BrowseFilters filters, out BrowsePosition position)
 {
     if (this.m_server == null)
     {
         throw new NotConnectedException();
     }
     return(((IServer)this.m_server).Browse(itemID, filters, out position));
 }
Пример #5
0
        //======================================================================
        // BrowseNext

        /// <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 BrowseElement[] BrowseNext(ref BrowsePosition position)
        {
            if (m_server == null)
            {
                throw new NotConnectedException();
            }
            return(((IServer)m_server).BrowseNext(ref position));
        }
Пример #6
0
        //======================================================================
        // BrowseNext

        /// <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 Opc.Da.BrowseElement[] BrowseNext(ref Opc.Da.BrowsePosition position)
        {
            if (position == null)
            {
                throw new ArgumentNullException("position");
            }

            lock (this)
            {
                return(m_cache.Browse(position.ItemID, position.Filters, ref position));
            }
        }
Пример #7
0
        //======================================================================
        // Browse

        /// <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 Opc.Da.BrowseElement[] Browse(
            ItemIdentifier itemID,
            BrowseFilters filters,
            out Opc.Da.BrowsePosition position)
        {
            position = null;

            lock (this)
            {
                return(m_cache.Browse(itemID, filters, ref position));
            }
        }
Пример #8
0
        //======================================================================
        // Browse

        /// <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 BrowseElement[] Browse(
            ItemIdentifier itemID,
            BrowseFilters filters,
            out Opc.Da.BrowsePosition position)
        {
            position = null;

            lock (this)
            {
                if (m_proxy == null)
                {
                    throw new NotConnectedException();
                }

                // use default filters if none specified.
                if (filters == null)
                {
                    filters = new BrowseFilters();
                }

                BrowsePosition pos = new BrowsePosition(itemID, filters, m_options.Locale, ((m_options.Filters & (int)ResultFilter.ErrorText) != 0));

                OpcXml.Da10.BrowseElement[] elements = null;
                OpcXml.Da10.OPCError[]      errors   = null;

                OpcXml.Da10.ReplyBase reply = m_proxy.Browse(
                    OpcXml.Da10.Request.GetPropertyNames(filters.PropertyIDs),
                    pos.Locale,
                    "",
                    (itemID != null)?itemID.ItemPath:null,
                    (itemID != null)?itemID.ItemName:null,
                    ref pos.ContinuationPoint,
                    filters.MaxElementsReturned,
                    OpcXml.Da10.Request.GetBrowseFilter(filters.BrowseFilter),
                    filters.ElementNameFilter,
                    filters.VendorFilter,
                    filters.ReturnAllProperties,
                    filters.ReturnPropertyValues,
                    pos.ReturnErrorText,
                    out elements,
                    out errors,
                    out pos.MoreElements);

                CacheResponse(pos.Locale, reply, errors);

                if (pos.MoreElements || (pos.ContinuationPoint != null && pos.ContinuationPoint != ""))
                {
                    position = pos;
                }

                return(OpcXml.Da10.Request.GetBrowseElements(elements));
            }
        }
Пример #9
0
        //======================================================================
        // BrowseNext

        /// <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 BrowseElement[] BrowseNext(ref Opc.Da.BrowsePosition position)
        {
            if (position == null)
            {
                throw new ArgumentNullException("position");
            }
            if (m_proxy == null)
            {
                throw new NotConnectedException();
            }

            lock (this)
            {
                BrowsePosition pos = (BrowsePosition)position;

                if (pos.ContinuationPoint == null || pos.ContinuationPoint == "")
                {
                    throw new BrowseCannotContinueException();
                }

                OpcXml.Da10.BrowseElement[] elements = null;
                OpcXml.Da10.OPCError[]      errors   = null;

                OpcXml.Da10.ReplyBase reply = m_proxy.Browse(
                    OpcXml.Da10.Request.GetPropertyNames(pos.Filters.PropertyIDs),
                    pos.Locale,
                    "",
                    (pos.ItemID != null)?pos.ItemID.ItemPath:null,
                    (pos.ItemID != null)?pos.ItemID.ItemName:null,
                    ref pos.ContinuationPoint,
                    pos.Filters.MaxElementsReturned,
                    OpcXml.Da10.Request.GetBrowseFilter(pos.Filters.BrowseFilter),
                    pos.Filters.ElementNameFilter,
                    pos.Filters.VendorFilter,
                    pos.Filters.ReturnAllProperties,
                    pos.Filters.ReturnPropertyValues,
                    pos.ReturnErrorText,
                    out elements,
                    out errors,
                    out pos.MoreElements);

                CacheResponse(pos.Locale, reply, errors);

                position = null;

                if (pos.MoreElements || (pos.ContinuationPoint != null && pos.ContinuationPoint != ""))
                {
                    position = pos;
                }

                return(OpcXml.Da10.Request.GetBrowseElements(elements));
            }
        }
Пример #10
0
        private bool BuildBrowseStack(ItemIdentifier itemID, ItemIdentifier targetID)
        {
            BrowseFilters filters = new BrowseFilters {
                MaxElementsReturned  = 0,
                BrowseFilter         = browseFilter.all,
                ElementNameFilter    = null,
                VendorFilter         = null,
                ReturnAllProperties  = false,
                PropertyIDs          = null,
                ReturnPropertyValues = false
            };

            BrowseElement[]       elementArray = null;
            Opc.Da.BrowsePosition position     = null;
            try
            {
                elementArray = this.m_server.Browse(itemID, filters, out position);
            }
            catch (Exception)
            {
                this.m_browseStack.Clear();
                return(false);
            }
            if (position != null)
            {
                position.Dispose();
                position = null;
            }
            if ((elementArray == null) || (elementArray.Length == 0))
            {
                this.m_browseStack.Clear();
                return(false);
            }
            foreach (BrowseElement element in elementArray)
            {
                if (element.ItemName == targetID.ItemName)
                {
                    return(true);
                }
                if (targetID.ItemName.StartsWith(element.ItemName))
                {
                    ItemIdentifier identifier = new ItemIdentifier(targetID.ItemName);
                    this.m_browseStack.Push(identifier);
                    return(this.BuildBrowseStack(identifier, targetID));
                }
            }
            return(false);
        }
Пример #11
0
        public virtual BrowseElement[] BrowseNext(ref Opc.Da.BrowsePosition position)
        {
            lock (this)
            {
                if (m_server == null)
                {
                    throw new NotConnectedException();
                }

                if (position == null || (object)position.GetType() != typeof(BrowsePosition))
                {
                    throw new BrowseCannotContinueException();
                }

                BrowsePosition browsePosition = (BrowsePosition)position;
                if (browsePosition == null || browsePosition.ContinuationPoint == null || browsePosition.ContinuationPoint == "")
                {
                    throw new BrowseCannotContinueException();
                }

                int            pdwCount             = 0;
                int            pbMoreElements       = 0;
                ItemIdentifier itemID               = ((BrowsePosition)position).ItemID;
                BrowseFilters  filters              = ((BrowsePosition)position).Filters;
                IntPtr         pszContinuationPoint = Marshal.StringToCoTaskMemUni(browsePosition.ContinuationPoint);
                IntPtr         ppBrowseElements     = IntPtr.Zero;
                try
                {
                    ((IOPCBrowse)m_server).Browse((itemID != null && itemID.ItemName != null) ? itemID.ItemName : "", ref pszContinuationPoint, filters.MaxElementsReturned, 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, Interop.GetPropertyIDs(filters.PropertyIDs), out pbMoreElements, out pdwCount, out ppBrowseElements);
                }
                catch (Exception e)
                {
                    throw OpcCom.Interop.CreateException("IOPCBrowse.BrowseNext", e);
                }

                BrowseElement[] browseElements = Interop.GetBrowseElements(ref ppBrowseElements, pdwCount, deallocate: true);
                browsePosition.ContinuationPoint = Marshal.PtrToStringUni(pszContinuationPoint);
                Marshal.FreeCoTaskMem(pszContinuationPoint);
                if (pbMoreElements == 0 && (browsePosition.ContinuationPoint == null || browsePosition.ContinuationPoint == ""))
                {
                    position = null;
                }

                ProcessResults(browseElements, filters.PropertyIDs);
                return(browseElements);
            }
        }
Пример #12
0
        public override BrowseElement[] BrowseNext(ref Opc.Da.BrowsePosition position)
        {
            lock (this)
            {
                if (m_server == null)
                {
                    throw new NotConnectedException();
                }

                if (position == null && (object)position.GetType() != typeof(BrowsePosition))
                {
                    throw new BrowseCannotContinueException();
                }

                BrowsePosition position2 = (BrowsePosition)position;
                ItemIdentifier itemID    = position2.ItemID;
                BrowseFilters  filters   = position2.Filters;
                ArrayList      arrayList = new ArrayList();
                if (position2.IsBranch)
                {
                    BrowseElement[] elements = GetElements(arrayList.Count, itemID, filters, branches: true, ref position2);
                    if (elements != null)
                    {
                        arrayList.AddRange(elements);
                    }

                    position = position2;
                    if (position != null)
                    {
                        return((BrowseElement[])arrayList.ToArray(typeof(BrowseElement)));
                    }
                }

                if (filters.BrowseFilter != browseFilter.branch)
                {
                    BrowseElement[] elements2 = GetElements(arrayList.Count, itemID, filters, branches: false, ref position2);
                    if (elements2 != null)
                    {
                        arrayList.AddRange(elements2);
                    }

                    position = position2;
                }

                return((BrowseElement[])arrayList.ToArray(typeof(BrowseElement)));
            }
        }
Пример #13
0
 public virtual BrowseElement[] BrowseNext(ref Opc.Da.BrowsePosition position)
 {
     lock (this)
     {
         if (base.m_server == null)
         {
             throw new NotConnectedException();
         }
         if ((position == null) || (position.GetType() != typeof(OpcCom.Da.BrowsePosition)))
         {
             throw new BrowseCannotContinueException();
         }
         OpcCom.Da.BrowsePosition position2 = (OpcCom.Da.BrowsePosition)position;
         if (((position2 == null) || (position2.ContinuationPoint == null)) || (position2.ContinuationPoint == ""))
         {
             throw new BrowseCannotContinueException();
         }
         int            pdwCount             = 0;
         int            pbMoreElements       = 0;
         ItemIdentifier itemID               = ((OpcCom.Da.BrowsePosition)position).ItemID;
         BrowseFilters  filters              = ((OpcCom.Da.BrowsePosition)position).Filters;
         IntPtr         pszContinuationPoint = Marshal.StringToCoTaskMemUni(position2.ContinuationPoint);
         IntPtr         zero = IntPtr.Zero;
         try
         {
             ((IOPCBrowse)base.m_server).Browse(((itemID != null) && (itemID.ItemName != null)) ? itemID.ItemName : "", ref pszContinuationPoint, filters.MaxElementsReturned, OpcCom.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, OpcCom.Da.Interop.GetPropertyIDs(filters.PropertyIDs), out pbMoreElements, out pdwCount, out zero);
         }
         catch (Exception exception)
         {
             throw OpcCom.Interop.CreateException("IOPCBrowse.BrowseNext", exception);
         }
         BrowseElement[] elements = OpcCom.Da.Interop.GetBrowseElements(ref zero, pdwCount, true);
         position2.ContinuationPoint = Marshal.PtrToStringUni(pszContinuationPoint);
         Marshal.FreeCoTaskMem(pszContinuationPoint);
         if ((pbMoreElements == 0) && ((position2.ContinuationPoint == null) || (position2.ContinuationPoint == "")))
         {
             position = null;
         }
         this.ProcessResults(elements, filters.PropertyIDs);
         return(elements);
     }
 }
Пример #14
0
 public override BrowseElement[] BrowseNext(ref Opc.Da.BrowsePosition position)
 {
     lock (this)
     {
         if (base.m_server == null)
         {
             throw new NotConnectedException();
         }
         if ((position == null) && (position.GetType() != typeof(OpcCom.Da20.BrowsePosition)))
         {
             throw new BrowseCannotContinueException();
         }
         OpcCom.Da20.BrowsePosition position2 = (OpcCom.Da20.BrowsePosition)position;
         ItemIdentifier             itemID    = position2.ItemID;
         BrowseFilters filters = position2.Filters;
         ArrayList     list    = new ArrayList();
         if (position2.IsBranch)
         {
             BrowseElement[] c = this.GetElements(list.Count, itemID, filters, true, ref position2);
             if (c != null)
             {
                 list.AddRange(c);
             }
             position = position2;
             if (position != null)
             {
                 return((BrowseElement[])list.ToArray(typeof(BrowseElement)));
             }
         }
         if (filters.BrowseFilter != browseFilter.branch)
         {
             BrowseElement[] elementArray2 = this.GetElements(list.Count, itemID, filters, false, ref position2);
             if (elementArray2 != null)
             {
                 list.AddRange(elementArray2);
             }
             position = position2;
         }
         return((BrowseElement[])list.ToArray(typeof(BrowseElement)));
     }
 }
Пример #15
0
        private BrowseElement FindChild(string name)
        {
            ItemIdentifier itemID = null;

            if (this.m_browseStack.Count > 0)
            {
                itemID = (ItemIdentifier)this.m_browseStack.Peek();
            }
            BrowseElement[] elementArray = null;
            try
            {
                BrowseFilters filters = new BrowseFilters {
                    MaxElementsReturned  = 0,
                    BrowseFilter         = browseFilter.all,
                    ElementNameFilter    = name,
                    VendorFilter         = null,
                    ReturnAllProperties  = false,
                    PropertyIDs          = null,
                    ReturnPropertyValues = false
                };
                Opc.Da.BrowsePosition position = null;
                elementArray = this.m_server.Browse(itemID, filters, out position);
                if (position != null)
                {
                    position.Dispose();
                    position = null;
                }
            }
            catch (Exception)
            {
                return(null);
            }
            if ((elementArray != null) && (elementArray.Length > 0))
            {
                return(elementArray[0]);
            }
            return(null);
        }
Пример #16
0
        public virtual BrowseElement[] Browse(ItemIdentifier itemID, BrowseFilters filters, out Opc.Da.BrowsePosition position)
        {
            if (filters == null)
            {
                throw new ArgumentNullException("filters");
            }

            lock (this)
            {
                if (m_server == null)
                {
                    throw new NotConnectedException();
                }

                position = null;
                int    pdwCount             = 0;
                int    pbMoreElements       = 0;
                IntPtr pszContinuationPoint = IntPtr.Zero;
                IntPtr ppBrowseElements     = IntPtr.Zero;
                try
                {
                    ((IOPCBrowse)m_server).Browse((itemID != null && itemID.ItemName != null) ? itemID.ItemName : "", ref pszContinuationPoint, filters.MaxElementsReturned, 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, Interop.GetPropertyIDs(filters.PropertyIDs), out pbMoreElements, out pdwCount, out ppBrowseElements);
                }
                catch (Exception e)
                {
                    throw OpcCom.Interop.CreateException("IOPCBrowse.Browse", e);
                }

                BrowseElement[] browseElements = Interop.GetBrowseElements(ref ppBrowseElements, pdwCount, deallocate: true);
                string          text           = Marshal.PtrToStringUni(pszContinuationPoint);
                Marshal.FreeCoTaskMem(pszContinuationPoint);
                if (pbMoreElements != 0 || (text != null && text != ""))
                {
                    position = new BrowsePosition(itemID, filters, text);
                }

                ProcessResults(browseElements, filters.PropertyIDs);
                return(browseElements);
            }
        }
Пример #17
0
 public virtual BrowseElement[] Browse(ItemIdentifier itemID, BrowseFilters filters, out Opc.Da.BrowsePosition position)
 {
     if (filters == null)
     {
         throw new ArgumentNullException("filters");
     }
     lock (this)
     {
         if (base.m_server == null)
         {
             throw new NotConnectedException();
         }
         position = null;
         int    pdwCount         = 0;
         int    pbMoreElements   = 0;
         IntPtr zero             = IntPtr.Zero;
         IntPtr ppBrowseElements = IntPtr.Zero;
         try
         {
             ((IOPCBrowse)base.m_server).Browse(((itemID != null) && (itemID.ItemName != null)) ? itemID.ItemName : "", ref zero, filters.MaxElementsReturned, OpcCom.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, OpcCom.Da.Interop.GetPropertyIDs(filters.PropertyIDs), out pbMoreElements, out pdwCount, out ppBrowseElements);
         }
         catch (Exception exception)
         {
             throw OpcCom.Interop.CreateException("IOPCBrowse.Browse", exception);
         }
         BrowseElement[] elements          = OpcCom.Da.Interop.GetBrowseElements(ref ppBrowseElements, pdwCount, true);
         string          continuationPoint = Marshal.PtrToStringUni(zero);
         Marshal.FreeCoTaskMem(zero);
         if ((pbMoreElements != 0) || ((continuationPoint != null) && (continuationPoint != "")))
         {
             position = new OpcCom.Da.BrowsePosition(itemID, filters, continuationPoint);
         }
         this.ProcessResults(elements, filters.PropertyIDs);
         return(elements);
     }
 }
Пример #18
0
        /// <summary>
        /// Returns the set of elements in the address space that meet the specified criteria.
        /// </summary>
        public Opc.Da.BrowseElement[] Browse(
            ItemIdentifier itemID,
            BrowseFilters filters,
            ref Opc.Da.BrowsePosition position)
        {
            lock (this)
            {
                if (m_disposed)
                {
                    throw new ObjectDisposedException("Opc.Da.Cache");
                }

                BrowseElement element = m_addressSpace;

                // find desired element.
                string browsePath = (itemID != null) ? itemID.ItemName : null;

                if (browsePath != null && browsePath.Length > 0)
                {
                    element = m_addressSpace.Find(browsePath);

                    if (element == null)
                    {
                        // check if browsing a property item.
                        PropertyID property = Property.VALUE;

                        string rootID = LookupProperty(browsePath, out property);

                        if (rootID != null)
                        {
                            element = m_addressSpace.Find(rootID);
                        }

                        if (element == null)
                        {
                            throw new ResultIDException(ResultID.Da.E_UNKNOWN_ITEM_NAME);
                        }

                        // property items never contain children.
                        return(new Opc.Da.BrowseElement[0]);
                    }
                }

                // check if no elements exist.
                if (element.Count == 0)
                {
                    return(new Opc.Da.BrowseElement[0]);
                }

                // determine start position.
                int start = 0;

                if (position != null)
                {
                    start = ((BrowsePosition)position).Index;
                    position.Dispose();
                    position = null;
                }

                // process child nodes.
                ArrayList results = new ArrayList();

                for (int ii = start; ii < element.Count; ii++)
                {
                    BrowseElement child = element.Child(ii);

                    // exclude elements without children.
                    if (filters.BrowseFilter == browseFilter.branch && child.Count == 0)
                    {
                        continue;
                    }

                    // check if an element is an item.
                    CacheItem item = (CacheItem)m_items[child.ItemID];

                    // exclude elements which are not items.
                    if (filters.BrowseFilter == browseFilter.item && item == null)
                    {
                        continue;
                    }

                    // apply name filter (using the SQL LIKE operator).
                    if (filters.ElementNameFilter != null && filters.ElementNameFilter.Length > 0)
                    {
                        if (!Opc.Convert.Match(child.Name, filters.ElementNameFilter, true))
                        {
                            continue;
                        }
                    }

                    // add element to list of results.
                    Opc.Da.BrowseElement result = new Opc.Da.BrowseElement();

                    result.Name        = child.Name;
                    result.ItemName    = child.ItemID;
                    result.ItemPath    = null;
                    result.IsItem      = item != null;
                    result.HasChildren = child.Count > 0;
                    result.Properties  = null;

                    // add properties to results.
                    if (filters.ReturnAllProperties || filters.PropertyIDs != null)
                    {
                        result.Properties = GetProperties(item, (filters.ReturnAllProperties) ? null : filters.PropertyIDs, filters.ReturnPropertyValues);
                    }

                    results.Add(result);

                    // check if max elements exceeded.
                    if (filters.MaxElementsReturned > 0 && results.Count >= filters.MaxElementsReturned)
                    {
                        if (ii + 1 < element.Count)
                        {
                            position = new BrowsePosition(itemID, filters);
                            ((BrowsePosition)position).Index = ii + 1;
                        }

                        break;
                    }
                }
                // return results.
                return((Opc.Da.BrowseElement[])results.ToArray(typeof(Opc.Da.BrowseElement)));
            }
        }
Пример #19
0
        public override BrowseElement[] Browse(ItemIdentifier itemID, BrowseFilters filters, out Opc.Da.BrowsePosition position)
        {
            if (filters == null)
            {
                throw new ArgumentNullException("filters");
            }

            position = null;
            lock (this)
            {
                if (m_server == null)
                {
                    throw new NotConnectedException();
                }

                BrowsePosition position2 = null;
                ArrayList      arrayList = new ArrayList();
                if (filters.BrowseFilter != browseFilter.item)
                {
                    BrowseElement[] elements = GetElements(arrayList.Count, itemID, filters, branches: true, ref position2);
                    if (elements != null)
                    {
                        arrayList.AddRange(elements);
                    }

                    position = position2;
                    if (position != null)
                    {
                        return((BrowseElement[])arrayList.ToArray(typeof(BrowseElement)));
                    }
                }

                if (filters.BrowseFilter != browseFilter.branch)
                {
                    BrowseElement[] elements2 = GetElements(arrayList.Count, itemID, filters, branches: false, ref position2);
                    if (elements2 != null)
                    {
                        arrayList.AddRange(elements2);
                    }

                    position = position2;
                }

                return((BrowseElement[])arrayList.ToArray(typeof(BrowseElement)));
            }
        }
Пример #20
0
        //======================================================================
        // Browse

        /// <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 BrowseElement[] Browse(
            ItemIdentifier itemID,
            BrowseFilters filters,
            out Opc.Da.BrowsePosition position)
        {
            if (filters == null)
            {
                throw new ArgumentNullException("filters");
            }

            lock (this)
            {
                if (m_server == null)
                {
                    throw new NotConnectedException();
                }

                position = null;

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

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

                // invoke COM method.
                try
                {
                    ((IOPCBrowse)m_server).Browse(
                        (itemID != null && itemID.ItemName != null)?itemID.ItemName:"",
                        ref pContinuationPoint,
                        filters.MaxElementsReturned,
                        OpcCom.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,
                        OpcCom.Da.Interop.GetPropertyIDs(filters.PropertyIDs),
                        out moreElements,
                        out count,
                        out pElements);
                }
                catch (Exception e)
                {
                    throw OpcCom.Interop.CreateException("IOPCBrowse.Browse", e);
                }

                // unmarshal results.
                BrowseElement[] elements = OpcCom.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 OpcCom.Da.BrowsePosition(itemID, filters, continuationPoint);
                }

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

                return(elements);
            }
        }
Пример #21
0
        private void Browse(ItemIdentifier itemID, OPCBROWSETYPE dwBrowseFilterType, string szFilterCriteria, short vtDataTypeFilter, int dwAccessRightsFilter, ArrayList hits)
        {
            BrowseFilters filters = new BrowseFilters {
                MaxElementsReturned = 0,
                BrowseFilter        = browseFilter.all,
                ElementNameFilter   = (dwBrowseFilterType != OPCBROWSETYPE.OPC_FLAT) ? szFilterCriteria : "",
                VendorFilter        = null,
                ReturnAllProperties = false
            };

            filters.PropertyIDs          = new PropertyID[] { Property.DATATYPE, Property.ACCESSRIGHTS };
            filters.ReturnPropertyValues = true;
            BrowseElement[] elementArray = null;
            try
            {
                Opc.Da.BrowsePosition position = null;
                elementArray = this.m_server.Browse(itemID, filters, out position);
                if (position != null)
                {
                    position.Dispose();
                    position = null;
                }
            }
            catch
            {
                throw new ExternalException("BrowseOPCItemIDs", -2147467259);
            }
            foreach (BrowseElement element in elementArray)
            {
                if (dwBrowseFilterType == OPCBROWSETYPE.OPC_FLAT)
                {
                    if (element.HasChildren)
                    {
                        this.Browse(new ItemIdentifier(element.ItemName), dwBrowseFilterType, szFilterCriteria, vtDataTypeFilter, dwAccessRightsFilter, hits);
                    }
                }
                else
                {
                    if (dwBrowseFilterType == OPCBROWSETYPE.OPC_BRANCH)
                    {
                        if (element.HasChildren)
                        {
                            goto Label_00F9;
                        }
                        continue;
                    }
                    if ((dwBrowseFilterType == OPCBROWSETYPE.OPC_LEAF) && element.HasChildren)
                    {
                        continue;
                    }
                }
Label_00F9:
                if (element.IsItem)
                {
                    if (vtDataTypeFilter != 0)
                    {
                        short type = (short)OpcCom.Interop.GetType((System.Type)element.Properties[0].Value);
                        if (type != vtDataTypeFilter)
                        {
                            continue;
                        }
                    }
                    if (dwAccessRightsFilter != 0)
                    {
                        accessRights rights = (accessRights)element.Properties[1].Value;
                        if (((dwAccessRightsFilter == 1) && (rights == accessRights.writable)) || ((dwAccessRightsFilter == 2) && (rights == accessRights.readable)))
                        {
                            continue;
                        }
                    }
                }
                if (dwBrowseFilterType != OPCBROWSETYPE.OPC_FLAT)
                {
                    hits.Add(element.Name);
                }
                else if (element.IsItem && ((szFilterCriteria.Length == 0) || Opc.Convert.Match(element.ItemName, szFilterCriteria, true)))
                {
                    hits.Add(element.ItemName);
                }
            }
        }
Пример #22
0
        public void ChangeBrowsePosition(OPCBROWSEDIRECTION dwBrowseDirection, string szString)
        {
            OpcCom.Da.Wrapper.Server server;
            Monitor.Enter(server = this);
            try
            {
                BrowseElement element;
                BrowseFilters filters = new BrowseFilters {
                    MaxElementsReturned  = 0,
                    BrowseFilter         = browseFilter.all,
                    ElementNameFilter    = null,
                    VendorFilter         = null,
                    ReturnAllProperties  = false,
                    PropertyIDs          = null,
                    ReturnPropertyValues = false
                };
                ItemIdentifier        itemID   = null;
                Opc.Da.BrowsePosition position = null;
                switch (dwBrowseDirection)
                {
                case OPCBROWSEDIRECTION.OPC_BROWSE_UP:
                    if (this.m_browseStack.Count == 0)
                    {
                        throw CreateException(-2147467259);
                    }
                    goto Label_0146;

                case OPCBROWSEDIRECTION.OPC_BROWSE_DOWN:
                    if ((szString == null) || (szString.Length == 0))
                    {
                        throw CreateException(-2147024809);
                    }
                    goto Label_00F4;

                case OPCBROWSEDIRECTION.OPC_BROWSE_TO:
                    if ((szString != null) && (szString.Length != 0))
                    {
                        break;
                    }
                    this.m_browseStack.Clear();
                    goto Label_0179;

                default:
                    goto Label_0179;
                }
                itemID = new ItemIdentifier(szString);
                BrowseElement[] elementArray = null;
                try
                {
                    elementArray = this.m_server.Browse(itemID, filters, out position);
                }
                catch (Exception)
                {
                    throw CreateException(-2147024809);
                }
                if ((elementArray == null) || (elementArray.Length == 0))
                {
                    throw CreateException(-2147024809);
                }
                this.m_browseStack.Clear();
                this.m_browseStack.Push(null);
                this.m_browseStack.Push(itemID);
                goto Label_0179;
Label_00F4:
                element = this.FindChild(szString);
                if ((element == null) || !element.HasChildren)
                {
                    throw CreateException(-2147024809);
                }
                this.m_browseStack.Push(new ItemIdentifier(element.ItemName));
                goto Label_0179;
Label_0146:
                itemID = (ItemIdentifier)this.m_browseStack.Pop();
                if ((this.m_browseStack.Count > 0) && (this.m_browseStack.Peek() == null))
                {
                    this.BuildBrowseStack(itemID);
                }
Label_0179:
                if (position != null)
                {
                    position.Dispose();
                    position = null;
                }
            }
            catch (Exception exception)
            {
                throw CreateException(exception);
            }
            finally
            {
                Monitor.Exit(server);
            }
        }
Пример #23
0
 public void Browse(string szItemID, ref IntPtr pszContinuationPoint, int dwMaxElementsReturned, OPCBROWSEFILTER dwBrowseFilter, string szElementNameFilter, string szVendorFilter, int bReturnAllProperties, int bReturnPropertyValues, int dwPropertyCount, int[] pdwPropertyIDs, out int pbMoreElements, out int pdwCount, out IntPtr ppBrowseElements)
 {
     OpcCom.Da.Wrapper.Server server;
     Monitor.Enter(server = this);
     try
     {
         ItemIdentifier itemID  = new ItemIdentifier(szItemID);
         BrowseFilters  filters = new BrowseFilters {
             MaxElementsReturned  = dwMaxElementsReturned,
             BrowseFilter         = OpcCom.Da.Interop.GetBrowseFilter(dwBrowseFilter),
             ElementNameFilter    = szElementNameFilter,
             VendorFilter         = szVendorFilter,
             ReturnAllProperties  = bReturnAllProperties != 0,
             ReturnPropertyValues = bReturnPropertyValues != 0,
             PropertyIDs          = OpcCom.Da.Interop.GetPropertyIDs(pdwPropertyIDs)
         };
         Opc.Da.BrowsePosition position = null;
         BrowseElement[]       input    = null;
         string key = null;
         if (pszContinuationPoint != IntPtr.Zero)
         {
             key = Marshal.PtrToStringUni(pszContinuationPoint);
         }
         if ((key == null) || (key.Length == 0))
         {
             input = this.m_server.Browse(itemID, filters, out position);
         }
         else
         {
             ContinuationPoint point = (ContinuationPoint)this.m_continuationPoints[key];
             if (point != null)
             {
                 position = point.Position;
                 this.m_continuationPoints.Remove(key);
             }
             if (position == null)
             {
                 throw new ExternalException("E_INVALIDCONTINUATIONPOINT", -1073478653);
             }
             Marshal.FreeCoTaskMem(pszContinuationPoint);
             pszContinuationPoint         = IntPtr.Zero;
             position.MaxElementsReturned = dwMaxElementsReturned;
             input = this.m_server.BrowseNext(ref position);
         }
         this.CleanupContinuationPoints();
         if (position != null)
         {
             key = Guid.NewGuid().ToString();
             this.m_continuationPoints[key] = new ContinuationPoint(position);
             pszContinuationPoint           = Marshal.StringToCoTaskMemUni(key);
         }
         if (pszContinuationPoint == IntPtr.Zero)
         {
             pszContinuationPoint = Marshal.StringToCoTaskMemUni(string.Empty);
         }
         pbMoreElements   = 0;
         pdwCount         = 0;
         ppBrowseElements = IntPtr.Zero;
         if (input != null)
         {
             pdwCount         = input.Length;
             ppBrowseElements = OpcCom.Da.Interop.GetBrowseElements(input, dwPropertyCount > 0);
         }
     }
     catch (Exception exception)
     {
         throw CreateException(exception);
     }
     finally
     {
         Monitor.Exit(server);
     }
 }
Пример #24
0
        //======================================================================
        // BrowseNext

        /// <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 BrowseElement[] BrowseNext(ref Opc.Da.BrowsePosition position)
        {
            lock (this)
            {
                if (m_server == null)
                {
                    throw new NotConnectedException();
                }

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

                OpcCom.Da.BrowsePosition pos = (OpcCom.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;

                ItemIdentifier itemID  = ((BrowsePosition)position).ItemID;
                BrowseFilters  filters = ((BrowsePosition)position).Filters;

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

                // invoke COM method.
                try
                {
                    ((IOPCBrowse)m_server).Browse(
                        (itemID != null && itemID.ItemName != null)?itemID.ItemName:"",
                        ref pContinuationPoint,
                        filters.MaxElementsReturned,
                        OpcCom.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,
                        OpcCom.Da.Interop.GetPropertyIDs(filters.PropertyIDs),
                        out moreElements,
                        out count,
                        out pElements);
                }
                catch (Exception e)
                {
                    throw OpcCom.Interop.CreateException("IOPCBrowse.BrowseNext", e);
                }

                // unmarshal results.
                BrowseElement[] elements = OpcCom.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);
            }
        }
Пример #25
0
 public ContinuationPoint(Opc.Da.BrowsePosition position)
 {
     this.Position = position;
 }
Пример #26
0
 public ContinuationPoint(Opc.Da.BrowsePosition position)
 {
     Timestamp = DateTime.UtcNow;
     Position  = position;
 }
Пример #27
0
        public void Browse(string szItemID, ref IntPtr pszContinuationPoint, int dwMaxElementsReturned, OPCBROWSEFILTER dwBrowseFilter, string szElementNameFilter, string szVendorFilter, int bReturnAllProperties, int bReturnPropertyValues, int dwPropertyCount, int[] pdwPropertyIDs, out int pbMoreElements, out int pdwCount, out IntPtr ppBrowseElements)
        {
            lock (this)
            {
                try
                {
                    ItemIdentifier itemID        = new ItemIdentifier(szItemID);
                    BrowseFilters  browseFilters = new BrowseFilters();
                    browseFilters.MaxElementsReturned  = dwMaxElementsReturned;
                    browseFilters.BrowseFilter         = Interop.GetBrowseFilter(dwBrowseFilter);
                    browseFilters.ElementNameFilter    = szElementNameFilter;
                    browseFilters.VendorFilter         = szVendorFilter;
                    browseFilters.ReturnAllProperties  = (bReturnAllProperties != 0);
                    browseFilters.ReturnPropertyValues = (bReturnPropertyValues != 0);
                    browseFilters.PropertyIDs          = Interop.GetPropertyIDs(pdwPropertyIDs);
                    Opc.Da.BrowsePosition position = null;
                    BrowseElement[]       array    = null;
                    string text = null;
                    if (pszContinuationPoint != IntPtr.Zero)
                    {
                        text = Marshal.PtrToStringUni(pszContinuationPoint);
                    }

                    if (text == null || text.Length == 0)
                    {
                        array = m_server.Browse(itemID, browseFilters, out position);
                    }
                    else
                    {
                        ContinuationPoint continuationPoint = (ContinuationPoint)m_continuationPoints[text];
                        if (continuationPoint != null)
                        {
                            position = continuationPoint.Position;
                            m_continuationPoints.Remove(text);
                        }

                        if (position == null)
                        {
                            throw new ExternalException("E_INVALIDCONTINUATIONPOINT", -1073478653);
                        }

                        Marshal.FreeCoTaskMem(pszContinuationPoint);
                        pszContinuationPoint         = IntPtr.Zero;
                        position.MaxElementsReturned = dwMaxElementsReturned;
                        array = m_server.BrowseNext(ref position);
                    }

                    CleanupContinuationPoints();
                    if (position != null)
                    {
                        text = Guid.NewGuid().ToString();
                        m_continuationPoints[text] = new ContinuationPoint(position);
                        pszContinuationPoint       = Marshal.StringToCoTaskMemUni(text);
                    }

                    if (pszContinuationPoint == IntPtr.Zero)
                    {
                        pszContinuationPoint = Marshal.StringToCoTaskMemUni(string.Empty);
                    }

                    pbMoreElements   = 0;
                    pdwCount         = 0;
                    ppBrowseElements = IntPtr.Zero;
                    if (array != null)
                    {
                        pdwCount         = array.Length;
                        ppBrowseElements = Interop.GetBrowseElements(array, dwPropertyCount > 0);
                    }
                }
                catch (Exception e)
                {
                    throw CreateException(e);
                }
            }
        }
Пример #28
0
        public void ChangeBrowsePosition(OPCBROWSEDIRECTION dwBrowseDirection, string szString)
        {
            lock (this)
            {
                try
                {
                    BrowseFilters browseFilters = new BrowseFilters();
                    browseFilters.MaxElementsReturned  = 0;
                    browseFilters.BrowseFilter         = browseFilter.all;
                    browseFilters.ElementNameFilter    = null;
                    browseFilters.VendorFilter         = null;
                    browseFilters.ReturnAllProperties  = false;
                    browseFilters.PropertyIDs          = null;
                    browseFilters.ReturnPropertyValues = false;
                    ItemIdentifier        itemIdentifier = null;
                    Opc.Da.BrowsePosition position       = null;
                    switch (dwBrowseDirection)
                    {
                    case OPCBROWSEDIRECTION.OPC_BROWSE_TO:
                    {
                        if (szString == null || szString.Length == 0)
                        {
                            m_browseStack.Clear();
                            break;
                        }

                        itemIdentifier = new ItemIdentifier(szString);
                        BrowseElement[] array = null;
                        try
                        {
                            array = m_server.Browse(itemIdentifier, browseFilters, out position);
                        }
                        catch (Exception)
                        {
                            throw CreateException(-2147024809);
                        }

                        if (array == null || array.Length == 0)
                        {
                            throw CreateException(-2147024809);
                        }

                        m_browseStack.Clear();
                        m_browseStack.Push(null);
                        m_browseStack.Push(itemIdentifier);
                        break;
                    }

                    case OPCBROWSEDIRECTION.OPC_BROWSE_DOWN:
                    {
                        if (szString == null || szString.Length == 0)
                        {
                            throw CreateException(-2147024809);
                        }

                        BrowseElement browseElement = FindChild(szString);
                        if (browseElement == null || !browseElement.HasChildren)
                        {
                            throw CreateException(-2147024809);
                        }

                        m_browseStack.Push(new ItemIdentifier(browseElement.ItemName));
                        break;
                    }

                    case OPCBROWSEDIRECTION.OPC_BROWSE_UP:
                        if (m_browseStack.Count == 0)
                        {
                            throw CreateException(-2147467259);
                        }

                        itemIdentifier = (ItemIdentifier)m_browseStack.Pop();
                        if (m_browseStack.Count > 0 && m_browseStack.Peek() == null)
                        {
                            BuildBrowseStack(itemIdentifier);
                        }

                        break;
                    }

                    if (position != null)
                    {
                        position.Dispose();
                        position = null;
                    }
                }
                catch (Exception e)
                {
                    throw CreateException(e);
                }
            }
        }
Пример #29
0
 public override BrowseElement[] Browse(ItemIdentifier itemID, BrowseFilters filters, out Opc.Da.BrowsePosition position)
 {
     if (filters == null)
     {
         throw new ArgumentNullException("filters");
     }
     position = null;
     lock (this)
     {
         if (base.m_server == null)
         {
             throw new NotConnectedException();
         }
         OpcCom.Da20.BrowsePosition position2 = null;
         ArrayList list = new ArrayList();
         if (filters.BrowseFilter != browseFilter.item)
         {
             BrowseElement[] c = this.GetElements(list.Count, itemID, filters, true, ref position2);
             if (c != null)
             {
                 list.AddRange(c);
             }
             position = position2;
             if (position != null)
             {
                 return((BrowseElement[])list.ToArray(typeof(BrowseElement)));
             }
         }
         if (filters.BrowseFilter != browseFilter.branch)
         {
             BrowseElement[] elementArray2 = this.GetElements(list.Count, itemID, filters, false, ref position2);
             if (elementArray2 != null)
             {
                 list.AddRange(elementArray2);
             }
             position = position2;
         }
         return((BrowseElement[])list.ToArray(typeof(BrowseElement)));
     }
 }