/// <summary> /// Initial point of the program. /// </summary> /// <param name="args">Arguments.</param> public static void Main(string[] args) { Init(); // Write the header. Console.WriteLine( @"ABB DECRC - SERVICE and usability LAB Advanced Identification and Labeling for Service DECRC 2011 KIT, TecO 2011 DPWS Discovery Project, Contact N. L. Fantana ([email protected]) * Please, start a gateway before select the options. Additionally when using manual discovery the node must be running "); // Go always into the menu, until the user selects to exit. while (true) { int index = 3; // Check the option. Console.WriteLine("-----------------"); Console.WriteLine("1. Wait for Announcement"); Console.WriteLine("2. Discover services"); Console.WriteLine("-----------------"); Console.WriteLine("Discovered devices:"); foreach (edu.teco.DPWS.Device device in knownDevices) { Console.WriteLine("{0}. Type {1} {2}:{3} at {4}", index, device.GetType().Name, device.GetDeviceType().Namespace, device.GetDeviceType().Name, device.EndpointAddress); index++; } Console.WriteLine("-----------------"); Console.WriteLine("0. Exit"); Console.WriteLine("-----------------"); Console.WriteLine(); string line = Console.ReadLine(); if (line.Equals("1")) { StartAnnouncementProcess(); } else if (line.Equals("2")) { StartDiscoveryProcess(); } else if (line.Equals("0")) { return; } else { // Switch to Device menu int selection = 0; if (int.TryParse(line, out selection) && selection > 2 && selection <= knownDevices.Count + 2) { bool done = false; Console.WriteLine(); edu.teco.DPWS.Device device = knownDevices[selection - 3]; while (!done) { Console.WriteLine("-----------------"); Console.WriteLine("Current device: {0} {1}:{2} at {3}", device.GetType().Name, device.GetDeviceType().Namespace, device.GetDeviceType().Name, device.EndpointAddress); Console.WriteLine("-----------------"); Console.WriteLine("Services:"); index = 1; foreach (edu.teco.DPWS.Service service in device.GetServices()) { Console.WriteLine("Service name: {0}", service.GetType().Name); Console.WriteLine("Invokable methods:"); foreach (MethodInfo method in service.GetInvokableMethods()) { Object[] subAttributes = method.GetCustomAttributes(typeof(edu.teco.DPWS.DPWSInvokeMethod), true); if (subAttributes.Length < 1) { continue; } Console.WriteLine("{0}. {1}", index, ((edu.teco.DPWS.DPWSInvokeMethod)subAttributes[0]).Description); index++; } Console.WriteLine("Subscribable methods:"); foreach (MethodInfo method in service.GetSubscribableMethods()) { Object[] subAttributes = method.GetCustomAttributes(typeof(edu.teco.DPWS.DPWSSubscription), true); if (subAttributes.Length < 1) { continue; } Console.WriteLine("{0}. {1}", index, ((edu.teco.DPWS.DPWSSubscription)subAttributes[0]).Description); index++; } Console.WriteLine(); } Console.WriteLine("-----------------"); Console.WriteLine("0. Return"); string deviceLine = Console.ReadLine(); if (deviceLine.Equals("0")) { done = true; } else { int serviceSelection = 0; if (int.TryParse(deviceLine, out serviceSelection) && serviceSelection > 0 && serviceSelection < index) { foreach (edu.teco.DPWS.Service service in device.GetServices()) { foreach (MethodInfo method in service.GetInvokableMethods()) { serviceSelection--; if (serviceSelection == 0) { service.InvokeMethod(method); break; } } if (serviceSelection == 0) { break; } foreach (MethodInfo method in service.GetSubscribableMethods()) { serviceSelection--; if (serviceSelection == 0) { service.SubscribeMethod(method); } } if (serviceSelection == 0) { break; } } } else { Console.WriteLine("Invalid input"); } } } } else { Console.WriteLine("Invalid input"); } } } }