public OPCNamespaceType QueryOrganization() { OPCNamespaceType l_NamespaceType; m_IfBrowse.QueryOrganization(out l_NamespaceType); return(l_NamespaceType); }
void ImportOPCChannels(IOPCBrowseServerAddressSpace srv, TreeNodeCollection root) { OPCNAMESPACETYPE nsType; srv.QueryOrganization(out nsType); OpcRcw.Da.IEnumString es; if (nsType == OPCNAMESPACETYPE.OPC_NS_HIERARCHIAL) { try{ srv.BrowseOPCItemIDs(OPCBROWSETYPE.OPC_BRANCH, "", 0, 0, out es); } catch (COMException) { return; } int fetched; do { string[] tmp = new string[100]; es.RemoteNext(tmp.Length, tmp, out fetched); for (int i = 0; i < fetched; i++) { try{ srv.ChangeBrowsePosition(OPCBROWSEDIRECTION.OPC_BROWSE_DOWN, tmp[i]); } catch (Exception e) { Env.Current.Logger.LogWarning(string.Format("OPC server failed to handle OPC_BROWSE_DOWN request for item '{0}' ({1})", tmp[i], e.Message)); continue; }; TreeNode node = root.Add(tmp[i]); ImportOPCChannels(srv, node.Nodes); try { srv.ChangeBrowsePosition(OPCBROWSEDIRECTION.OPC_BROWSE_UP, ""); } catch (Exception e) { Env.Current.Logger.LogWarning(string.Format("OPC server failed to handle OPC_BROWSE_UP request for item '{0}' ({1})", tmp[i], e.Message)); continue; }; } } while(fetched > 0); try{ srv.BrowseOPCItemIDs(OPCBROWSETYPE.OPC_LEAF, "", 0, 0, out es); } catch (COMException) { return; } IterateOPCItems(srv, root, es); } else if (nsType == OPCNAMESPACETYPE.OPC_NS_FLAT) { try { srv.BrowseOPCItemIDs(OPCBROWSETYPE.OPC_FLAT, "", 0, 0, out es); } catch (COMException) { return; } IterateOPCItems(srv, root, es); } es = null; }
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))); }
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))); }