Ejemplo n.º 1
0
        private ArrayList FetchElements(EnumString enumerator, int maxElements, bool isBranch)
        {
            ArrayList list = new ArrayList();

            while (list.Count < maxElements)
            {
                int count = 10;
                if ((list.Count + count) > maxElements)
                {
                    count = maxElements - list.Count;
                }
                string[] strArray = enumerator.Next(count);
                if ((strArray == null) || (strArray.Length == 0))
                {
                    break;
                }
                foreach (string str in strArray)
                {
                    BrowseElement element = new BrowseElement {
                        Name = str
                    };
                    try
                    {
                        string pszItemID = null;
                        this.m_browser.GetItemID(str, out pszItemID);
                        element.ItemName    = pszItemID;
                        element.ItemPath    = null;
                        element.HasChildren = isBranch;
                    }
                    catch
                    {
                    }
                    list.Add(element);
                }
            }
            IdentifiedResult[] resultArray = this.m_server.ValidateItems((ItemIdentifier[])list.ToArray(typeof(ItemIdentifier)));
            if (resultArray != null)
            {
                for (int i = 0; i < resultArray.Length; i++)
                {
                    if (resultArray[i].ResultID.Succeeded())
                    {
                        ((BrowseElement)list[i]).IsItem = true;
                    }
                }
            }
            return(list);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Fetches the element names and item ids for each element.
        /// </summary>
        private ArrayList FetchElements(EnumString enumerator, int maxElements, bool isBranch)
        {
            ArrayList elements = new ArrayList();

            while (elements.Count < maxElements)
            {
                // fetch next batch of element names.
                int count = BLOCK_SIZE;

                if (elements.Count + count > maxElements)
                {
                    count = maxElements - elements.Count;
                }

                string[] names = null;
                names = enumerator.Next(count);

                // check if no more elements found.
                if (names == null || names.Length == 0)
                {
                    break;
                }

                // create new element objects.
                foreach (string name in names)
                {
                    TsCHdaBrowseElement element = new TsCHdaBrowseElement();

                    element.Name = name;
                    // lookup item id for element.
                    try
                    {
                        string itemID = null;
                        m_browser.GetItemID(name, out itemID);

                        element.ItemName    = itemID;
                        element.ItemPath    = null;
                        element.HasChildren = isBranch;
                    }
                    catch
                    {
                        // ignore errors.
                    }

                    elements.Add(element);
                }
            }

            // validate items - this is necessary to set the IsItem flag correctly.
            OpcItemResult[] results = m_server.ValidateItems((OpcItem[])elements.ToArray(typeof(OpcItem)));

            if (results != null)
            {
                for (int ii = 0; ii < results.Length; ii++)
                {
                    if (results[ii].Result.Succeeded())
                    {
                        ((TsCHdaBrowseElement)elements[ii]).IsItem = true;
                    }
                }
            }

            // return results.
            return(elements);
        }
Ejemplo n.º 3
0
        private BrowseElement[] GetElements(int elementsFound, ItemIdentifier itemID, BrowseFilters filters, bool branches, ref OpcCom.Da20.BrowsePosition position)
        {
            EnumString enumerator = null;

            if (position == null)
            {
                IOPCBrowseServerAddressSpace server         = (IOPCBrowseServerAddressSpace)base.m_server;
                OPCNAMESPACETYPE             pNameSpaceType = OPCNAMESPACETYPE.OPC_NS_HIERARCHIAL;
                try
                {
                    server.QueryOrganization(out pNameSpaceType);
                }
                catch (Exception exception)
                {
                    throw OpcCom.Interop.CreateException("IOPCBrowseServerAddressSpace.QueryOrganization", exception);
                }
                if ((pNameSpaceType == OPCNAMESPACETYPE.OPC_NS_FLAT) && branches)
                {
                    return(new BrowseElement[0]);
                }
                enumerator = this.GetEnumerator((itemID != null) ? itemID.ItemName : null, filters, branches);
            }
            else
            {
                enumerator = position.Enumerator;
            }
            ArrayList     list    = new ArrayList();
            BrowseElement element = null;
            int           index   = 0;

            string[] names = null;
            if (position != null)
            {
                index    = position.Index;
                names    = position.Names;
                position = null;
            }
Label_0089:
            if (names != null)
            {
                for (int i = index; i < names.Length; i++)
                {
                    if ((filters.MaxElementsReturned != 0) && (filters.MaxElementsReturned == (list.Count + elementsFound)))
                    {
                        position       = new OpcCom.Da20.BrowsePosition(itemID, filters, enumerator, branches);
                        position.Names = names;
                        position.Index = i;
                        break;
                    }
                    element = this.GetElement(names[i], filters, branches);
                    if (element == null)
                    {
                        break;
                    }
                    list.Add(element);
                }
            }
            if (position == null)
            {
                names = enumerator.Next(10);
                index = 0;
                if ((names != null) && (names.Length > 0))
                {
                    goto Label_0089;
                }
            }
            if (position == null)
            {
                enumerator.Dispose();
            }
            return((BrowseElement[])list.ToArray(typeof(BrowseElement)));
        }
Ejemplo n.º 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)));
        }
Ejemplo n.º 5
0
        private ArrayList FetchElements(EnumString enumerator, int maxElements, bool isBranch)
        {
            ArrayList arrayList = new ArrayList();

            while (arrayList.Count < maxElements)
            {
                int num = 10;
                if (arrayList.Count + num > maxElements)
                {
                    num = maxElements - arrayList.Count;
                }

                string[] array = enumerator.Next(num);
                if (array == null || array.Length == 0)
                {
                    break;
                }

                string[] array2 = array;
                foreach (string text in array2)
                {
                    BrowseElement browseElement = new BrowseElement();
                    browseElement.Name        = text;
                    browseElement.ItemPath    = null;
                    browseElement.HasChildren = isBranch;
                    string pszItemID = null;
                    try
                    {
                        if (isBranch)
                        {
                            pszItemID = GetFullBranchName(text);
                        }
                        else
                        {
                            m_browser.GetItemID(text, out pszItemID);
                        }
                    }
                    catch
                    {
                        pszItemID = null;
                    }

                    browseElement.ItemName = pszItemID;
                    arrayList.Add(browseElement);
                }
            }

            IdentifiedResult[] array3 = m_server.ValidateItems((ItemIdentifier[])arrayList.ToArray(typeof(ItemIdentifier)));
            if (array3 != null)
            {
                for (int j = 0; j < array3.Length; j++)
                {
                    if (array3[j].ResultID.Succeeded())
                    {
                        ((BrowseElement)arrayList[j]).IsItem = true;
                    }
                }
            }

            return(arrayList);
        }