diff --git a/AIS/bsmd.AIS2Service/AISController.cs b/AIS/bsmd.AIS2Service/AISController.cs index f529e4f1..5b13fe87 100644 --- a/AIS/bsmd.AIS2Service/AISController.cs +++ b/AIS/bsmd.AIS2Service/AISController.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; using System.Web.Http; +using System.Web.Http.Cors; namespace bsmd.AIS2Service { + public class AISController : ApiController { [HttpGet] diff --git a/AIS/bsmd.AIS2Service/App.config b/AIS/bsmd.AIS2Service/App.config index ebffd0bc..4018ac42 100644 --- a/AIS/bsmd.AIS2Service/App.config +++ b/AIS/bsmd.AIS2Service/App.config @@ -1,31 +1,31 @@ - + - +
-
+
- - - + + + - - - - - - + + + + + + - + - + @@ -63,4 +63,16 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/AIS/bsmd.AIS2Service/Program.cs b/AIS/bsmd.AIS2Service/Program.cs index 33bbc1ac..a6b67bd8 100644 --- a/AIS/bsmd.AIS2Service/Program.cs +++ b/AIS/bsmd.AIS2Service/Program.cs @@ -17,7 +17,7 @@ namespace bsmd.AIS2Service { AISManager.Start(); // TODO wait some - Thread.Sleep(120000); + Thread.Sleep(720000); // Test finish.. AISManager.Stop(); } diff --git a/AIS/bsmd.AIS2Service/StartupWebAPI.cs b/AIS/bsmd.AIS2Service/StartupWebAPI.cs index 5341523d..b2d1ac0d 100644 --- a/AIS/bsmd.AIS2Service/StartupWebAPI.cs +++ b/AIS/bsmd.AIS2Service/StartupWebAPI.cs @@ -1,4 +1,5 @@ using System.Web.Http; +using System.Web.Http.Cors; using Owin; namespace bsmd.AIS2Service @@ -8,12 +9,16 @@ namespace bsmd.AIS2Service public void Configuration(IAppBuilder appBuilder) { HttpConfiguration config = new HttpConfiguration(); + var cors = new EnableCorsAttribute("*", "*", "*"); + config.Routes.MapHttpRoute( name: "AISList", routeTemplate: "api/{Controller}", defaults: new { id = RouteParameter.Optional, Controller = "AIS"} ); + config.EnableCors(cors); appBuilder.UseWebApi(config); + } } } diff --git a/AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj b/AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj index ec6f5bdf..df15c6ff 100644 --- a/AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj +++ b/AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj @@ -38,17 +38,17 @@ packages\log4net.2.0.15\lib\net45\log4net.dll - - packages\Microsoft.Owin.2.0.2\lib\net45\Microsoft.Owin.dll + + packages\Microsoft.Owin.4.2.2\lib\net45\Microsoft.Owin.dll - - packages\Microsoft.Owin.Host.HttpListener.2.0.2\lib\net45\Microsoft.Owin.Host.HttpListener.dll + + packages\Microsoft.Owin.Host.HttpListener.4.2.2\lib\net45\Microsoft.Owin.Host.HttpListener.dll - - packages\Microsoft.Owin.Hosting.2.0.2\lib\net45\Microsoft.Owin.Hosting.dll + + packages\Microsoft.Owin.Hosting.4.2.2\lib\net45\Microsoft.Owin.Hosting.dll - - packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll + + packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll packages\Owin.1.0\lib\net40\Owin.dll @@ -63,9 +63,15 @@ packages\Microsoft.AspNet.WebApi.Client.5.2.9\lib\net45\System.Net.Http.Formatting.dll + + packages\Microsoft.AspNet.Cors.5.2.9\lib\net45\System.Web.Cors.dll + packages\Microsoft.AspNet.WebApi.Core.5.2.9\lib\net45\System.Web.Http.dll + + packages\Microsoft.AspNet.WebApi.Cors.5.2.9\lib\net45\System.Web.Http.Cors.dll + packages\Microsoft.AspNet.WebApi.Owin.5.2.9\lib\net45\System.Web.Http.Owin.dll @@ -124,7 +130,9 @@ Settings.Designer.cs - + + + AIS2_Service.cs diff --git a/AIS/bsmd.AIS2Service/index.html b/AIS/bsmd.AIS2Service/index.html new file mode 100644 index 00000000..75abb240 --- /dev/null +++ b/AIS/bsmd.AIS2Service/index.html @@ -0,0 +1,27 @@ + + + + + + + JSON Test + + + + + + + + + + + + + + + + + +
MMSINameTimestampLatitudeLongitudeIMO
+ + \ No newline at end of file diff --git a/AIS/bsmd.AIS2Service/packages.config b/AIS/bsmd.AIS2Service/packages.config index 8edf1530..c1bc6dff 100644 --- a/AIS/bsmd.AIS2Service/packages.config +++ b/AIS/bsmd.AIS2Service/packages.config @@ -1,14 +1,16 @@  + + - - - - + + + + diff --git a/AIS/bsmd.AIS2Service/update.js b/AIS/bsmd.AIS2Service/update.js new file mode 100644 index 00000000..817d09ba --- /dev/null +++ b/AIS/bsmd.AIS2Service/update.js @@ -0,0 +1,41 @@ +function update() { + fetch('http://localhost:9050/api/ais') + .then(function (response) { + return response.json(); + }) + .then(function (data) { + updateData(data); + }) + .catch(function (err) { + console.log('error: ' + err); + }); + function updateData(data) { + var table = document.getElementById("aisTable"); + + const table = document.getElementById('Table'); + let numItems = 1; + + numItems++; + const row = document.createElement('tr'); + row.innerHTML = ` + + + + + + `; + // You could also do the same for the cells and inputs + table.appendChild(row); + + + for (var i = 0; i < data.length; i++) { + var div = document.createElement("div"); + div.innerHTML = 'Name: ' + data[i].Name; + mainContainer.appendChild(div); + } + } +} + +function startup() { + setInterval(function () { update(); }, 10000); +} \ No newline at end of file