static void ProcessRequest(string server, string credential, string serverPath) { if (string.IsNullOrEmpty(server) && string.IsNullOrEmpty(serverPath)) { Console.WriteLine("Missing command path"); return; } string path = serverPath; if (!string.IsNullOrEmpty(serverPath) && string.IsNullOrEmpty(server)) { // path format is "192.168.0.10:8000/p1/p2/p3" string[] parts = serverPath.Split(SlashDelimiter, 2); server = parts[0]; if (parts.Length > 1) { path = parts[1]; } else { path = null; } } if (string.IsNullOrEmpty(path)) { Discover(server, credential); return; } // create client factories PiClientFactory pi = new PiClientFactory(); SmartPlugClientFactory plug = new SmartPlugClientFactory(); // discover server endpoints and create client nodes IotClientNode rootNode = IotClientFactory.Discover(server, credential); if (rootNode?.Children.Count <= 0) { Console.WriteLine($"Server {server} does not support REST IOT."); return; } HttpResponse response = rootNode.GetResponse(path); if (response.Success) { LogUtil.WritePassed("Server {0} response for endpoint {1}:\n{2}", server, path, response.Result); } else { Console.WriteLine("Error from Server {0} response for endpoint {1}:\n{2}\n{3}", server, path, response.Result, response.ErrorMessage); } }
static void TestNode(IotClientNode node) { LogUtil.WriteAction($"==== Test: {node.FullPath}"); HttpResponse response = node.GetResponse(); if (response.Success) { LogUtil.WritePassed("Server response:\n{0}", response.Result); } else { LogUtil.WriteFailed("Error response:\n{0}\n{1}", response.Result, response.ErrorMessage); } foreach (IotClientNode child in node.Children) { TestNode(child); } }