diff --git a/.gitignore b/.gitignore index 9ef596f..52a509f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ **/obj/** **/packages/** **/.vs/** +**dotsettings diff --git a/RaceLapTimer/Interfaces/Pilot.cs b/RaceLapTimer/Interfaces/Pilot.cs index 9a092a5..82a371c 100644 --- a/RaceLapTimer/Interfaces/Pilot.cs +++ b/RaceLapTimer/Interfaces/Pilot.cs @@ -2,6 +2,8 @@ { public class Pilot { + public int Id { get; set; } + public string ImageUrl { get; set; } public string Name { get; set; } public int TransponderToken { get; set; } public string ThingyName { get; set; } diff --git a/RaceLapTimer/RaceLapTimer/ApiControllers/InfoApiModule.cs b/RaceLapTimer/RaceLapTimer/ApiControllers/InfoApiModule.cs index 73cc6af..492d6eb 100644 --- a/RaceLapTimer/RaceLapTimer/ApiControllers/InfoApiModule.cs +++ b/RaceLapTimer/RaceLapTimer/ApiControllers/InfoApiModule.cs @@ -4,9 +4,17 @@ namespace RaceLapTimer.ApiControllers { public class InfoApiModule:NancyModule { - public InfoApiModule() : base("/api/info") + private IDbProvider _provider; + public InfoApiModule(IDbProvider provider) : base("/api/info") { - + _provider = provider; + + Get["/lastscanned"] = args => GetLastScannedId(); + } + + private dynamic GetLastScannedId() + { + return Response.AsJson(_provider.GetLastScannedId()); } } } diff --git a/RaceLapTimer/RaceLapTimer/ApiControllers/LapTrackApiModule.cs b/RaceLapTimer/RaceLapTimer/ApiControllers/LapTrackApiModule.cs index dc55c35..8bb37dd 100644 --- a/RaceLapTimer/RaceLapTimer/ApiControllers/LapTrackApiModule.cs +++ b/RaceLapTimer/RaceLapTimer/ApiControllers/LapTrackApiModule.cs @@ -1,12 +1,52 @@ -using Nancy; +using System; +using Nancy; namespace RaceLapTimer.ApiControllers { public class LapTrackApiModule:NancyModule { - public LapTrackApiModule() : base("/api/laptrack") + private IDbProvider _dbProvider; + public LapTrackApiModule(IDbProvider provider) : base("/api/laptrack") { - + _dbProvider = provider; + Get["/create"] = args => LogLapTime(args); } + + private dynamic LogLapTime(dynamic args) + { + var transponderToken = Convert.ToInt32(Request.Query["transponder_token"]); + var lapTimeInMs = Convert.ToInt32(Request.Query["lap_time_in_ms"]); + var log = new SatelliteLog + { + TransponderToken = transponderToken, + LapTimeMS = lapTimeInMs + }; + _dbProvider.StoreTransponderLog(log); + return HttpStatusCode.OK; + } + /* + a non-competition race will result in: 66f92adaf43f8f6ad96204ec being returned? + a competition race will result in: + { + "id": 7, + "created_at": "2017-05-10T19:31:27.517Z", + "created_at_timestamp": 1494444687, + "lap_num": 2, + "lap_time": 95000, + "pilot_id": 2, + "pilot": { + "name": "test2", + "quad": "testste", + "team": "tetststs" + }, + "race_session_id": 6, + "race_session": { + "title": "Competition 1", + "mode": "competition" + } + } + + */ + } } diff --git a/RaceLapTimer/RaceLapTimer/ApiControllers/MonitorApiModule.cs b/RaceLapTimer/RaceLapTimer/ApiControllers/MonitorApiModule.cs index 08bbddd..9e5e84d 100644 --- a/RaceLapTimer/RaceLapTimer/ApiControllers/MonitorApiModule.cs +++ b/RaceLapTimer/RaceLapTimer/ApiControllers/MonitorApiModule.cs @@ -1,12 +1,160 @@ -using Nancy; +using System; +using System.Collections.Generic; +using Interfaces; +using Nancy; namespace RaceLapTimer.ApiControllers { - public class MonitorApiModule:NancyModule + public class MonitorApiModule : NancyModule { - public MonitorApiModule() : base("api/monitor") + private IDbProvider _provider; + public MonitorApiModule(IDbProvider provider) : base("api/monitor") { - + _provider = provider; + + Get[""] = args => GetRootMonitorData(args); + } + + private dynamic GetRootMonitorData(dynamic args) + { + return Response.AsJson(new { data=_provider.GetRaceSessions(true)}); + } + } + + public interface IDbProvider + { + List GetRaceSessions(bool getActive); + + List GetPilotsList(); + + Pilot GetPilot(int pilotId); + + bool CreatePilot(Pilot pilot); + + int GetLastScannedId(); + + void StoreTransponderLog(SatelliteLog log); + } + + public class TestProvider : IDbProvider + { + public List GetRaceSessions(bool getActive) + { + return new List + { + #region Session 1 + new RaceSession + { + Active = true, + CreatedAt = DateTime.UtcNow, + HotSeatEnabled = false, + Id = 1, + IdleTimeSeconds = 400, + Mode = RaceMode.STANDARD, + MaxLaps = 20, + SatelliteCount = 1, + TimePenaltyPerSatellite = 100, + Title = "TEST Session 1" + }, + #endregion + #region Session 2 + new RaceSession + { + Active = true, + CreatedAt = DateTime.UtcNow, + HotSeatEnabled = false, + Id = 2, + IdleTimeSeconds = 400, + Mode = RaceMode.STANDARD, + MaxLaps = 10, + SatelliteCount = 1, + TimePenaltyPerSatellite = 100, + Title = "TEST Session 2" + }, + #endregion + #region Session 3 + new RaceSession + { + Active = getActive, + CreatedAt = DateTime.UtcNow, + HotSeatEnabled = false, + Id = 3, + IdleTimeSeconds = 400, + Mode = RaceMode.STANDARD, + MaxLaps = 10, + SatelliteCount = 1, + TimePenaltyPerSatellite = 100, + Title = "TEST Session 3" + }, + #endregion + #region Session 3 + new RaceSession + { + Active = getActive, + CreatedAt = DateTime.UtcNow, + HotSeatEnabled = false, + Id = 4, + IdleTimeSeconds = 400, + Mode = RaceMode.STANDARD, + MaxLaps = 10, + SatelliteCount = 1, + TimePenaltyPerSatellite = 100, + Title = "TEST Session 4" + } + #endregion + }; + } + + public List GetPilotsList() + { + return new List + { + new Pilot + { + Name = "Pilot1", + TeamName = "PilotTeam 1", + ThingyName = "Kart1", + TransponderToken = 222, + ImageUrl = "images/pilotPic.png" + }, + new Pilot + { + Name = "Pilot 2", + TeamName = "Pilot Team 2", + ThingyName = "Kart2", + TransponderToken = 200 + } + }; + } + + public Pilot GetPilot(int pilotId) + { + return new Pilot + { + Id = pilotId, + Name = "Pilot " + pilotId, + TeamName = "Team " + pilotId, + ThingyName = "Id:" + pilotId, + TransponderToken = pilotId + }; + } + + public bool CreatePilot(Pilot pilot) + { + var rand = new Random(); + var numb = rand.NextDouble(); + return numb > 0.5; + } + + public int GetLastScannedId() + { + var rand = new Random(); + return rand.Next(0, 100); + } + + public void StoreTransponderLog(SatelliteLog log) + { + //do nothing. } } } diff --git a/RaceLapTimer/RaceLapTimer/ApiControllers/PilotApiModule.cs b/RaceLapTimer/RaceLapTimer/ApiControllers/PilotApiModule.cs index 8601923..d255ad2 100644 --- a/RaceLapTimer/RaceLapTimer/ApiControllers/PilotApiModule.cs +++ b/RaceLapTimer/RaceLapTimer/ApiControllers/PilotApiModule.cs @@ -1,13 +1,31 @@ using System.Web.Http; +using Interfaces; using Nancy; +using Nancy.ModelBinding; namespace RaceLapTimer.ApiControllers { public class PilotApiModule:NancyModule { - public PilotApiModule() : base("/api/pilot") + private IDbProvider _provider; + public PilotApiModule(IDbProvider provider) : base("/api/pilot") { - + _provider = provider; + Get["/{id}"] = args => GetPilot(args); + Post["/edit"] = args => EditCreatePilot(args); + } + + private dynamic GetPilot(dynamic args) + { + int pilotId = args.Id; + return Response.AsJson(_provider.GetPilot(pilotId)); + } + + private dynamic EditCreatePilot(dynamic args) + { + var pilotObject = this.Bind(); + var resp = _provider.CreatePilot(pilotObject); + return Response.AsRedirect("/pilots"); } } } diff --git a/RaceLapTimer/RaceLapTimer/ApiControllers/PilotsApiModule.cs b/RaceLapTimer/RaceLapTimer/ApiControllers/PilotsApiModule.cs new file mode 100644 index 0000000..f42ef4e --- /dev/null +++ b/RaceLapTimer/RaceLapTimer/ApiControllers/PilotsApiModule.cs @@ -0,0 +1,19 @@ +using Nancy; + +namespace RaceLapTimer.ApiControllers +{ + public class PilotsApiModule : NancyModule + { + private readonly IDbProvider _provider; + public PilotsApiModule(IDbProvider provider) : base("/api/pilots") + { + _provider = provider; + Get[""] = args => GetPilotsList(); + } + + private dynamic GetPilotsList() + { + return Response.AsJson(new { data = _provider.GetPilotsList() }); + } + } +} \ No newline at end of file diff --git a/RaceLapTimer/RaceLapTimer/ApiControllers/RaceSessionApiModule.cs b/RaceLapTimer/RaceLapTimer/ApiControllers/RaceSessionApiModule.cs index 05e11a7..114cebf 100644 --- a/RaceLapTimer/RaceLapTimer/ApiControllers/RaceSessionApiModule.cs +++ b/RaceLapTimer/RaceLapTimer/ApiControllers/RaceSessionApiModule.cs @@ -1,4 +1,5 @@ -using Interfaces; +using System.Collections.Generic; +using Interfaces; using Nancy; using Nancy.ModelBinding; @@ -6,9 +7,25 @@ namespace RaceLapTimer.ApiControllers { public class RaceSessionApiModule:NancyModule { - public RaceSessionApiModule() : base("/api/racesession") + private readonly IDbProvider _provider; + public RaceSessionApiModule(IDbProvider provider) : base("/api/racesession") { + _provider = provider; + Get[""] = args => GetRaceSessions(); Post["/create"] = args => CreateRaceSession(args); + Get["/historic"] = args => GetHistoricRaceSessions(); + } + + private dynamic GetHistoricRaceSessions() + { + var sessions = _provider.GetRaceSessions(false); + return Response.AsJson(new {data= sessions}); + } + + private dynamic GetRaceSessions() + { + var sessions = _provider.GetRaceSessions(true); + return Response.AsJson(new {data= sessions}); } private dynamic CreateRaceSession(dynamic args) diff --git a/RaceLapTimer/RaceLapTimer/ApiControllers/SatelliteApiModule.cs b/RaceLapTimer/RaceLapTimer/ApiControllers/SatelliteApiModule.cs index 0a0c65d..27bc244 100644 --- a/RaceLapTimer/RaceLapTimer/ApiControllers/SatelliteApiModule.cs +++ b/RaceLapTimer/RaceLapTimer/ApiControllers/SatelliteApiModule.cs @@ -1,12 +1,35 @@ -using Nancy; +using System; +using Nancy; namespace RaceLapTimer.ApiControllers { public class SatelliteApiModule:NancyModule { - public SatelliteApiModule() : base("/api/satellite") + private IDbProvider _provider; + public SatelliteApiModule(IDbProvider provider) : base("/api/satellite") { - + _provider = provider; + + Get[""] = args => LogNewLapSatelliteTime(args); + } + + private dynamic LogNewLapSatelliteTime(dynamic args) + { + var transponderToken = Convert.ToInt32(Request.Query["transponder_token"]); + var lapTimeMs = Convert.ToInt32(Request.Query["lap_time_in_ms"]); + var logObj = new SatelliteLog + { + TransponderToken = transponderToken, + LapTimeMS = lapTimeMs + }; + _provider.StoreTransponderLog(logObj); + return HttpStatusCode.OK; } } + + public class SatelliteLog + { + public int TransponderToken { get; set; } + public int LapTimeMS { get; set; } + } } diff --git a/RaceLapTimer/RaceLapTimer/ApiControllers/SystemApiModule.cs b/RaceLapTimer/RaceLapTimer/ApiControllers/SystemApiModule.cs index 8c65d33..028608d 100644 --- a/RaceLapTimer/RaceLapTimer/ApiControllers/SystemApiModule.cs +++ b/RaceLapTimer/RaceLapTimer/ApiControllers/SystemApiModule.cs @@ -1,17 +1,32 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using Nancy; namespace RaceLapTimer.ApiControllers { - public class SystemApiModule:NancyModule + public class SystemApiModule : NancyModule { public SystemApiModule() : base("/api/system") { - + Get["info"] = args => GetSystemInfo(); + } + + private dynamic GetSystemInfo() + { + return Response.AsJson( + new SystemInfo + { + Version = Assembly.GetEntryAssembly().GetName().Version.ToString() + }); } } + + public class SystemInfo + { + public string Version { get; set; } + } } diff --git a/RaceLapTimer/RaceLapTimer/AuthenticationBootstrapper.cs b/RaceLapTimer/RaceLapTimer/AuthenticationBootstrapper.cs index 30baeb6..003312c 100644 --- a/RaceLapTimer/RaceLapTimer/AuthenticationBootstrapper.cs +++ b/RaceLapTimer/RaceLapTimer/AuthenticationBootstrapper.cs @@ -2,8 +2,10 @@ using Nancy; using Nancy.Authentication.Forms; using Nancy.Bootstrapper; +using Nancy.Conventions; using Nancy.Diagnostics; using Nancy.TinyIoc; +using RaceLapTimer.ApiControllers; namespace RaceLapTimer { @@ -22,6 +24,7 @@ namespace RaceLapTimer // Here we register our user mapper as a per-request singleton. // As this is now per-request we could inject a request scoped // database "context" or other request scoped services. + container.Register(); container.Register(); //register the storage provider.. container.Register().AsSingleton(); } @@ -53,5 +56,13 @@ namespace RaceLapTimer } protected override IRootPathProvider RootPathProvider { get {return new NancyRootPathProvider();} } + + protected override void ConfigureConventions(NancyConventions conventions) + { + base.ConfigureConventions(conventions); + conventions.StaticContentsConventions.Add( + StaticContentConventionBuilder.AddDirectory("images","images") + ); + } } } diff --git a/RaceLapTimer/RaceLapTimer/RaceLapTimer.csproj b/RaceLapTimer/RaceLapTimer/RaceLapTimer.csproj index 1704b25..b82e0c7 100644 --- a/RaceLapTimer/RaceLapTimer/RaceLapTimer.csproj +++ b/RaceLapTimer/RaceLapTimer/RaceLapTimer.csproj @@ -101,6 +101,7 @@ + @@ -158,7 +159,6 @@ - @@ -171,6 +171,11 @@ Interfaces + + + Always + + diff --git a/RaceLapTimer/RaceLapTimer/www/Views/Monitor.cshtml b/RaceLapTimer/RaceLapTimer/www/Views/Monitor.cshtml index 7be1e9c..df76d4d 100644 --- a/RaceLapTimer/RaceLapTimer/www/Views/Monitor.cshtml +++ b/RaceLapTimer/RaceLapTimer/www/Views/Monitor.cshtml @@ -5,34 +5,42 @@ }

@ViewBag.Title

- +
- - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + -
Race NamePilot CountLap Count
Race NameIdle Time (s)Lap Count
None010
None010
None010
None010
\ No newline at end of file + + \ No newline at end of file diff --git a/RaceLapTimer/RaceLapTimer/www/Views/Pilots.cshtml b/RaceLapTimer/RaceLapTimer/www/Views/Pilots.cshtml index 2833553..25c8223 100644 --- a/RaceLapTimer/RaceLapTimer/www/Views/Pilots.cshtml +++ b/RaceLapTimer/RaceLapTimer/www/Views/Pilots.cshtml @@ -5,39 +5,50 @@ }

@ViewBag.Title

- +
- - - - + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + -
NameQuadTotal RacesTotal LapsPilot NameTransponder NumberKart NameTeam Name
None01010
None01010
None01010
None01010pilotLogo---
\ No newline at end of file + + \ No newline at end of file diff --git a/RaceLapTimer/RaceLapTimer/www/Views/razor-layout.cshtml b/RaceLapTimer/RaceLapTimer/www/Views/razor-layout.cshtml index d46f145..daf6cf6 100644 --- a/RaceLapTimer/RaceLapTimer/www/Views/razor-layout.cshtml +++ b/RaceLapTimer/RaceLapTimer/www/Views/razor-layout.cshtml @@ -2,10 +2,21 @@ - - + @**@ + @* - + *@ + @* + + + + *@ + + + + + + Razor Localization Demo @@ -65,32 +76,32 @@ -
+
+
+
+ @RenderBody() +
+
+ -
+
\ No newline at end of file diff --git a/RaceLapTimer/RaceLapTimer/www/images/pilotPic.png b/RaceLapTimer/RaceLapTimer/www/images/pilotPic.png new file mode 100644 index 0000000..db3fe77 Binary files /dev/null and b/RaceLapTimer/RaceLapTimer/www/images/pilotPic.png differ