{"id":20669717,"url":"https://github.com/genielabs/mig-service-dotnet","last_synced_at":"2025-08-01T23:04:44.827Z","repository":{"id":65067494,"uuid":"41694958","full_name":"genielabs/mig-service-dotnet","owner":"genielabs","description":"MIG is a .Net library providing an integrated solution for developing networked applications and real time web applications","archived":false,"fork":false,"pushed_at":"2025-02-20T19:38:56.000Z","size":1215,"stargazers_count":16,"open_issues_count":0,"forks_count":18,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-20T03:20:52.963Z","etag":null,"topics":["api","api-gateway","gateway","http-server","mig","networked","real-time","rtc","sse","web","websockets"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/genielabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-08-31T19:08:29.000Z","updated_at":"2025-02-25T01:58:04.000Z","dependencies_parsed_at":"2025-04-19T18:13:11.837Z","dependency_job_id":"b540e63a-35d6-4444-bc56-07ab6c0de55a","html_url":"https://github.com/genielabs/mig-service-dotnet","commit_stats":null,"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"purl":"pkg:github/genielabs/mig-service-dotnet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/genielabs%2Fmig-service-dotnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/genielabs%2Fmig-service-dotnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/genielabs%2Fmig-service-dotnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/genielabs%2Fmig-service-dotnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/genielabs","download_url":"https://codeload.github.com/genielabs/mig-service-dotnet/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/genielabs%2Fmig-service-dotnet/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268310611,"owners_count":24230180,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","api-gateway","gateway","http-server","mig","networked","real-time","rtc","sse","web","websockets"],"created_at":"2024-11-16T20:15:48.929Z","updated_at":"2025-08-01T23:04:44.772Z","avatar_url":"https://github.com/genielabs.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build status](https://ci.appveyor.com/api/projects/status/6genehqw9wtuuxkl?svg=true)](https://ci.appveyor.com/project/genemars/mig-service-dotnet)\n[![NuGet](https://img.shields.io/nuget/v/MIG.svg)](https://www.nuget.org/packages/MIG/)\n![License](https://img.shields.io/github/license/genielabs/mig-service-dotnet.svg)\n\n# MIG libray for .Net/Mono\n\nMIG is a .Net library providing an integrated solution for developing networked applications\nand real time web applications.\n\n## How it works\n\nWe have two main actors in MIG: **Gateway** and **Interface**.\n\nA *Gateway* is the medium used for receiving API commands from the client and for transmitting\nresponses and events back to it.\n\nAn *Interface* is where all API commands are defined and related actions take place.\n\nSo, when writing an application based on MIG, the developer will just focus on the *API* coding.\n\nOnce the API commands are implemented, the application is ready to communicate with its clients\nthrough the desired **Gateway** medium. This can be a raw TCP socket server *(TcpSocketGateway)*,\nan HTTP server *(WebServiceGateway)*, a WebSocket server *(WebSocketGateway)*, a MQTT server\n*(MqttServiceGateway)* or even **ALL** of them at the same time, so to have a multi-protocol\nsupport for the application.\n\nExample code:\n```csharp\nvar migService = new MigService();\n\n// Add Web Server gateway\nvar webServiceGw = migService.AddGateway(Gateways.WebServiceGateway);\n\n// Add Web Socket gateway\nvar webSocketGw = migService.AddGateway(Gateways.WebSocketGateway);\n\n// Define an API handler for myapp/demo/greet command\nmigService.RegisterApi(\"myapp/demo/greet\", (request)=\u003e{\n    // we registered an handler for\n    // myapp/demo/greet/\u003coption_0\u003e[/\u003coption_1\u003e/../\u003coption_n\u003e]\n    var name = request.Command.GetOption(0);\n    // raise an event in the form\n    // \u003cdomain\u003e, \u003csource\u003e, \u003cdescription\u003e, \u003cproperty\u003e, \u003cvalue\u003e\n    migService.RaiseEvent(\"myapp\", \"demo\", \"Reply to greet\", \"Greet.User\", name);\n    // return the response (objects are automatically serialized to JSON)\n    return new ResponseStatus(Status.Ok);\n});\n\n// OR we can define a generic API handler for any request starting with myapp/....\nmigService.RegisterApi(\"myapp\", (request)=\u003e{\n    // we registered an handler for\n    // myapp/\u003cmodule_address\u003e/\u003ccommand\u003e/\u003coption_0\u003e[/\u003coption_1\u003e/../\u003coption_n\u003e]\n\n    var cmd = request.Command;\n    switch(cmd.Address)\n    {\n    case \"demo\":\n        // myapp/demo/....\n        switch (cmd.Command)\n        {\n        case \"greet\":\n            // myapp/demo/greet/....\n            // ....\n            break;\n        case \"ping\":\n            // myapp/demo/ping/....\n            // ...\n            break;\n        }\n        break;\n    case \"configure\":\n        // myapp/configure/....\n        // ...\n        break;\n    }\n\n    // return the response (objects are automatically serialized to JSON)\n    return new ResponseStatus(Status.Ok);\n});\n```\nIn the above example we defined an handler for the API command *myapp/demo/greet*.\nThis command can be issued from the web browser by either using a standard HTTP call\n```\n// HTTP service API commands have to be issued using the /api/ prefix\n$.get('http://localhost/api/myapp/demo/greet/Foo+Bar', function(res) { ... });\n```\nor by using the websocket client connection\n```\nwsclient.send('myapp/demo/greet/Foo Bar');\n```\n\n## Gateways\n\nEach gateway can be configured by using the *SetOption* method.\n\n### WebServiceGateway\n\nFeatures\n\n- HTTP server with built-in support for SSE (Server Sent Events) stream (url **/events**)\n- Digest/Basic Authentication\n- Automatic Markdown files to HTML translation\n- File caching\n\nOption List\n\n- BaseUrl (base url for HTML files)\n- HomePath (folder where to get HTML files from)\n- Host (host name or IP - use `*` for any)\n- Port (TCP port, default: *`80`*)\n- Authentication (`None`, `Digest` or `Basic`, default: `None`)\n- AuthenticationRealm (The authentication realm, default: `MIG Secure Zone`)\n- EnableFileCaching (*`True`* or *`False`*, default: *`False`*)\n- corsAllowOrigin (default: *`*`*)\n\nExample\n```csharp\nvar web = migService.AddGateway(Gateways.WebServiceGateway);\n// HTML files folder \nweb.SetOption(WebServiceGatewayOptions.HomePath, \"html\");\n// base URL for html files\nweb.SetOption(WebServiceGatewayOptions.BaseUrl, \"/pages/\"); \n// listen on any address\nweb.SetOption(WebServiceGatewayOptions.Host, \"*\"); \n// TCP port\nweb.SetOption(WebServiceGatewayOptions.Port, \"8080\");\n// enable authentication\nweb.SetOption(WebServiceGatewayOptions.Authentication, \"Digest\"); \n// disable file caching\nweb.SetOption(WebServiceGatewayOptions.EnableFileCaching, \"False\"); \n// disable CORS\nweb.SetOption(WebServiceGatewayOptions.CorsAllowOrigin, \"\"); \n// add a url alias (`path/to/myfile.jpg` will serve `real/path/file.jpg`)\nweb.SetOption(WebServiceGatewayOptions.UrlAliasPrefix, \"path/to/myfile.jpg:real/path/file.jpg\");\n// add web-app folder (used for deploying SPA and PWA such as Angular2 apps)\n// all requested files non found in `app/` will be redirected to `app/index.html`\nweb.SetOption(WebServiceGatewayOptions.UrlAliasPrefix, \"app/*:app/index.html\");\n```\n\n#### User authentication with `Digest` or `Basic` methods\n\n```\nstring authReam = \"My App Realm\";\nweb.SetOption(WebServiceGatewayOptions.Authentication, WebAuthenticationSchema.Digest);\nweb.SetOption(WebServiceGatewayOptions.AuthenticationRealm, authRealm);\nweb.UserAuthenticationHandler += (sender, eventArgs) =\u003e\n{\n    // lookup 'eventArgs.Username' in your database\n    var user = GetUser(eventArgs.Username);\n    if (user != null)\n    {\n        // WebServiceGateway requires password to be encrypted using the `Digest.CreatePassword(..)` method.\n        // This applies both to 'Digest' and 'Basic' authentication methods.\n        // So if 'user.Password' is stored in clear (not recommended) it must be encrypted\n        string encryptedPassword = Digest.CreatePassword(user.Username, authRealm, user.Password);\n        // if 'user.Password' is already encrypted the previous line can be removed\n        return new User(user.Username, authRealm, encryptedPassword);\n    }\n    return null;\n};\n```\n\n### WebSocketGateway\n\nOptions\n\n- Port (TCP port to listen on)\n- Authentication (`None`, `Token`, `Digest` or `Basic`, default: `None`)\n- AuthenticationRealm (The authentication realm, default: `MIG Secure Zone`)\n\nExample\n```csharp\nvar ws = migService.AddGateway(Gateways.WebSocketGateway);\nws.SetOption(WebSocketGatewayOptions.Port, \"8181\");\n```\n\n#### Authentication using Token\n\nWhen `Authentication` option is set to `Token`, the websocket service will require the client\nto connect by providing an authentication token in the url query-string as the `at` parameter.\n\nThe authorization token is obtained by calling the following method\n\n```\ndouble expireSeconds = 5; // 5 seconds validity\nvar token = ws.GetAuthorizationToken(expireSeconds);\n// ...\n```\n\nWhen the client is a browser, then `GetAuthorizationToken` can be exposed implementing a custom API method as shown in\nthe included example application (Test.WebService).\n\nThe following snippet from the example application shows how to request and use the token in JavaScript:\n\n```js\nvar webSocket;\nfetch('/api/myapp/demo/token').then(function(response) {\n    return response.json();\n}).then(function(data) {\n    var token = data.ResponseValue;\n    webSocket = new WebSocket(\"ws://localhost:8181/events?at=\"+token);\n    // ...\n}).catch(function() {\n    // ...\n});\n```\n\n#### User authentication with `Digest` or `Basic` methods\n\nThis is similar as seen for `WebServiceGateway` the only difference is that the password is not encrypted.\n\n\n### TcpSocketGateway\n\nOptions\n\n- Port (TCP port to listen on)\n\n\n### MqttServiceGateway\n\nA MIG Gateway for supporting the MQTT protocol will be integrated in future releases.\nIn the meantime a simple MQTT broker implementation is available as a *MIG Interface*\nfrom [this repository](https://github.com/genielabs/mig-protocols-mqttbroker).\n\n## Interfaces \n\nWhile in the earlier examples we used the **RegisterApi** method to dynamically add new\nAPI commands, these can also be added by using **Interface** plugins.\nInterface plugins are library modules (dll) that can be dinamically loaded into MIG.\nSee [MIG.HomeAutomation](https://github.com/genielabs/mig-homeauto)\nproject source code for an example about how to create a MIG Interface plugin.\n\nCode for loading an Interface plugin:\n```csharp\n// Load the \"HomeAutomation.ZWave\" Interface from the \"MIG.HomeAutomation.dll\" library file\nvar zwave = migService.AddInterface(\"HomeAutomation.ZWave\", \"MIG.HomeAutomation.dll\");\n// configure the serial port\nzwave.SetOption(\"Port\", \"/dev/ttyUSB0\");\n```\nThe example above is used to load the *HomeAutomation.ZWave* Interface plugin into MIG.\nThis will add a set of new API commands for controlling Z-Wave Home Automation hardware.\nFor a list of currently available Interfaces and API, see the\n[MIG API](https://genielabs.github.io/HomeGenie/api/mig/mig_api_zwave.html) documentation page.\n\n## Suggested syntax for API commands\n\n The following is the suggested syntax for a MIG API command:\n```\n\u003capi_domain\u003e/\u003cmodule_address\u003e/\u003ccommand\u003e[/\u003coption_0\u003e/.../\u003coption_n\u003e]\n```\nWhere ```\u003capi_domain\u003e``` is used to address a specific API domain, ```\u003cmodule_address\u003e```\nthe target module of the API ```\u003ccommand\u003e```\nand ```\u003coption_0\u003e...\u003coption_n\u003e``` are optional parameters that the ```\u003ccommand\u003e``` may require. \n\nSo in the previous example where we used the **RegisterApi** methods, we have:\n```\n\u003capi_domain\u003e ::= \"myapp\"\n\u003cmodule_address\u003e ::= \"demo\"\n\u003ccommand\u003e ::= \"greet\"\n\u003coption_0\u003e ::= \"Foo+Bar\"\n```\n\n## NuGet Package\n\nMIG is available as a [NuGet package](https://www.nuget.org/packages/MIG).\n\nRun `Install-Package MIG` in the [Package Manager Console](http://docs.nuget.org/docs/start-here/using-the-package-manager-console) or search for “MIG” in your IDE’s package management console.\n\n## Related Projects\n\n- https://github.com/genielabs/HomeGenie (smart home server based on MIG)\n- https://github.com/genielabs/mig-homeauto (x10/Z-Wave)\n- https://github.com/genielabs/mig-homeauto-insteon\n- https://github.com/genielabs/mig-protocols (UPnP/DLNA)\n- https://github.com/genielabs/mig-protocols-mqttbroker\n- https://github.com/genemars/mig-controllers-lircremote\n- https://github.com/genemars/mig-homeauto-w800rf32\n- https://github.com/genemars/mig-media-v4lcamera\n- https://github.com/genemars/mig-sbc-weecoboard\n\n## License\n\nMIG is open source software, licensed under the terms of Apache license 2.0. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenielabs%2Fmig-service-dotnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgenielabs%2Fmig-service-dotnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenielabs%2Fmig-service-dotnet/lists"}