protected override PublishedNodesCollection GetPublishedNodesLegacy(string endpointUrl, CancellationToken ct)
        {
            string logPrefix = $"{_logClassPrefix}:GetPublishedNodesLegacy:";
            PublishedNodesCollection nodeList = null;

            VariantCollection inputArgumentsTestserver = new VariantCollection()
            {
                ""
            };

            try
            {
                CallMethodRequestCollection requests        = new CallMethodRequestCollection();
                CallMethodResultCollection  results         = new CallMethodResultCollection();
                DiagnosticInfoCollection    diagnosticInfos = null;
                CallMethodRequest           request         = new CallMethodRequest
                {
                    ObjectId = new NodeId("Methods", 2),
                    MethodId = new NodeId("GetPublishedNodes", 2),
                };
                request.InputArguments = inputArgumentsTestserver;
                requests.Add(request);
                try
                {
                    ResponseHeader responseHeader = _session.Call(null, requests, out results, out diagnosticInfos);
                }
                catch (Exception e)
                {
                    Logger.Fatal(e, $"{logPrefix} Exception");
                }
                if (StatusCode.IsBad(results[0].StatusCode))
                {
                    Logger.Warning($"{logPrefix} call was not successfull (status: '{results[0].StatusCode}'");
                }
                else
                {
                    if (results?[0]?.OutputArguments.Count == 1)
                    {
                        string stringResult   = results[0].OutputArguments[0].ToString();
                        int    jsonStartIndex = stringResult.IndexOf("[", StringComparison.InvariantCulture);
                        int    jsonEndIndex   = stringResult.LastIndexOf("]", StringComparison.InvariantCulture);
                        nodeList = JsonConvert.DeserializeObject <PublishedNodesCollection>(stringResult.Substring(jsonStartIndex, jsonEndIndex - jsonStartIndex + 1));
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Fatal(e, $"{logPrefix} Exception");
            }
            return(nodeList);
        }
예제 #2
0
        protected override PublishedNodesCollection GetPublishedNodesLegacy(string endpointUrl, CancellationToken ct)
        {
            List <OpcNodeOnEndpointModel> nodeList       = GetConfiguredNodesOnEndpoint(endpointUrl, ct);
            PublishedNodesCollection      publishedNodes = new PublishedNodesCollection();

            foreach (var node in nodeList)
            {
                NodeLookup nodeLookup = new NodeLookup();
                nodeLookup.EndPointURL = new Uri(endpointUrl);
                nodeLookup.NodeID      = new NodeId(node.Id);
                publishedNodes.Add(new NodeLookup());
            }
            return(publishedNodes);
        }
        protected override List <OpcNodeOnEndpointModel> GetConfiguredNodesOnEndpoint(string endpointUrl, CancellationToken ct)
        {
            string logPrefix = $"{_logClassPrefix}:GetConfiguredNodesOnEndpoint:";
            Random random    = new Random();
            List <OpcNodeOnEndpointModel> nodeList = new List <OpcNodeOnEndpointModel>();

            try
            {
                PublishedNodesCollection publishedNodes = GetPublishedNodesLegacy(endpointUrl, ct);

                foreach (var publishedNode in publishedNodes)
                {
                    OpcNodeOnEndpointModel node = new OpcNodeOnEndpointModel(publishedNode.NodeID.ToString());
                    nodeList.Add(node);
                }
            }
            catch (Exception e)
            {
                Logger.Fatal(e, $"{logPrefix} Exception");
            }
            return(nodeList);
        }