private uint GetMaxResults(BrowseFilter browseFilter) { var max = browseFilter != null ? (uint)browseFilter.maxResults : uint.MaxValue; if (max > 0) { return(max); } return(uint.MaxValue); }
private CallResourceResponse Browse(CallResourceRequest request, Session connection, NameValueCollection queryParams, NamespaceTable nsTable) { CallResourceResponse response = new CallResourceResponse(); string nodeId = HttpUtility.UrlDecode(queryParams["nodeId"]); var mask = queryParams["nodeClassMask"]; string filter = queryParams["browseFilter"]; BrowseFilter browseFilter = null; if (!string.IsNullOrEmpty(filter)) { browseFilter = JsonSerializer.Deserialize <BrowseFilter>(filter); } var hasMask = !string.IsNullOrWhiteSpace(mask); uint nodeClassMask = 0; if (hasMask) { if (!uint.TryParse(mask, out nodeClassMask)) { hasMask = false; } } var nId = Converter.GetNodeId(nodeId, nsTable); IEnumerable <ReferenceDescription> browseResult = connection.Browse(nId, hasMask ? nodeClassMask : (int)(NodeClass.Object | NodeClass.Variable), GetMaxResults(browseFilter)); if (!string.IsNullOrEmpty(browseFilter?.browseName)) { browseResult = browseResult.Where(a => a.BrowseName.Name.Contains(browseFilter.browseName)); } var result = JsonSerializer.Serialize(browseResult.Select(a => Converter.ConvertToBrowseResult(a, nsTable)).OrderBy(refdesc => refdesc.displayName).ToArray()); response.Code = 200; response.Body = ByteString.CopyFrom(result, Encoding.ASCII); _log.LogDebug("We got a result from browse => {0}", result); return(response); }