/// <summary> /// Main Program /// </summary> /// <param name="args">command line arguments</param> public static void Main(string[] args) { Console.WriteLine("Mig Interface test APP"); var migService = new MigService(); // Load the configuration from systemconfig.xml file MigServiceConfiguration configuration; // Construct an instance of the XmlSerializer with the type // of object that is being deserialized. XmlSerializer mySerializer = new XmlSerializer(typeof(MigServiceConfiguration)); // To read the file, create a FileStream. FileStream myFileStream = new FileStream("systemconfig.xml", FileMode.Open); // Call the Deserialize method and cast to the object type. configuration = (MigServiceConfiguration)mySerializer.Deserialize(myFileStream); // Set the configuration and start MIG Service migService.Configuration = configuration; migService.StartService(); // Get a reference to the test interface var interfaceDomain = "HomeAutomation.TradfriInterface"; var migInterface = migService.GetInterface(interfaceDomain); migInterface.Connect(); Console.WriteLine("Get Modules"); var interfacemodules = migInterface.GetModules(); foreach (MIG.InterfaceModule mod in interfacemodules) { Console.WriteLine($"Module Address: {mod.Address} Module Type: {mod.ModuleType}"); if (mod.ModuleType.ToString() != "Dimmer") { ResponseText resp; resp = (ResponseText)migInterface.InterfaceControl(new MigInterfaceCommand(interfaceDomain + $"/{mod.Address}/Battery.Get")); Console.WriteLine(resp.ResponseValue); } // var response = migInterface.InterfaceControl(new MigInterfaceCommand(interfaceDomain + $"/{mod.Address}/Control.On")); // System.Threading.Thread.Sleep(1000); // response = migInterface.InterfaceControl(new MigInterfaceCommand(interfaceDomain + $"/{mod.Address}/Control.Colour/eaf6fb")); // System.Threading.Thread.Sleep(2000); // response = migInterface.InterfaceControl(new MigInterfaceCommand(interfaceDomain + $"/{mod.Address}/Control.Colour/ebb63e")); // System.Threading.Thread.Sleep(2000); // response = migInterface.InterfaceControl(new MigInterfaceCommand(interfaceDomain + $"/{mod.Address}/Control.Colour/f5faf6")); // System.Threading.Thread.Sleep(2000); // response = migInterface.InterfaceControl(new MigInterfaceCommand(interfaceDomain + $"/{mod.Address}/Control.Off")); } Console.WriteLine("\n[Press Enter to Quit]\n"); Console.ReadLine(); }
/// <summary> /// Main Program /// </summary> /// <param name="args">command line arguments</param> public static void Main(string[] args) { Console.WriteLine("Mig Interface Hikvision test APP"); var migService = new MigService(); // Load the configuration from systemconfig.xml file MigServiceConfiguration configuration; // Construct an instance of the XmlSerializer with the type // of object that is being deserialized. var mySerializer = new XmlSerializer(typeof(MigServiceConfiguration)); // To read the file, create a FileStream. var myFileStream = new FileStream("systemconfig.xml", FileMode.Open); // Call the Deserialize method and cast to the object type. configuration = (MigServiceConfiguration)mySerializer.Deserialize(myFileStream); // Set the configuration and start MIG Service migService.Configuration = configuration; migService.StartService(); // Get a reference to the test interface var interfaceDomain = "Hikvision.InterfaceHikvision"; var migInterface = migService.GetInterface(interfaceDomain); // Test an interface API command programmatically <module_domain>/<module_address>/<command>[/<option_0>[/../<option_n>]] var response = migInterface.InterfaceControl(new MigInterfaceCommand(interfaceDomain + "/3/Greet.Hello/Username")); // <module_domain> ::= "Hikvision.InterfaceHikvision" // <module_address> ::= "3" // <command> ::= "Greet.Hello" // <option_0> ::= "Username" // For more infos about MIG API see: // http://genielabs.github.io/HomeGenie-BE/api/mig/overview.html // http://genielabs.github.io/HomeGenie-BE/api/mig/mig_api_interfaces.html // The same command can be invoked though the WebGateway // http://<server_address>:8080/api/Hikvision.InterfaceHikvision/1/Greet.Hello/Username // Test some other interface API command response = migInterface.InterfaceControl(new MigInterfaceCommand(interfaceDomain + "/1/Control.On")); MigService.Log.Debug(response); response = migInterface.InterfaceControl(new MigInterfaceCommand(interfaceDomain + "/1/Control.Off")); MigService.Log.Debug(response); response = migInterface.InterfaceControl(new MigInterfaceCommand(interfaceDomain + "/2/Temperature.Get")); MigService.Log.Debug(response); Console.WriteLine("\n[Press Enter to Quit]\n"); Console.ReadLine(); }
public static void Main(string[] args) { var migService = new MigService(); // Construct an instance of the XmlSerializer with the type // of object that is being deserialized. var mySerializer = new XmlSerializer(typeof(MigServiceConfiguration)); // To read the file, create a FileStream. var myFileStream = new FileStream("systemconfig.xml", FileMode.Open); // Call the Deserialize method and cast to the object type. var configuration = (MigServiceConfiguration)mySerializer.Deserialize(myFileStream); // Load the configuration Set the configuration and start MIG Service migService.Configuration = configuration; migService.StartService(); Console.WriteLine("\n[Press Enter to Quit]\n"); Console.ReadLine(); }
public static void Main(string[] args) { string webPort = "8088"; Console.WriteLine("MigService test APP"); Console.WriteLine("URL: http://localhost:{0}", webPort); var migService = new MigService(); // Add and configure the Web gateway var web = migService.AddGateway("WebServiceGateway"); web.SetOption("HomePath", "html"); web.SetOption("BaseUrl", "/pages/"); web.SetOption("Host", "*"); web.SetOption("Port", webPort); web.SetOption("Password", ""); web.SetOption("EnableFileCaching", "False"); /* * // Add and configure the Web Socket gateway * var ws = migService.AddGateway("WebSocketGateway"); * ws.SetOption("Port", "8181"); */ migService.StartService(); // Enable UPnP interface var upnp = migService.AddInterface("Protocols.UPnP", "MIG.Protocols.dll"); migService.EnableInterface("Protocols.UPnP"); while (true) { Thread.Sleep(10000); } }
public static void Main(string[] args) { var migService = new MigService(); // Configuration can also be loaded from a file as shown below MigServiceConfiguration configuration; // Construct an instance of the XmlSerializer with the type // of object that is being deserialized. XmlSerializer mySerializer = new XmlSerializer(typeof(MigServiceConfiguration)); // To read the file, create a FileStream. FileStream myFileStream = new FileStream("systemconfig.xml", FileMode.Open); // Call the Deserialize method and cast to the object type. configuration = (MigServiceConfiguration)mySerializer.Deserialize(myFileStream); // Set the configuration migService.Configuration = configuration; migService.StartService(); // Enable some interfaces for testing... /* * var zwave = migService.AddInterface("HomeAutomation.ZWave", "MIG.HomeAutomation.dll"); * zwave.SetOption("Port", "/dev/ttyUSB0"); * migService.EnableInterface("HomeAutomation.ZWave"); */ /* * var x10 = migService.AddInterface("HomeAutomation.X10", "MIG.HomeAutomation.dll"); * zwave.SetOption("Port", "CM19"); // "USB" for CM15 or the serial port path for CM11 * migService.EnableInterface("HomeAutomation.X10"); */ while (true) { Thread.Sleep(10000); } }
public static void Main(string[] args) { string webPort = "8088"; Console.WriteLine("MigService test APP"); Console.WriteLine("URL: http://localhost:{0}", webPort); var migService = new MigService(); // Add and configure the Web gateway var web = migService.AddGateway("WebServiceGateway"); web.SetOption("HomePath", "html"); web.SetOption("BaseUrl", "/pages/"); web.SetOption("Host", "*"); web.SetOption("Port", webPort); web.SetOption("Password", ""); web.SetOption("EnableFileCaching", "False"); // Add and configure the Web Socket gateway var ws = migService.AddGateway("WebSocketGateway"); ws.SetOption("Port", "8181"); // Configuration can also be loaded from a file as shown below /* * MigServiceConfiguration configuration; * // Construct an instance of the XmlSerializer with the type * // of object that is being deserialized. * XmlSerializer mySerializer = new XmlSerializer(typeof(MigServiceConfiguration)); * // To read the file, create a FileStream. * FileStream myFileStream = new FileStream("systemconfig.xml", FileMode.Open); * // Call the Deserialize method and cast to the object type. * configuration = (MigServiceConfiguration)mySerializer.Deserialize(myFileStream); * // Set the configuration * migService.Configuration = configuration; */ migService.StartService(); // Enable some interfaces for testing... /* * var zwave = migService.AddInterface("HomeAutomation.ZWave", "MIG.HomeAutomation.dll"); * zwave.SetOption("Port", "/dev/ttyUSB0"); * migService.EnableInterface("HomeAutomation.ZWave"); */ /* * var upnp = migService.AddInterface("Protocols.UPnP", "MIG.Protocols.dll"); * migService.EnableInterface("Protocols.UPnP"); */ migService.RegisterApi("myapp/demo", (request) => { Console.WriteLine("Received API call from source {0}\n", request.Context.Source); Console.WriteLine("[Context data]\n{0}\n", MigService.JsonSerialize(request.Context.Data, true)); Console.WriteLine("[Mig Command]\n{0}\n", MigService.JsonSerialize(request.Command, true)); var cmd = request.Command; // cmd.Domain is the first element in the API URL (myapp) // cmd.Address is the second element in the API URL (demo) // cmd.Command is the third element in the API URL (greet | echo | ping) // cmd.GetOption(<n>) will give all the subsequent elements in the API URL (0...n) switch (cmd.Command) { case "greet": var name = cmd.GetOption(0); migService.RaiseEvent(typeof(MainClass), cmd.Domain, cmd.Address, "Reply to Greet", "Greet.User", name); break; case "echo": string fullRequestPath = cmd.OriginalRequest; migService.RaiseEvent(typeof(MainClass), cmd.Domain, cmd.Address, "Reply to Echo", "Echo.Data", fullRequestPath); break; case "ping": migService.RaiseEvent(typeof(MainClass), cmd.Domain, cmd.Address, "Reply to Ping", "Ping.Reply", "PONG"); break; } return(new ResponseStatus(Status.Ok)); }); while (true) { Thread.Sleep(10000); } }
public static void Main(string[] args) { string webPort = "8088"; Console.WriteLine("MigService test APP"); Console.WriteLine("URL: http://localhost:{0}", webPort); var migService = new MigService(); // Add and configure the Web gateway var web = migService.AddGateway("WebServiceGateway"); web.SetOption("HomePath", "html"); web.SetOption("BaseUrl", "/pages/"); web.SetOption("Host", "*"); web.SetOption("Port", webPort); web.SetOption("Password", ""); web.SetOption("EnableFileCaching", "False"); // Add and configure the Web Socket gateway var ws = migService.AddGateway("WebSocketGateway"); ws.SetOption("Port", "8181"); migService.StartService(); migService.RegisterApi("myapp/demo", (request) => { Console.WriteLine("Received API call from source {0}\n", request.Context.Source); Console.WriteLine("[Context data]\n{0}\n", MigService.JsonSerialize(request.Context.Data, true)); Console.WriteLine("[Mig Command]\n{0}\n", MigService.JsonSerialize(request.Command, true)); var cmd = request.Command; // cmd.Domain is the first element in the API URL (myapp) // cmd.Address is the second element in the API URL (demo) // cmd.Command is the third element in the API URL (greet | echo | ping) // cmd.GetOption(<n>) will give all the subsequent elements in the API URL (0...n) switch (cmd.Command) { case "greet": var name = cmd.GetOption(0); migService.RaiseEvent(typeof(MainClass), cmd.Domain, cmd.Address, "Reply to Greet", "Greet.User", name); break; case "echo": string fullRequestPath = cmd.OriginalRequest; migService.RaiseEvent(typeof(MainClass), cmd.Domain, cmd.Address, "Reply to Echo", "Echo.Data", fullRequestPath); break; case "ping": migService.RaiseEvent(typeof(MainClass), cmd.Domain, cmd.Address, "Reply to Ping", "Ping.Reply", "PONG"); break; } return(new ResponseStatus(Status.Ok)); }); while (true) { Thread.Sleep(10000); } }
public static void Main(string[] args) { var Log = MigService.Log; string webServicePort = "8088"; string webSocketPort = "8181"; string authUser = "******"; string authPass = "******"; string authRealm = "MIG Secure Zone"; Log.Info("MigService test APP"); Log.Info("URL: http://localhost:{0}", webServicePort); var migService = new MigService(); // Add and configure the WebService gateway var web = (WebServiceGateway)migService.AddGateway(Gateways.WebServiceGateway); web.SetOption(WebServiceGatewayOptions.HomePath, "html"); web.SetOption(WebServiceGatewayOptions.BaseUrl, "/pages/"); // for deploying modern web app (eg. Angular 2 apps) web.SetOption(WebServiceGatewayOptions.UrlAliasPrefix, "app/*:app/index.html"); web.SetOption(WebServiceGatewayOptions.Host, "*"); web.SetOption(WebServiceGatewayOptions.Port, webServicePort); if (!String.IsNullOrEmpty(authUser) && !String.IsNullOrEmpty(authPass)) { //web.SetOption(WebServiceGatewayOptions.Authentication, WebAuthenticationSchema.Basic); web.SetOption(WebServiceGatewayOptions.Authentication, WebAuthenticationSchema.Digest); web.SetOption(WebServiceGatewayOptions.AuthenticationRealm, authRealm); web.UserAuthenticationHandler += (sender, eventArgs) => { if (eventArgs.Username == authUser) { // WebServiceGateway requires password to be encrypted using the `Digest.CreatePassword(..)` method. // This applies both to 'Digest' and 'Basic' authentication methods. string password = Digest.CreatePassword(authUser, authRealm, authPass); return(new User(authUser, authRealm, password)); } return(null); }; } web.SetOption(WebServiceGatewayOptions.EnableFileCaching, "False"); // Add and configure the WebSocket gateway var ws = (WebSocketGateway)migService.AddGateway(Gateways.WebSocketGateway); ws.SetOption(WebSocketGatewayOptions.Port, webSocketPort); // WebSocketGateway access via authorization token ws.SetOption(WebSocketGatewayOptions.Authentication, WebAuthenticationSchema.Token); /* * if (!String.IsNullOrEmpty(authUser) && !String.IsNullOrEmpty(authPass)) * { * //ws.SetOption(WebSocketGatewayOptions.Authentication, WebAuthenticationSchema.Basic); * ws.SetOption(WebSocketGatewayOptions.Authentication, WebAuthenticationSchema.Digest); * ws.SetOption(WebSocketGatewayOptions.AuthenticationRealm, authRealm); * ((WebSocketGateway) ws).UserAuthenticationHandler += (sender, eventArgs) => * { * if (eventArgs.Username == authUser) * { * return new User(authUser, authRealm, authPass); * } * return null; * }; * } */ migService.StartService(); // API commands and events are exposed to all active gateways (WebService and WebSocket in this example) migService.RegisterApi("myapp/demo", (request) => { Log.Debug("Received API call over {0}\n", request.Context.Source); Log.Debug("[Context data]\n{0}\n", request.Context.Data); Log.Debug("[Mig Command]\n{0}\n", MigService.JsonSerialize(request.Command, true)); var cmd = request.Command; // cmd.Domain is the first element in the API URL (myapp) // cmd.Address is the second element in the API URL (demo) // cmd.Command is the third element in the API URL (greet | echo | ping) // cmd.GetOption(<n>) will give all the subsequent elements in the API URL (0...n) switch (cmd.Command) { case ApiCommands.Token: // authorization token will expire in 5 seconds var token = ws.GetAuthorizationToken(5); return(new ResponseText(token.Value)); case ApiCommands.Greet: var name = cmd.GetOption(0); migService.RaiseEvent( typeof(MainClass), cmd.Domain, cmd.Address, "Reply to Greet", "Greet.User", name ); break; case ApiCommands.Echo: string fullRequestPath = cmd.OriginalRequest; migService.RaiseEvent( typeof(MainClass), cmd.Domain, cmd.Address, "Reply to Echo", "Echo.Data", fullRequestPath ); break; case ApiCommands.Ping: migService.RaiseEvent( typeof(MainClass), cmd.Domain, cmd.Address, "Reply to Ping", "Ping.Reply", "PONG" ); break; } return(new ResponseStatus(Status.Ok)); }); while (true) { Thread.Sleep(5000); } }
static void Main(string[] args) { Console.WriteLine("Mig Interface Skelton test APP"); var migService = new MigService(); // Load the configuration from systemconfig.xml file MigServiceConfiguration configuration; // Construct an instance of the XmlSerializer with the type // of object that is being deserialized. XmlSerializer mySerializer = new XmlSerializer(typeof(MigServiceConfiguration)); // To read the file, create a FileStream. FileStream myFileStream = new FileStream("systemconfig.xml", FileMode.Open); // Call the Deserialize method and cast to the object type. configuration = (MigServiceConfiguration)mySerializer.Deserialize(myFileStream); // Set the configuration and start MIG Service migService.Configuration = configuration; migService.StartService(); // Get a reference to the test interface var interfaceDomain = "Knx.KnxInterface"; var migInterface = migService.GetInterface(interfaceDomain); migInterface.InterfacePropertyChanged += MigInterface_InterfacePropertyChanged; // Test an interface API command programmatically <module_domain>/<module_address>/<command>[/<option_0>[/../<option_n>]] // var response = migInterface.InterfaceControl(new MigInterfaceCommand(interfaceDomain + "/3/Greet.Hello/Username")); // MigService.Log.Debug(response); // <module_domain> ::= "Example.InterfaceSkelton" // <module_address> ::= "3" // <command> ::= "Greet.Hello" // <option_0> ::= "Username" // For more infos about MIG API see: // http://genielabs.github.io/HomeGenie/api/mig/overview.html // http://genielabs.github.io/HomeGenie/api/mig/mig_api_interfaces.html // The same command can be invoked though the WebGateway // http://<server_address>:8080/api/Example.InterfaceSkelton/1/Greet.Hello/Username // Test some other interface API command /* * var response = migInterface.InterfaceControl(new MigInterfaceCommand(interfaceDomain + "/1.0.0/Control.On")); * MigService.Log.Debug(response); * Thread.Sleep(3000); * response = migInterface.InterfaceControl(new MigInterfaceCommand(interfaceDomain + "/1.0.0/Control.Off")); * MigService.Log.Debug(response); */ //response = migInterface.InterfaceControl(new MigInterfaceCommand(interfaceDomain + "/2/Temperature.Get")); //MigService.Log.Debug(response); //Console.WriteLine("\n[Press Enter to Quit]\n"); Console.WriteLine("Test Commands : "); Console.WriteLine("Adress : Type : Command"); Console.WriteLine("Adress Example 1.0.0"); Console.WriteLine("Command On, Off, Up, Down"); Console.WriteLine("Exit for End"); while (true) { var value = Console.ReadLine(); if (value.ToLower().Equals("exit")) { break; } var parts = value.Split(':'); if (parts.Length == 2) { var address = parts[0].Trim(); var command = ""; switch (parts[1].Trim()) { case "On": command = "Control.On"; break; case "Up": command = "Dimmer.Up"; break; case "Down": command = "Dimmer.Down"; break; default: command = "Control.Off"; break; } var response = migInterface.InterfaceControl(new MigInterfaceCommand(interfaceDomain + "/" + address + "/" + command)); Console.WriteLine(((MIG.ResponseText)response).ResponseValue); MigService.Log.Debug(response); } else { Console.WriteLine("Wrong Command"); } } }