Results of SyntaxCheck -> extra State

This commit is contained in:
Simon Martens
2023-09-10 16:34:49 +02:00
parent 8fd0050cf3
commit 80e593ce7c
16 changed files with 122 additions and 102 deletions

View File

@@ -4,10 +4,12 @@ namespace HaWeb.FileHelpers;
public class ConfigurationMonitor {
private System.Timers.Timer? _timer;
private string[] _paths;
private (string, byte[])[]? _h;
private IServiceProvider _serviceProvider;
public ConfigurationMonitor(string[] paths, IServiceProvider services) {
_paths = paths;
_h = _getHash(paths);
_serviceProvider = services;
}
@@ -33,27 +35,25 @@ public class ConfigurationMonitor {
return true;
}
public void InvokeChanged(string[] paths) {
var h = _getHash(paths);
public void InvokeChanged(IHostEnvironment _) {
var h = _getHash(_paths);
if (_timer == null && !isEqual(h, _h)) {
_h = h;
_timer = new(5000) { AutoReset = false };
_timer = new(8000) { AutoReset = false };
_timer.Enabled = true;
_timer.Elapsed += Action;
_timer.Elapsed += OnChanged;
}
}
private void Action(Object source, System.Timers.ElapsedEventArgs e) {
private void OnChanged(Object source, System.Timers.ElapsedEventArgs e) {
Console.WriteLine("Configuration changed (ConfigurationMonitor Class)");
using IServiceScope serviceScope = _serviceProvider.CreateScope();
IServiceProvider provider = serviceScope.ServiceProvider;
var cP = provider.GetRequiredService<IConfiguration>();
var hP = provider.GetRequiredService<IHaDocumentWrappper>();
hP.ParseConfiguration(cP);
var fP = provider.GetRequiredService<IXMLFileProvider>();
fP.Reload(cP);
fP.ParseConfiguration(cP);
// _lifetime.StopApplication();
_timer = null;
}

View File

@@ -10,7 +10,7 @@ public interface IXMLFileProvider {
public IFileInfo? SaveHamannFile(XElement element, string basefilepath, ModelStateDictionary ModelState);
public List<IFileInfo>? GetHamannFiles();
public (DateTime PullTime, string Hash)? GetGitData();
public void Reload(IConfiguration config);
public void ParseConfiguration(IConfiguration config);
public bool HasChanged();
public void DeleteHamannFile(string filename);
public void Scan();

View File

@@ -49,19 +49,19 @@ public class XMLFileProvider : IXMLFileProvider {
}
_HamannFiles = _ScanHamannFiles();
// Check if hamann file already is current working tree status
// Check if hamann file already is current working tree status
// -> YES: Load up the file via _lib.SetLibrary();
if (_IsAlreadyParsed()) {
_Lib.SetLibrary(_HamannFiles.First(), null, null);
_Lib.SetLibrary(_HamannFiles!.First(), null, null);
if (_Lib.GetLibrary() != null) return;
}
// -> NO: Try to create a new file
var created = xmlservice.TryCreate();
var created = _XMLService.TryCreate();
if (created != null) {
var file = SaveHamannFile(created, _hamannFileProvider.GetFileInfo("./").PhysicalPath, null);
if (file != null) {
_lib.SetLibrary(file, created.Document, null);
_Lib.SetLibrary(file, created.Document, null);
if (_Lib.GetLibrary() != null) return;
}
}
@@ -75,36 +75,32 @@ public class XMLFileProvider : IXMLFileProvider {
// -> There is none? Use Fallback:
else {
var options = new HaWeb.Settings.HaDocumentOptions();
if (_lib.SetLibrary(null, null, null) == null) {
if (_Lib.SetLibrary(null, null, null) == null) {
throw new Exception("Die Fallback Hamann.xml unter " + options.HamannXMLFilePath + " kann nicht geparst werden.");
}
}
}
public void Reload(IConfiguration config) {
public void ParseConfiguration(IConfiguration config) {
_Branch = config.GetValue<string>("RepositoryBranch");
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
_hamannFileProvider = new PhysicalFileProvider(config.GetValue<string>("HamannFileStoreWindows"));
_bareRepositoryFileProvider = new PhysicalFileProvider(config.GetValue<string>("BareRepositoryPathWindows"));
_workingTreeFileProvider = new PhysicalFileProvider(config.GetValue<string>("WorkingTreePathWindows"));
}
else {
_hamannFileProvider = new PhysicalFileProvider(config.GetValue<string>("HamannFileStoreLinux"));
_bareRepositoryFileProvider = new PhysicalFileProvider(config.GetValue<string>("BareRepositoryPathLinux"));
_workingTreeFileProvider = new PhysicalFileProvider(config.GetValue<string>("WorkingTreePathLinux"));
}
// Create File Lists; Here and in xmlservice, which does preliminary checking
Scan();
// Reset XMLInteractionService
if (_WorkingTreeFiles != null && _WorkingTreeFiles.Any()) {
_XMLService.Collect(_WorkingTreeFiles);
}
_HamannFiles = _ScanHamannFiles();
if (_HamannFiles != null && _HamannFiles.Select(x => x.Name).Contains(_Lib.GetActiveFile().Name)) {
_Lib.SetLibrary(_Lib.GetActiveFile(), null, null);
if (_Lib.GetLibrary() != null) return;
}
// Failed to reload File, reload it all, same procedure as above:
// Check if hamann file already is current working tree status
// -> YES: Load up the file via _lib.SetLibrary();
if (_IsAlreadyParsed()) {
_Lib.SetLibrary(_HamannFiles.First(), null, null);
_Lib.SetLibrary(_HamannFiles!.First(), null, null);
if (_Lib.GetLibrary() != null) return;
}