/// <summary> /// constructor /// </summary> public DiscoverService(string serverAndPort, string credential) { // discover server endpoints and create client nodes IotClientNode rootNode = IotClientFactory.Discover(serverAndPort, credential); BuildNodeDictionary(rootNode, _nodeDictionary); }
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 TestAllEndpoints(string server, string credential) { // 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; } foreach (IotClientNode node in rootNode.Children) { TestNode(node); } }