Move project to use NancyFx as Api controller in order to use the core dependency injection ability across the whole app.

should also make routing a damned sight easier!!!
This commit is contained in:
chris.watts90@outlook.com 2017-04-30 22:00:24 +01:00
parent ba91962eac
commit 834875aa5f
26 changed files with 212 additions and 98 deletions

View File

@ -0,0 +1,15 @@
using System.Collections.Generic;
namespace Interfaces
{
public class CompetitionRace
{
public List<Pilot> Pilots { get; set; }
public string Title { get; set; }
public int MaxLaps { get; set; }
public int NumberOfSatellites { get; set; }
public int SatelliteTimePenaltyMicroS { get; set; }
public bool HotSeatEnabled { get; set; }
public int IdleTime { get; set; }
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Interfaces
{
public class ConfigurationSetting
{
public string ConfigurationName { get; set; }
public string ConfigurationValue { get; set; }
}
}

View File

@ -40,8 +40,13 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ConfigurationSetting.cs" />
<Compile Include="CompetitionRace.cs" />
<Compile Include="Pilot.cs" />
<Compile Include="RaceSession.cs" />
<Compile Include="IUserStorage.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RaceMode.cs" />
<Compile Include="User.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View File

@ -0,0 +1,10 @@
namespace Interfaces
{
public class Pilot
{
public string Name { get; set; }
public int TransponderToken { get; set; }
public string ThingyName { get; set; }
public string TeamName { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace Interfaces
{
public enum RaceMode
{
STANDARD = 1,
COMPETITION = 2
}
}

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Interfaces
{
public class RaceSession
{
public int Id { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
public string Title { get; set; }
public bool Active { get; set; }
public RaceMode Mode { get; set; }
public int MaxLaps { get; set; }
public DateTime DeletedAt { get; set; }
public int SatelliteCount { get; set; }
public int TimePenaltyPerSatellite { get; set; }
public bool HotSeatEnabled { get; set; }
public int IdleTimeSeconds { get; set; }
}
}

View File

@ -0,0 +1,12 @@
using Nancy;
namespace RaceLapTimer.ApiControllers
{
public class InfoApiModule:NancyModule
{
public InfoApiModule() : base("/api/info")
{
}
}
}

View File

@ -1,18 +0,0 @@
using System;
using System.Web.Http;
namespace RaceLapTimer
{
public class InfoController:ApiController
{
/// <summary>
/// returns the last transponder Id from the ir daemon.
/// </summary>
/// <returns></returns>
[HttpGet]
public IHttpActionResult LastScannedId()
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,12 @@
using Nancy;
namespace RaceLapTimer.ApiControllers
{
public class LapTrackApiModule:NancyModule
{
public LapTrackApiModule() : base("/api/laptrack")
{
}
}
}

View File

@ -1,8 +0,0 @@
using System.Web.Http;
namespace RaceLapTimer
{
public class LapTrackController:ApiController
{
}
}

View File

@ -0,0 +1,12 @@
using Nancy;
namespace RaceLapTimer.ApiControllers
{
public class MonitorApiModule:NancyModule
{
public MonitorApiModule() : base("api/monitor")
{
}
}
}

View File

@ -1,8 +0,0 @@
using System.Web.Http;
namespace RaceLapTimer
{
public class MonitorController:ApiController
{
}
}

View File

@ -0,0 +1,13 @@
using System.Web.Http;
using Nancy;
namespace RaceLapTimer.ApiControllers
{
public class PilotApiModule:NancyModule
{
public PilotApiModule() : base("/api/pilot")
{
}
}
}

View File

@ -1,8 +0,0 @@
using System.Web.Http;
namespace RaceLapTimer
{
public class PilotController:ApiController
{
}
}

View File

@ -0,0 +1,20 @@
using Interfaces;
using Nancy;
using Nancy.ModelBinding;
namespace RaceLapTimer.ApiControllers
{
public class RaceSessionApiModule:NancyModule
{
public RaceSessionApiModule() : base("/api/racesession")
{
Post["/create"] = args => CreateRaceSession(args);
}
private dynamic CreateRaceSession(dynamic args)
{
var postObject = this.Bind<RaceSession>();
return Response.AsRedirect("/racedirector");
}
}
}

View File

@ -1,9 +0,0 @@
using System.Web.Http;
namespace RaceLapTimer
{
public class RaceSessionController:ApiController
{
}
}

View File

@ -0,0 +1,12 @@
using Nancy;
namespace RaceLapTimer.ApiControllers
{
public class SatelliteApiModule:NancyModule
{
public SatelliteApiModule() : base("/api/satellite")
{
}
}
}

View File

@ -1,6 +0,0 @@
namespace RaceLapTimer
{
public class SatelliteController
{
}
}

View File

@ -0,0 +1,13 @@
using System.Web.Http;
using Nancy;
namespace RaceLapTimer.ApiControllers
{
public class SoundApiModule:NancyModule
{
public SoundApiModule() : base("/api/sound")
{
}
}
}

View File

@ -1,8 +0,0 @@
using System.Web.Http;
namespace RaceLapTimer
{
public class SoundController:ApiController
{
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Nancy;
namespace RaceLapTimer.ApiControllers
{
public class SystemApiModule:NancyModule
{
public SystemApiModule() : base("/api/system")
{
}
}
}

View File

@ -98,20 +98,21 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ApiControllers\InfoController.cs" />
<Compile Include="ApiControllers\LapTrackController.cs" />
<Compile Include="ApiControllers\MonitorController.cs" />
<Compile Include="ApiControllers\PilotController.cs" />
<Compile Include="ApiControllers\RaceSessionController.cs" />
<Compile Include="ApiControllers\SatelliteController.cs" />
<Compile Include="ApiControllers\SoundController.cs" />
<Compile Include="ApiControllers\LapTrackApiModule.cs" />
<Compile Include="ApiControllers\MonitorApiModule.cs" />
<Compile Include="ApiControllers\PilotApiModule.cs" />
<Compile Include="ApiControllers\SatelliteApiModule.cs" />
<Compile Include="ApiControllers\SoundApiModule.cs" />
<Compile Include="ApiControllers\SystemApiModule.cs" />
<Compile Include="AuthenticationBootstrapper.cs" />
<Compile Include="Modules\HistoryModule.cs" />
<Compile Include="ApiControllers\InfoApiModule.cs" />
<Compile Include="Modules\LoginModule.cs" />
<Compile Include="Modules\MonitorModule.cs" />
<Compile Include="Modules\PilotModule.cs" />
<Compile Include="Modules\PilotsModule.cs" />
<Compile Include="Modules\RaceDirectorModule.cs" />
<Compile Include="ApiControllers\RaceSessionApiModule.cs" />
<Compile Include="Modules\SoundfileModule.cs" />
<Compile Include="Modules\SystemModule.cs" />
<Compile Include="Modules\UserModule.cs" />

View File

@ -1,2 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=apicontrollers/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=apicontrollers/@EntryIndexedValue">False</s:Boolean></wpf:ResourceDictionary>

View File

@ -13,12 +13,12 @@ namespace RaceLapTimer
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.EnsureInitialized();
app.UseWebApi(config);
//app.UseWebApi(config);
app.UseNancy();
}

View File

@ -2,13 +2,7 @@
@{
Layout = "razor-layout.cshtml";
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Login</title>
</head>
<body>
<form method="POST">
<form method="POST">
Username <input type="text" name="Username" />
<br />
Password <input name="Password" type="password" />
@ -16,10 +10,8 @@
Remember Me <input name="RememberMe" type="checkbox" value="True" />
<br />
<input type="submit" value="Login" />
</form>
@if (Model.Errored)
{
</form>
@if (Model.Errored)
{
<div id="errorBox" class="floatingError">Invalid Username or Password</div>
}
</body>
</html>
}

View File

@ -26,7 +26,7 @@
<div class='collapse navbar-collapse' id='navbar'>
<ul class='nav navbar-nav navbar-right'>
<li>
<a href="/race_director">Race Director</a>
<a href="/racedirector">Race Director</a>
</li>
<li class='dropdown'>
<a aria-expanded='false' aria-haspopup='true' class='dropdown-toggle' data-toggle='dropdown' href='#' role='button'>
@ -55,7 +55,7 @@
<a href="/history">History</a>
</li>
<li>
<a href='#'>
<a href="#">
Version
0.5.1
</a>