add code to support nodes providing their own time (in support of satellite modes)

#72
This commit is contained in:
chris.watts90@outlook.com 2019-09-11 17:38:43 +01:00
parent 1943895eec
commit 380b976f3d

View File

@ -1,47 +1,53 @@
using System; using System;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Web.Http; using System.Web.Http;
using Interfaces; using Interfaces;
namespace WindowsDataCenter namespace WindowsDataCenter
{ {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[RoutePrefix("api/swipedata")] [RoutePrefix("api/swipedata")]
public class SwipeDataController : ApiController public class SwipeDataController : ApiController
{ {
private readonly IRepository _repo; private readonly IRepository _repo;
private readonly ILogger _logger; private readonly ILogger _logger;
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="repo"></param> /// <param name="repo"></param>
/// <param name="logger"></param> /// <param name="logger"></param>
public SwipeDataController(IRepository repo, ILogger logger) public SwipeDataController(IRepository repo, ILogger logger)
{ {
if(repo == null) throw new ArgumentNullException(nameof(repo)); if(repo == null) throw new ArgumentNullException(nameof(repo));
_repo = repo; _repo = repo;
if(logger == null) throw new ArgumentNullException(nameof(logger)); if(logger == null) throw new ArgumentNullException(nameof(logger));
_logger = logger; _logger = logger;
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="cData"></param> /// <param name="cData"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
[Route("")] [Route("")]
public IHttpActionResult PostData([FromBody] CardData cData) public IHttpActionResult PostData([FromBody] CardData cData)
{ {
int logId; int logId;
var resp = _repo.LogEventTime(new Identifier {UniqueId = cData.CardUId}, out logId);
_logger.Trace("Received new \"Swipe Event\" for UId: {0} at {1}, direction is : {2}", cData.CardUId, var id = new Identifier {UniqueId = cData.CardUId};
DateTime.UtcNow, resp.Direction);
return Ok(new {Id = logId, resp.Direction}); var resp = cData.UtcTimeStamp.HasValue
} ? _repo.LogEventTime(id, out logId, cData.UtcTimeStamp.Value)
} : _repo.LogEventTime(id, out logId);
_logger.Trace("Received new \"Swipe Event\" for UId: {0} at {1}, direction is : {2}", cData.CardUId,
DateTime.UtcNow, resp.Direction);
return Ok(new {Id = logId, resp.Direction});
}
}
} }