create GET_LOGS_IN_LAST_X_MINUTES procedure.

implement logs in last x minute check.
can be configured from app.config file using "SwipeTimeGap" configuration. defaults to 3 minutes if configuration is not there.
#36
This commit is contained in:
chris.watts90@outlook.com 2017-02-22 21:17:53 +00:00
parent 4c18778a79
commit 0e1e23a770
4 changed files with 19 additions and 0 deletions

View File

@ -2,6 +2,7 @@ namespace SQLiteRepository
{ {
internal static class SQLiteProcedures internal static class SQLiteProcedures
{ {
public const string GET_LOGS_IN_LAST_X_MINUTES= "select * from TimeLogDb where "+nameof(TimeLogDb.SwipeEventDateTime)+" > ? AND "+nameof(TimeLogDb.UserId_FK)+"=?";
public const string GET_TIMELOGS = "select * from "+nameof(TimeLogDb)+ " where (" + nameof(TimeLogDb.UserId_FK) + "=? AND " + nameof(TimeLogDb.CalendarWeek) + "=? and " + nameof(TimeLogDb.Year) + "=?)"; public const string GET_TIMELOGS = "select * from "+nameof(TimeLogDb)+ " where (" + nameof(TimeLogDb.UserId_FK) + "=? AND " + nameof(TimeLogDb.CalendarWeek) + "=? and " + nameof(TimeLogDb.Year) + "=?)";
public const string GET_ALL_USERS = "select * from " + nameof(UserIdentity); public const string GET_ALL_USERS = "select * from " + nameof(UserIdentity);
public const string GET_USER_BY_ID = "select * from " + nameof(UserIdentity) + " where " + nameof(UserIdentity.Id) + "=?"; public const string GET_USER_BY_ID = "select * from " + nameof(UserIdentity) + " where " + nameof(UserIdentity.Id) + "=?";

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Configuration;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -349,6 +350,21 @@ namespace SQLiteRepository
// Get The User Direction (are they going in or out)? // Get The User Direction (are they going in or out)?
var logDirection = GetLogDirection(ident.UserId_FK); var logDirection = GetLogDirection(ident.UserId_FK);
#region Check the user hasnt registered an event in the last few minutes..
var hysteresisThresholdMinutes = Convert.ToInt32(ConfigurationManager.AppSettings["SwipeTimeGap"] ?? "3");
var threshold = DateTime.UtcNow.AddMinutes(0 - hysteresisThresholdMinutes);
var logs = _connection.Query<TimeLogDb>(
SQLiteProcedures.GET_LOGS_IN_LAST_X_MINUTES,
threshold, ident.UserId_FK);
if (logs.Any())
{
logId = -1;
return OperationResponse.FAILED;
}
#endregion
#region Get the current time (for swiping). and calendar week/year to help recall the data. #region Get the current time (for swiping). and calendar week/year to help recall the data.
var logTime = DateTime.UtcNow; var logTime = DateTime.UtcNow;
var calendarWeek = GetIso8601CalendarWeek(logTime); var calendarWeek = GetIso8601CalendarWeek(logTime);

View File

@ -3,6 +3,7 @@
<appSettings> <appSettings>
<add key="NLogConfigFilePath" value="Configs/NLogConfig.xml" /> <add key="NLogConfigFilePath" value="Configs/NLogConfig.xml" />
<add key="DefaultPageSize" value="20"/> <add key="DefaultPageSize" value="20"/>
<add key="SwipeTimeGap" value="20"/>
</appSettings> </appSettings>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />

View File

@ -3,6 +3,7 @@
<appSettings> <appSettings>
<add key="NLogConfigFilePath" value="Configs/NLogConfig.xml" /> <add key="NLogConfigFilePath" value="Configs/NLogConfig.xml" />
<add key="DefaultPageSize" value="20"/> <add key="DefaultPageSize" value="20"/>
<add key="SwipeTimeGap" value="20"/>
</appSettings> </appSettings>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />