Ejemplo n.º 1
0
Archivo: opc.cs Proyecto: fr830/KepView
        // GET api/<controller>
        // GET api/<controller>/5
        public object Get([FromUri] string[] path, string query = null)
        {
            var server = ConfigurationManager.AppSettings["opc-server"];

            using (var client = new EasyUAClient())
            {
                UANodeElementCollection nodes = new UANodeElementCollection();
                path = path.Where(p => p != null).ToArray();             //.FirstOrDefault()?.Split('/');

                var nodePath = new List <UANodeElement>();
                if (!path.Any())
                {
                    nodes = client.BrowseObjects(server);
                }
                else
                {
                    nodePath = GetNode(server, client, path, null).ToList();
                    if (!nodePath.Any())
                    {
                        return(null);
                    }
                    nodes = client.BrowseVariables(server, nodePath.Last());
                }


                return(new { path = path.Select((p, i) => new {
                        browseName = p,
                        node = NodeReturn(nodePath.ElementAtOrDefault(i))
                    }),
                             children = nodes.Select(NodeReturn) });
            }
        }
Ejemplo n.º 2
0
Archivo: opc.cs Proyecto: fr830/KepView
        static IEnumerable <UANodeElement> GetNode(string server, EasyUAClient client, IEnumerable <string> path, IEnumerable <UANodeElement> currentNodes)
        {
            var _currentNodes = currentNodes ?? new List <UANodeElement>();

            if (!path.Any())
            {
                return(currentNodes);
            }
            UANodeElementCollection nodes = new UANodeElementCollection();

            if (!_currentNodes.Any())
            {
                nodes = client.BrowseObjects(server);
            }
            else
            {
                nodes = client.BrowseVariables(server, currentNodes.Last());
            }
            var node = nodes.SingleOrDefault(n => n.BrowseName.Name == path.First());

            if (node != null)
            {
                return(GetNode(server, client, path.Skip(1), _currentNodes.Concat(new List <UANodeElement> {
                    node
                })));
            }
            return(new List <UANodeElement>());
        }