try pulling ConfigMonitor into the same project to get it to work.
doesnt appear to work so parking it for now. #54
This commit is contained in:
parent
a424260409
commit
44b8012b27
@ -81,7 +81,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\ConfigMonitor\ConfigMonitor.csproj">
|
<ProjectReference Include="..\ConfigMonitor\ConfigMonitor.csproj">
|
||||||
<Project>{6F3878B0-1E07-4DE7-BFEC-509FF4443B71}</Project>
|
<Project>{6f3878b0-1e07-4de7-bfec-509ff4443b71}</Project>
|
||||||
<Name>ConfigMonitor</Name>
|
<Name>ConfigMonitor</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\Interfaces\Interfaces.csproj">
|
<ProjectReference Include="..\Interfaces\Interfaces.csproj">
|
||||||
|
|||||||
@ -19,7 +19,7 @@ namespace ConfigMonitor
|
|||||||
}
|
}
|
||||||
|
|
||||||
_lastChange = DateTime.MinValue;
|
_lastChange = DateTime.MinValue;
|
||||||
//var configFile = string.Concat(System.Reflection.Assembly.GetEntryAssembly().Location, ".config");
|
configFilePath = string.Concat(System.Reflection.Assembly.GetEntryAssembly().Location, ".config");
|
||||||
if (File.Exists(configFilePath))
|
if (File.Exists(configFilePath))
|
||||||
{
|
{
|
||||||
_watcher = new FileSystemWatcher(Path.GetDirectoryName(configFilePath), Path.GetFileName(configFilePath))
|
_watcher = new FileSystemWatcher(Path.GetDirectoryName(configFilePath), Path.GetFileName(configFilePath))
|
||||||
@ -49,7 +49,7 @@ namespace ConfigMonitor
|
|||||||
if ((DateTime.Now - _lastChange).Seconds <= 5 || IsFileLocked(e.FullPath)) return;
|
if ((DateTime.Now - _lastChange).Seconds <= 5 || IsFileLocked(e.FullPath)) return;
|
||||||
var monitoredSections = ConfigurationManager.AppSettings["monitoredSections"];
|
var monitoredSections = ConfigurationManager.AppSettings["monitoredSections"];
|
||||||
|
|
||||||
if (monitoredSections!= null)
|
if (monitoredSections != null)
|
||||||
{
|
{
|
||||||
IEnumerable<string> sections = monitoredSections.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
IEnumerable<string> sections = monitoredSections.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
if (sections.Any())
|
if (sections.Any())
|
||||||
|
|||||||
@ -0,0 +1,93 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -18,7 +18,7 @@ namespace WindowsDataCenter
|
|||||||
private bool _stopMainWorkerThread;
|
private bool _stopMainWorkerThread;
|
||||||
private Thread _mainWorkerThread;
|
private Thread _mainWorkerThread;
|
||||||
private ILogger _logger;
|
private ILogger _logger;
|
||||||
private ConfigMonitor.ConfigMonitor _cfgWatcher;
|
private ConfigMonitor _cfgWatcher;
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
@ -38,7 +38,7 @@ namespace WindowsDataCenter
|
|||||||
_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.ConfigMonitor(configPath);
|
_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)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -147,6 +147,7 @@
|
|||||||
</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" />
|
||||||
@ -212,7 +213,9 @@
|
|||||||
<Content Include="www\spa.js">
|
<Content Include="www\spa.js">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<None Include="App.config" />
|
<None Include="App.config">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</None>
|
||||||
<Content Include="Help\DalSoft.WebApi.HelpPage.Views\api.cshtml">
|
<Content Include="Help\DalSoft.WebApi.HelpPage.Views\api.cshtml">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
@ -259,10 +262,6 @@
|
|||||||
<Content Include="sqlite3.dll" />
|
<Content Include="sqlite3.dll" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\ConfigMonitor\ConfigMonitor.csproj">
|
|
||||||
<Project>{6F3878B0-1E07-4DE7-BFEC-509FF4443B71}</Project>
|
|
||||||
<Name>ConfigMonitor</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