reference ConfigurationHandler and update calls to get configurations.
removed ConfigMonitor.cs. #54
This commit is contained in:
parent
bd54511d70
commit
bb1eeed231
@ -19,7 +19,6 @@ namespace CardReaderService
|
|||||||
private SCardMonitor _cardMonitor;
|
private SCardMonitor _cardMonitor;
|
||||||
|
|
||||||
private ILogger _logger;
|
private ILogger _logger;
|
||||||
private ConfigMonitor.ConfigMonitor _cfgMonitor;
|
|
||||||
|
|
||||||
public CardReaderService()
|
public CardReaderService()
|
||||||
{
|
{
|
||||||
@ -38,8 +37,6 @@ namespace CardReaderService
|
|||||||
_logger = NinjectHelper.GetInstance().Get<ILogger>();
|
_logger = NinjectHelper.GetInstance().Get<ILogger>();
|
||||||
_logger.Trace("Starting Service.. Getting available readers");
|
_logger.Trace("Starting Service.. Getting available readers");
|
||||||
|
|
||||||
_cfgMonitor = new ConfigMonitor.ConfigMonitor(configPath);
|
|
||||||
|
|
||||||
var ctxFactory = ContextFactory.Instance;
|
var ctxFactory = ContextFactory.Instance;
|
||||||
using(var context = ctxFactory.Establish(SCardScope.System))
|
using(var context = ctxFactory.Establish(SCardScope.System))
|
||||||
{
|
{
|
||||||
@ -54,7 +51,7 @@ namespace CardReaderService
|
|||||||
_logger.Trace("Found reader: {0}", reader);
|
_logger.Trace("Found reader: {0}", reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
var readerNameConfig = ConfigurationManager.AppSettings["ReaderName"];
|
var readerNameConfig = ConfigurationHandler.ConfigurationHandler.GetConfiguration("ReaderName");
|
||||||
if (string.IsNullOrEmpty(readerNameConfig))
|
if (string.IsNullOrEmpty(readerNameConfig))
|
||||||
{
|
{
|
||||||
if (!readerNames.Contains(readerNameConfig))
|
if (!readerNames.Contains(readerNameConfig))
|
||||||
@ -83,8 +80,6 @@ namespace CardReaderService
|
|||||||
|
|
||||||
protected override void OnStop()
|
protected override void OnStop()
|
||||||
{
|
{
|
||||||
_cfgMonitor.Stop();
|
|
||||||
|
|
||||||
_stopMainWorkerThread = true;
|
_stopMainWorkerThread = true;
|
||||||
if (_mainWorkThread!= null && _mainWorkThread.IsAlive)
|
if (_mainWorkThread!= null && _mainWorkThread.IsAlive)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -80,9 +80,9 @@
|
|||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\ConfigMonitor\ConfigMonitor.csproj">
|
<ProjectReference Include="..\ConfigurationHandler\ConfigurationHandler.csproj">
|
||||||
<Project>{6f3878b0-1e07-4de7-bfec-509ff4443b71}</Project>
|
<Project>{115250F6-F8C4-4F9B-A15F-251EA258D963}</Project>
|
||||||
<Name>ConfigMonitor</Name>
|
<Name>ConfigurationHandler</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\Interfaces\Interfaces.csproj">
|
<ProjectReference Include="..\Interfaces\Interfaces.csproj">
|
||||||
<Project>{B7347B72-E208-423A-9D99-723B558EA3D7}</Project>
|
<Project>{B7347B72-E208-423A-9D99-723B558EA3D7}</Project>
|
||||||
|
|||||||
@ -13,7 +13,7 @@ namespace CardReaderService
|
|||||||
{
|
{
|
||||||
public static void Post(CardDataPost postObject, string url)
|
public static void Post(CardDataPost postObject, string url)
|
||||||
{
|
{
|
||||||
var endpointConfig = ConfigurationManager.AppSettings["DataCenterServiceEndpoint"] ??
|
var endpointConfig = ConfigurationHandler.ConfigurationHandler.GetConfiguration("DataCenterServiceEndpoint") ??
|
||||||
"http://localhost:8800";
|
"http://localhost:8800";
|
||||||
|
|
||||||
using (var client = new HttpClient())
|
using (var client = new HttpClient())
|
||||||
|
|||||||
@ -49,6 +49,10 @@
|
|||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\ConfigurationHandler\ConfigurationHandler.csproj">
|
||||||
|
<Project>{115250F6-F8C4-4F9B-A15F-251EA258D963}</Project>
|
||||||
|
<Name>ConfigurationHandler</Name>
|
||||||
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\Interfaces\Interfaces.csproj">
|
<ProjectReference Include="..\Interfaces\Interfaces.csproj">
|
||||||
<Project>{B7347B72-E208-423A-9D99-723B558EA3D7}</Project>
|
<Project>{B7347B72-E208-423A-9D99-723B558EA3D7}</Project>
|
||||||
<Name>Interfaces</Name>
|
<Name>Interfaces</Name>
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Configuration;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using NLog;
|
using NLog;
|
||||||
@ -13,7 +12,8 @@ namespace NLogLogger
|
|||||||
private NLog.Logger _logger;
|
private NLog.Logger _logger;
|
||||||
public NLogger()
|
public NLogger()
|
||||||
{
|
{
|
||||||
var nlogConfigPathOption = ConfigurationManager.AppSettings["NLogConfigFilePath"];
|
var nlogConfigPathOption =
|
||||||
|
ConfigurationHandler.ConfigurationHandler.GetConfiguration("NLogConfigFilePath");
|
||||||
if (nlogConfigPathOption == null)
|
if (nlogConfigPathOption == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("nlogConfigPath");
|
throw new ArgumentNullException("nlogConfigPath");
|
||||||
|
|||||||
@ -1,11 +1,9 @@
|
|||||||
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;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
|
||||||
using Interfaces;
|
using Interfaces;
|
||||||
using SQLite.Net;
|
using SQLite.Net;
|
||||||
using SQLite.Net.Platform.Win32;
|
using SQLite.Net.Platform.Win32;
|
||||||
@ -368,7 +366,7 @@ namespace SQLiteRepository
|
|||||||
|
|
||||||
if (ident.UserId_FK!=-1)
|
if (ident.UserId_FK!=-1)
|
||||||
{ //only check log gap if the card is associated to a user
|
{ //only check log gap if the card is associated to a user
|
||||||
var hysteresisThresholdMinutes = Convert.ToInt32(ConfigurationManager.AppSettings["SwipeTimeGap"] ?? "3");
|
var hysteresisThresholdMinutes = Convert.ToInt32(ConfigurationHandler.ConfigurationHandler.GetConfiguration("SwipeTimeGap") ?? "3");
|
||||||
var threshold = DateTime.UtcNow.AddMinutes(0 - hysteresisThresholdMinutes);
|
var threshold = DateTime.UtcNow.AddMinutes(0 - hysteresisThresholdMinutes);
|
||||||
var logs = _connection.Query<TimeLogDb>(
|
var logs = _connection.Query<TimeLogDb>(
|
||||||
SQLiteProcedures.GET_LOGS_IN_LAST_X_MINUTES,
|
SQLiteProcedures.GET_LOGS_IN_LAST_X_MINUTES,
|
||||||
|
|||||||
@ -69,6 +69,10 @@
|
|||||||
<Compile Include="UserIdentity.cs" />
|
<Compile Include="UserIdentity.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\ConfigurationHandler\ConfigurationHandler.csproj">
|
||||||
|
<Project>{115250F6-F8C4-4F9B-A15F-251EA258D963}</Project>
|
||||||
|
<Name>ConfigurationHandler</Name>
|
||||||
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\Interfaces\Interfaces.csproj">
|
<ProjectReference Include="..\Interfaces\Interfaces.csproj">
|
||||||
<Project>{B7347B72-E208-423A-9D99-723B558EA3D7}</Project>
|
<Project>{B7347B72-E208-423A-9D99-723B558EA3D7}</Project>
|
||||||
<Name>Interfaces</Name>
|
<Name>Interfaces</Name>
|
||||||
|
|||||||
@ -1,93 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Configuration;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace WindowsDataCenter
|
|
||||||
{
|
|
||||||
public class ConfigMonitor
|
|
||||||
{
|
|
||||||
private readonly FileSystemWatcher _watcher;
|
|
||||||
private DateTime _lastChange;
|
|
||||||
|
|
||||||
public ConfigMonitor(string configFilePath)
|
|
||||||
{
|
|
||||||
if (configFilePath == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(configFilePath));
|
|
||||||
}
|
|
||||||
|
|
||||||
_lastChange = DateTime.MinValue;
|
|
||||||
configFilePath = string.Concat(System.Reflection.Assembly.GetEntryAssembly().Location, ".config");
|
|
||||||
if (File.Exists(configFilePath))
|
|
||||||
{
|
|
||||||
_watcher = new FileSystemWatcher(Path.GetDirectoryName(configFilePath), Path.GetFileName(configFilePath))
|
|
||||||
{
|
|
||||||
EnableRaisingEvents = true
|
|
||||||
};
|
|
||||||
_watcher.Changed += Watcher_Changed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~ConfigMonitor()
|
|
||||||
{
|
|
||||||
_watcher.EnableRaisingEvents = false;
|
|
||||||
_watcher.Changed -= Watcher_Changed;
|
|
||||||
_watcher.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Stop()
|
|
||||||
{
|
|
||||||
_watcher.EnableRaisingEvents = false;
|
|
||||||
_watcher.Changed -= Watcher_Changed;
|
|
||||||
_watcher.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Watcher_Changed(object sender, FileSystemEventArgs e)
|
|
||||||
{
|
|
||||||
if ((DateTime.Now - _lastChange).Seconds <= 5 || IsFileLocked(e.FullPath)) return;
|
|
||||||
var monitoredSections = ConfigurationManager.AppSettings["monitoredSections"];
|
|
||||||
|
|
||||||
if (monitoredSections != null)
|
|
||||||
{
|
|
||||||
IEnumerable<string> sections = monitoredSections.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
if (sections.Any())
|
|
||||||
{
|
|
||||||
foreach (var section in sections)
|
|
||||||
{
|
|
||||||
ConfigurationManager.RefreshSection(section);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.WriteLine(ConfigurationManager.AppSettings["SwipeTimeGap"]);
|
|
||||||
ConfigurationManager.RefreshSection("AppSettings");
|
|
||||||
Debug.WriteLine(ConfigurationManager.AppSettings["SwipeTimeGap"]);
|
|
||||||
}
|
|
||||||
_lastChange = DateTime.Now;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool IsFileLocked(string filePath)
|
|
||||||
{
|
|
||||||
FileStream stream = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
stream = File.OpenRead(filePath);
|
|
||||||
}
|
|
||||||
catch (IOException)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
stream?.Close();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,5 +1,4 @@
|
|||||||
using System.Configuration;
|
using System.Reflection;
|
||||||
using System.Reflection;
|
|
||||||
using System.Web.Http;
|
using System.Web.Http;
|
||||||
using Interfaces;
|
using Interfaces;
|
||||||
|
|
||||||
@ -18,7 +17,7 @@ namespace WindowsDataCenter
|
|||||||
DataBaseProvider = ninjectHelper.Get<IRepository>().GetType().ToString(),
|
DataBaseProvider = ninjectHelper.Get<IRepository>().GetType().ToString(),
|
||||||
LoggerProvider = ninjectHelper.Get<ILogger>().GetType().ToString(),
|
LoggerProvider = ninjectHelper.Get<ILogger>().GetType().ToString(),
|
||||||
Version = Assembly.GetEntryAssembly().GetName().Version.ToString(),
|
Version = Assembly.GetEntryAssembly().GetName().Version.ToString(),
|
||||||
ErrorEmailAddress = ConfigurationManager.AppSettings["BugSubmissionEmailAddress"] ?? "NONE"
|
ErrorEmailAddress = ConfigurationHandler.ConfigurationHandler.GetConfiguration("BugSubmissionEmailAddress") ?? "NONE"
|
||||||
};
|
};
|
||||||
|
|
||||||
return Ok(appDetails);
|
return Ok(appDetails);
|
||||||
|
|||||||
@ -54,7 +54,7 @@ namespace WindowsDataCenter
|
|||||||
|
|
||||||
private int GetPageSize(int pageSize)
|
private int GetPageSize(int pageSize)
|
||||||
{
|
{
|
||||||
var cfgPageSize = ConfigurationManager.AppSettings["DefaultPageSize"] ?? 10.ToString();
|
var cfgPageSize = ConfigurationHandler.ConfigurationHandler.GetConfiguration("DefaultPageSize")?? 10.ToString();
|
||||||
|
|
||||||
return pageSize == -1
|
return pageSize == -1
|
||||||
? Convert.ToInt32(cfgPageSize)
|
? Convert.ToInt32(cfgPageSize)
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.ServiceProcess;
|
using System.ServiceProcess;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Interfaces;
|
using Interfaces;
|
||||||
@ -18,7 +17,6 @@ namespace WindowsDataCenter
|
|||||||
private bool _stopMainWorkerThread;
|
private bool _stopMainWorkerThread;
|
||||||
private Thread _mainWorkerThread;
|
private Thread _mainWorkerThread;
|
||||||
private ILogger _logger;
|
private ILogger _logger;
|
||||||
private ConfigMonitor _cfgWatcher;
|
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
@ -37,8 +35,7 @@ namespace WindowsDataCenter
|
|||||||
var ninjectInstance = NinjectHelper.GetInstance();
|
var ninjectInstance = NinjectHelper.GetInstance();
|
||||||
_logger = NinjectHelper.GetInstance().Get<ILogger>();
|
_logger = NinjectHelper.GetInstance().Get<ILogger>();
|
||||||
_logger.Trace("Starting Data Center Service");
|
_logger.Trace("Starting Data Center Service");
|
||||||
|
|
||||||
_cfgWatcher = new ConfigMonitor(configPath);
|
|
||||||
_logger.Trace("Monitoring App.config for changes");
|
_logger.Trace("Monitoring App.config for changes");
|
||||||
_mainWorkerThread = new Thread(MainWorkerThread)
|
_mainWorkerThread = new Thread(MainWorkerThread)
|
||||||
{
|
{
|
||||||
@ -62,10 +59,7 @@ namespace WindowsDataCenter
|
|||||||
|
|
||||||
_webApp.Dispose();
|
_webApp.Dispose();
|
||||||
_logger.Trace("Stopped WebApi");
|
_logger.Trace("Stopped WebApi");
|
||||||
|
|
||||||
_cfgWatcher.Stop();
|
|
||||||
_logger.Trace("Stopped Config Watcher");
|
|
||||||
|
|
||||||
_stopMainWorkerThread = true;
|
_stopMainWorkerThread = true;
|
||||||
if (_mainWorkerThread != null && _mainWorkerThread.IsAlive)
|
if (_mainWorkerThread != null && _mainWorkerThread.IsAlive)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -19,8 +19,6 @@ namespace WindowsDataCenter
|
|||||||
config.MapHttpAttributeRoutes();
|
config.MapHttpAttributeRoutes();
|
||||||
|
|
||||||
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
|
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
|
||||||
//ninject resolver for ApiController DI.
|
|
||||||
//config.DependencyResolver = new NinjectDependencyResolver(NinjectHelper.GetInstance().Kernel);
|
|
||||||
//JSONP formatter for cross-domain requests.
|
//JSONP formatter for cross-domain requests.
|
||||||
config.Formatters.Insert(0, new JsonpFormatter());
|
config.Formatters.Insert(0, new JsonpFormatter());
|
||||||
|
|
||||||
|
|||||||
@ -147,7 +147,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="CardData.cs" />
|
<Compile Include="CardData.cs" />
|
||||||
<Compile Include="ConfigMonitor.cs" />
|
|
||||||
<Compile Include="Controllers\ApplicationController.cs" />
|
<Compile Include="Controllers\ApplicationController.cs" />
|
||||||
<Compile Include="Controllers\CardsController.cs" />
|
<Compile Include="Controllers\CardsController.cs" />
|
||||||
<Compile Include="Configuration.cs" />
|
<Compile Include="Configuration.cs" />
|
||||||
@ -262,6 +261,10 @@
|
|||||||
<Content Include="sqlite3.dll" />
|
<Content Include="sqlite3.dll" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\ConfigurationHandler\ConfigurationHandler.csproj">
|
||||||
|
<Project>{115250F6-F8C4-4F9B-A15F-251EA258D963}</Project>
|
||||||
|
<Name>ConfigurationHandler</Name>
|
||||||
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\Interfaces\Interfaces.csproj">
|
<ProjectReference Include="..\Interfaces\Interfaces.csproj">
|
||||||
<Project>{B7347B72-E208-423A-9D99-723B558EA3D7}</Project>
|
<Project>{B7347B72-E208-423A-9D99-723B558EA3D7}</Project>
|
||||||
<Name>Interfaces</Name>
|
<Name>Interfaces</Name>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user