private void CleanupContinuationPoints() { ArrayList list = new ArrayList(); foreach (DictionaryEntry entry in this.m_continuationPoints) { try { ContinuationPoint point = entry.Value as ContinuationPoint; if ((DateTime.UtcNow.Ticks - point.Timestamp.Ticks) > 0x165a0bc00L) { list.Add(entry.Key); } } catch { list.Add(entry.Key); } } foreach (string str in list) { ContinuationPoint point2 = (ContinuationPoint)this.m_continuationPoints[str]; this.m_continuationPoints.Remove(str); point2.Position.Dispose(); } }
/// <summary> /// Checks if the node is in the view. /// </summary> protected override bool IsNodeInView(ServerSystemContext context, ContinuationPoint continuationPoint, NodeState node) { if (continuationPoint.View != null) { if (continuationPoint.View.ViewId == new NodeId(Quickstarts.Views.Views.Engineering, NamespaceIndex)) { // suppress operations properties. if (node != null && node.BrowseName.NamespaceIndex == NamespaceIndexes[2]) { return(false); } } if (continuationPoint.View.ViewId == new NodeId(Quickstarts.Views.Views.Operations, NamespaceIndex)) { // suppress engineering properties. if (node != null && node.BrowseName.NamespaceIndex == NamespaceIndexes[1]) { return(false); } } } return(true); }
/// <summary> /// Checks if the reference is in the view. /// </summary> protected override bool IsReferenceInView(ServerSystemContext context, ContinuationPoint continuationPoint, IReference reference) { if (continuationPoint.View != null) { // guard against absolute node ids. if (reference.TargetId.IsAbsolute) { return(true); } // find the node. NodeState node = FindPredefinedNode((NodeId)reference.TargetId, typeof(NodeState)); if (node != null) { return(IsNodeInView(context, continuationPoint, node)); } } return(true); }
/// <summary> /// Browses for the children of the specified item. /// </summary> /// <param name="session">The session.</param> /// <param name="itemId">The item id.</param> /// <param name="continuationPoint">The continuation point.</param> /// <param name="maxElementsReturned">The max elements returned.</param> /// <param name="elementFilter">The element filter.</param> /// <param name="nameFilter">The name filter.</param> /// <param name="revisedContinuationPoint">The revised continuation point.</param> /// <returns>The list of elements that meet the criteria.</returns> public List <ComDaBrowseElement> BrowseForElements( Session session, string itemId, string continuationPoint, int maxElementsReturned, int elementFilter, string nameFilter, out string revisedContinuationPoint) { TraceState("BrowseForElements", itemId, continuationPoint, maxElementsReturned, elementFilter, nameFilter); revisedContinuationPoint = String.Empty; // look up continuation point. ContinuationPoint cp = null; if (!String.IsNullOrEmpty(continuationPoint)) { if (!m_continuationPoints.TryGetValue(continuationPoint, out cp)) { throw ComUtils.CreateComException(ResultIds.E_INVALIDCONTINUATIONPOINT); } m_continuationPoints.Remove(continuationPoint); } // get the element queue. Queue <ComDaBrowseElement> elements = null; // get element from continuation point. if (cp != null) { elements = cp.Elements; } // get list from cache. else { elements = m_cache.BrowseForElements(session, itemId); // check if nothing found. if (elements == null) { throw ComUtils.CreateComException(ResultIds.E_UNKNOWNITEMID); } } // apply filters. List <ComDaBrowseElement> hits = new List <ComDaBrowseElement>(); while (elements.Count > 0) { ComDaBrowseElement hit = elements.Dequeue(); // apply name filter. if (!String.IsNullOrEmpty(nameFilter)) { if (!ComUtils.Match(hit.BrowseName, nameFilter, true)) { continue; } } // apply element filter if (elementFilter == (int)OpcRcw.Da.OPCBROWSEFILTER.OPC_BROWSE_FILTER_BRANCHES) { if (!hit.HasChildren) { continue; } } if (elementFilter == (int)OpcRcw.Da.OPCBROWSEFILTER.OPC_BROWSE_FILTER_ITEMS) { if (!hit.IsItem) { continue; } } // check max reached. if (maxElementsReturned > 0 && hits.Count == maxElementsReturned) { elements.Enqueue(hit); cp = new ContinuationPoint(); cp.Id = Guid.NewGuid().ToString(); cp.Elements = elements; m_continuationPoints.Add(cp.Id, cp); revisedContinuationPoint = cp.Id; break; } // add the result. hits.Add(hit); } // return results. return(hits); }
/// <summary> /// Browses for the children of the specified item. /// </summary> /// <param name="session">The session.</param> /// <param name="itemId">The item id.</param> /// <param name="continuationPoint">The continuation point.</param> /// <param name="maxElementsReturned">The max elements returned.</param> /// <param name="elementFilter">The element filter.</param> /// <param name="nameFilter">The name filter.</param> /// <param name="revisedContinuationPoint">The revised continuation point.</param> /// <returns>The list of elements that meet the criteria.</returns> public List<ComDaBrowseElement> BrowseForElements( Session session, string itemId, string continuationPoint, int maxElementsReturned, int elementFilter, string nameFilter, out string revisedContinuationPoint) { TraceState("BrowseForElements", itemId, continuationPoint, maxElementsReturned, elementFilter, nameFilter); revisedContinuationPoint = String.Empty; // look up continuation point. ContinuationPoint cp = null; if (!String.IsNullOrEmpty(continuationPoint)) { if (!m_continuationPoints.TryGetValue(continuationPoint, out cp)) { throw ComUtils.CreateComException(ResultIds.E_INVALIDCONTINUATIONPOINT); } m_continuationPoints.Remove(continuationPoint); } // get the element queue. Queue<ComDaBrowseElement> elements = null; // get element from continuation point. if (cp != null) { elements = cp.Elements; } // get list from cache. else { elements = m_cache.BrowseForElements(session, itemId); // check if nothing found. if (elements == null) { throw ComUtils.CreateComException(ResultIds.E_UNKNOWNITEMID); } } // apply filters. List<ComDaBrowseElement> hits = new List<ComDaBrowseElement>(); while (elements.Count > 0) { ComDaBrowseElement hit = elements.Dequeue(); // apply name filter. if (!String.IsNullOrEmpty(nameFilter)) { if (!ComUtils.Match(hit.BrowseName, nameFilter, true)) { continue; } } // apply element filter if (elementFilter == (int)OpcRcw.Da.OPCBROWSEFILTER.OPC_BROWSE_FILTER_BRANCHES) { if (!hit.HasChildren) { continue; } } if (elementFilter == (int)OpcRcw.Da.OPCBROWSEFILTER.OPC_BROWSE_FILTER_ITEMS) { if (!hit.IsItem) { continue; } } // check max reached. if (maxElementsReturned > 0 && hits.Count == maxElementsReturned) { elements.Enqueue(hit); cp = new ContinuationPoint(); cp.Id = Guid.NewGuid().ToString(); cp.Elements = elements; m_continuationPoints.Add(cp.Id, cp); revisedContinuationPoint = cp.Id; break; } // add the result. hits.Add(hit); } // return results. return hits; }
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); } }
/// <summary> /// Finds the references that meet the browse criteria. /// </summary> private IList<BrowseElement> Browse( NodeId startId, ref ContinuationPoint cp, int dwMaxElementsReturned, OPCBROWSEFILTER dwBrowseFilter, string szElementNameFilter) { IList<BrowseElement> filteredResults = new List<BrowseElement>(); IList<BrowseElement> unprocessedResults = new List<BrowseElement>(); byte[] continuationPoint = null; while (dwMaxElementsReturned == 0 || filteredResults.Count < dwMaxElementsReturned) { ReferenceDescriptionCollection currentBatch = null; if (cp == null) { currentBatch = Browse(startId, dwMaxElementsReturned, out continuationPoint); if (continuationPoint != null) { cp = new ContinuationPoint(); cp.LastCP = continuationPoint; cp.UnprocessedElements = null; } } else { if (cp.UnprocessedElements != null) { // add any unprocessed results from the previous call. for (int ii = 0; ii < cp.UnprocessedElements.Count; ii++) { if (dwMaxElementsReturned == 0 || filteredResults.Count < dwMaxElementsReturned) { filteredResults.Add(cp.UnprocessedElements[ii]); } else { unprocessedResults.Add(cp.UnprocessedElements[ii]); } } // check if all done. if (unprocessedResults.Count == 0 && cp.LastCP == null) { cp = null; break; } // check for max results. if (unprocessedResults.Count > 0) { cp = new ContinuationPoint(); cp.LastCP = null; cp.UnprocessedElements = unprocessedResults; break; } } // get the next batch. if (cp != null && cp.LastCP != null) { continuationPoint = cp.LastCP; currentBatch = BrowseNext(ref continuationPoint); if (continuationPoint != null) { cp = new ContinuationPoint(); cp.LastCP = continuationPoint; cp.UnprocessedElements = null; } } } // apply the filters. ApplyFilters( currentBatch, dwBrowseFilter, szElementNameFilter, dwMaxElementsReturned, filteredResults, unprocessedResults); // check if all done. if (unprocessedResults.Count == 0 && (cp == null || cp.LastCP == null)) { cp = null; break; } // check for max results. if (unprocessedResults.Count > 0) { cp = new ContinuationPoint(); cp.LastCP = continuationPoint; cp.UnprocessedElements = unprocessedResults; break; } } return filteredResults; }
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); } } }