From b8cd5792cfac86dac98ca8f85e12735a887043b8 Mon Sep 17 00:00:00 2001 From: "chris.watts90@outlook.com" Date: Wed, 22 Feb 2017 20:43:48 +0000 Subject: [PATCH 1/4] Set the default page size to a config value - "DefaultPageSize", defaults to 10 if the config value is missing. #37 --- .../WindowsDataCenter/WindowsDataCenter/App.config | 1 + .../Controllers/UsersController.cs | 13 ++++++++++++- .../WindowsDataCenter/WindowsDataCenter.csproj | 1 + .../WindowsDataServiceHost/App.config | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/App.config b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/App.config index e86b823..a33c2a7 100644 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/App.config +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/App.config @@ -2,6 +2,7 @@ + diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/UsersController.cs b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/UsersController.cs index 9987377..0a65dee 100644 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/UsersController.cs +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/UsersController.cs @@ -1,4 +1,5 @@ using System; +using System.Configuration; using System.Net; using System.Net.Http; using System.Net.Http.Headers; @@ -29,8 +30,9 @@ namespace WindowsDataCenter public IHttpActionResult GetUsers([FromUri] string query = "",[FromUri] int pageSize = -1, [FromUri] int pageNumber =-1) { _logger.Trace("GetUsers called with arguments >> query: {0}, pageSize: {1}, pageNumber: {2}", query, pageSize, pageNumber); + pageNumber = pageNumber == -1 ? 1 : pageNumber; - pageSize = pageSize == -1 ? 1 : pageSize; + pageSize = GetPageSize(pageSize); var userList = query == string.Empty ? _repo.GetUsers(pageNumber, pageSize) : _repo.Search(query); _logger.Trace("Got UserList from Repository, UserCount: {0}", userList.UserCount); if (query != string.Empty) @@ -50,6 +52,15 @@ namespace WindowsDataCenter return ResponseMessage(msg); } + private int GetPageSize(int pageSize) + { + var cfgPageSize = ConfigurationManager.AppSettings["DefaultPageSize"] ?? 10.ToString(); + + return pageSize == -1 + ? Convert.ToInt32(cfgPageSize) + : pageSize; + } + [HttpGet] [Route("{id:int}")] [CacheControl(MaxAge = 0)] diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/WindowsDataCenter.csproj b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/WindowsDataCenter.csproj index b9c024b..012fb8d 100644 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/WindowsDataCenter.csproj +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/WindowsDataCenter.csproj @@ -110,6 +110,7 @@ + ..\packages\System.Data.SQLite.Core.1.0.104.0\lib\net451\System.Data.SQLite.dll diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/App.config b/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/App.config index 9f000de..8c1062c 100644 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/App.config +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/App.config @@ -2,6 +2,7 @@ + From 4c18778a79e9ccce4a574e10f5825499db63cbb9 Mon Sep 17 00:00:00 2001 From: "chris.watts90@outlook.com" Date: Wed, 22 Feb 2017 20:53:10 +0000 Subject: [PATCH 2/4] remove test error message code, plus some additional tidying, removing old comments. plus removed unnecessary menu options. #38 --- .../WindowsDataCenter/www/spa.js | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/spa.js b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/spa.js index 282d3fa..82ac54b 100644 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/spa.js +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/spa.js @@ -1,7 +1,7 @@ function DataVM() { "use strict"; var self = this; - self.menuOptions = ["Users", "Data", "Stats", "Other"]; + self.menuOptions = ["Home"]; self.chosenMenuItemId = ko.observable(); self.userList = ko.observable(null); self.chosenUserDetails = ko.observable(null); @@ -12,11 +12,11 @@ self.errorData = ko.observable(null); self.apiEndpoints = { root: "http://localhost:8800", - getUserList: "/api/users",//"/userstest", - getUserDetails: "/api/users",//"/users", - editUser: "/api/users/edit",//"/users/edit", - getTimeLogs: "/api/timelogs",//"/timelogs", - getUnassignedCards: "/api/cards/unassigned"//"/unassignedcards" + getUserList: "/api/users", + getUserDetails: "/api/users", + editUser: "/api/users/edit", + getTimeLogs: "/api/timelogs", + getUnassignedCards: "/api/cards/unassigned" }; self.uiPages = { users: "users", @@ -200,10 +200,6 @@ if (!data.events.changeDate) { $("#weeklyDatePicker").on("changeDate", function (e) { var kk = e.date; - //console.log( - // "1: Iso Week Number: " + moment(kk).isoWeek() + " of " + - // moment(kk).weeksInYear() - //); self.selectedCalendarWeek(moment(kk).isoWeek()); self.goToTimeLogs(self.chosenTimeLogUserId, null, [{ key: "selectedDate", value: moment(kk).format("MM-DD-YYYY") }]); }); @@ -313,8 +309,6 @@ self.searchUsers(query); else self.getUserList(pageSize, pageNumber); - self.assignErrorObject(101, "An Error has occurred.. run away!!!", "test"); - //$.get("http://localhost:3000", { menu: this.params.menu }, self.chosenMenuData); }); this.get("#userData/:userId", function () { self.chosenMenuItemId("Data"); @@ -322,7 +316,6 @@ self.getUserDetails(this.params.userId); self.userTimeLogData(null); self.getUnassignedCardData(); - //$.get("http://localhost:3000", { menu: this.params.menu }, self.chosenMenuData); }); this.get("#timelogs/:userId", function () { var selectedDate = this.params.selectedDate; @@ -330,9 +323,6 @@ self.userList(null); self.chosenUserDetails(null); self.chosenTimeLogUserId = this.params.userId; - //if (!selectedDate) { - // selectedDate = new Date(); - //} self.getTimeLogData(this.params.userId, selectedDate); }); this.get("#newUser", function () { 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 3/4] 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 @@ + From f5513ce1225471505e250744347e61568282d32c Mon Sep 17 00:00:00 2001 From: "chris.watts90@outlook.com" Date: Wed, 22 Feb 2017 22:31:31 +0100 Subject: [PATCH 4/4] change all versions to 0.1.2.0 --- .../CardReaderService/Properties/AssemblyInfo.cs | 4 ++-- .../WindowsDataCenter/CardReaderServiceInstaller/Product.wxs | 2 +- .../WindowsDataCenter/Interfaces/Properties/AssemblyInfo.cs | 4 ++-- .../WindowsDataCenter/NLogLogger/Properties/AssemblyInfo.cs | 4 ++-- .../SQLiteRepository/Properties/AssemblyInfo.cs | 4 ++-- .../WindowsDataCenter/WebApiServerHostInstaller/Product.wxs | 2 +- .../WindowsDataCenter/Properties/AssemblyInfo.cs | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/DataCenter_Windows/WindowsDataCenter/CardReaderService/Properties/AssemblyInfo.cs b/DataCenter_Windows/WindowsDataCenter/CardReaderService/Properties/AssemblyInfo.cs index e6f4bb0..c7bedab 100644 --- a/DataCenter_Windows/WindowsDataCenter/CardReaderService/Properties/AssemblyInfo.cs +++ b/DataCenter_Windows/WindowsDataCenter/CardReaderService/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("0.1.2.0")] +[assembly: AssemblyFileVersion("0.1.2.0")] diff --git a/DataCenter_Windows/WindowsDataCenter/CardReaderServiceInstaller/Product.wxs b/DataCenter_Windows/WindowsDataCenter/CardReaderServiceInstaller/Product.wxs index c841e72..186eb0a 100644 --- a/DataCenter_Windows/WindowsDataCenter/CardReaderServiceInstaller/Product.wxs +++ b/DataCenter_Windows/WindowsDataCenter/CardReaderServiceInstaller/Product.wxs @@ -3,7 +3,7 @@ diff --git a/DataCenter_Windows/WindowsDataCenter/Interfaces/Properties/AssemblyInfo.cs b/DataCenter_Windows/WindowsDataCenter/Interfaces/Properties/AssemblyInfo.cs index 1cf91d9..b188278 100644 --- a/DataCenter_Windows/WindowsDataCenter/Interfaces/Properties/AssemblyInfo.cs +++ b/DataCenter_Windows/WindowsDataCenter/Interfaces/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("0.1.2.0")] +[assembly: AssemblyFileVersion("0.1.2.0")] diff --git a/DataCenter_Windows/WindowsDataCenter/NLogLogger/Properties/AssemblyInfo.cs b/DataCenter_Windows/WindowsDataCenter/NLogLogger/Properties/AssemblyInfo.cs index 1fe2198..b0b6e8c 100644 --- a/DataCenter_Windows/WindowsDataCenter/NLogLogger/Properties/AssemblyInfo.cs +++ b/DataCenter_Windows/WindowsDataCenter/NLogLogger/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("0.1.2.0")] +[assembly: AssemblyFileVersion("0.1.2.0")] diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/Properties/AssemblyInfo.cs b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/Properties/AssemblyInfo.cs index ff4d02c..13a4415 100644 --- a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/Properties/AssemblyInfo.cs +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("0.1.2.0")] +[assembly: AssemblyFileVersion("0.1.2.0")] diff --git a/DataCenter_Windows/WindowsDataCenter/WebApiServerHostInstaller/Product.wxs b/DataCenter_Windows/WindowsDataCenter/WebApiServerHostInstaller/Product.wxs index 2fa3299..c5dd793 100644 --- a/DataCenter_Windows/WindowsDataCenter/WebApiServerHostInstaller/Product.wxs +++ b/DataCenter_Windows/WindowsDataCenter/WebApiServerHostInstaller/Product.wxs @@ -3,7 +3,7 @@ diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Properties/AssemblyInfo.cs b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Properties/AssemblyInfo.cs index 4172feb..970703e 100644 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Properties/AssemblyInfo.cs +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("0.1.2.0")] +[assembly: AssemblyFileVersion("0.1.2.0")]