Пример #1
0
        public override object Clone()
        {
            BrowsePosition browsePosition = (BrowsePosition)MemberwiseClone();

            browsePosition.Enumerator = Enumerator.Clone();
            return(browsePosition);
        }
Пример #2
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)));
            }
        }
Пример #3
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)));
            }
        }
Пример #4
0
        private BrowseElement[] GetElements(int elementsFound, ItemIdentifier itemID, BrowseFilters filters, bool branches, ref BrowsePosition position)
        {
            EnumString enumString = null;

            if (position == null)
            {
                IOPCBrowseServerAddressSpace iOPCBrowseServerAddressSpace = (IOPCBrowseServerAddressSpace)m_server;
                OPCNAMESPACETYPE             pNameSpaceType = OPCNAMESPACETYPE.OPC_NS_HIERARCHIAL;
                try
                {
                    iOPCBrowseServerAddressSpace.QueryOrganization(out pNameSpaceType);
                }
                catch (Exception e)
                {
                    throw Interop.CreateException("IOPCBrowseServerAddressSpace.QueryOrganization", e);
                }

                if (pNameSpaceType == OPCNAMESPACETYPE.OPC_NS_FLAT)
                {
                    if (branches)
                    {
                        return(new BrowseElement[0]);
                    }

                    if (itemID != null && itemID.ItemName != null && itemID.ItemName.Length > 0)
                    {
                        throw new ResultIDException(ResultID.Da.E_UNKNOWN_ITEM_NAME);
                    }
                }

                enumString = GetEnumerator(itemID?.ItemName, filters, branches, pNameSpaceType == OPCNAMESPACETYPE.OPC_NS_FLAT);
            }
            else
            {
                enumString = position.Enumerator;
            }

            ArrayList     arrayList     = new ArrayList();
            BrowseElement browseElement = null;
            int           num           = 0;

            string[] array = null;
            if (position != null)
            {
                num      = position.Index;
                array    = position.Names;
                position = null;
            }

            do
            {
                if (array != null)
                {
                    for (int i = num; i < array.Length; i++)
                    {
                        if (filters.MaxElementsReturned != 0 && filters.MaxElementsReturned == arrayList.Count + elementsFound)
                        {
                            position       = new BrowsePosition(itemID, filters, enumString, branches);
                            position.Names = array;
                            position.Index = i;
                            break;
                        }

                        browseElement = GetElement(itemID, array[i], filters, branches);
                        if (browseElement == null)
                        {
                            break;
                        }

                        arrayList.Add(browseElement);
                    }
                }

                if (position != null)
                {
                    break;
                }

                array = enumString.Next(10);
                num   = 0;
            }while (array != null && array.Length > 0);
            if (position == null)
            {
                enumString.Dispose();
            }

            return((BrowseElement[])arrayList.ToArray(typeof(BrowseElement)));
        }