From 0e1e23a770eb4f3e0466d6e7e3b55e3ff15fa1af Mon Sep 17 00:00:00 2001 From: "chris.watts90@outlook.com" Date: Wed, 22 Feb 2017 21:17:53 +0000 Subject: [PATCH] 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 --- .../SQLiteRepository/SQLiteProcedures.cs | 1 + .../SQLiteRepository/SQLiteRepository.cs | 16 ++++++++++++++++ .../WindowsDataCenter/App.config | 1 + .../WindowsDataServiceHost/App.config | 1 + 4 files changed, 19 insertions(+) diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteProcedures.cs b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteProcedures.cs index 1c0d8d3..4873cb6 100644 --- a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteProcedures.cs +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteProcedures.cs @@ -2,6 +2,7 @@ namespace SQLiteRepository { 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_ALL_USERS = "select * from " + nameof(UserIdentity); public const string GET_USER_BY_ID = "select * from " + nameof(UserIdentity) + " where " + nameof(UserIdentity.Id) + "=?"; diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs index cd248eb..936c5be 100644 --- a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Configuration; using System.Globalization; using System.IO; using System.Linq; @@ -349,6 +350,21 @@ namespace SQLiteRepository // Get The User Direction (are they going in or out)? 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( + 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. var logTime = DateTime.UtcNow; var calendarWeek = GetIso8601CalendarWeek(logTime); diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/App.config b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/App.config index a33c2a7..e91591d 100644 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/App.config +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/App.config @@ -3,6 +3,7 @@ + diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/App.config b/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/App.config index 8c1062c..e152d66 100644 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/App.config +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/App.config @@ -3,6 +3,7 @@ +