mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-29 09:15:33 +00:00
Created FileList with ability to set used files
This commit is contained in:
@@ -15,15 +15,13 @@ public class HaDocumentWrapper : IHaDocumentWrappper {
|
||||
|
||||
_startYear = configuration.GetValue<int>("AvailableStartYear");
|
||||
_endYear = configuration.GetValue<int>("AvailableEndYear");
|
||||
|
||||
var filelist = xmlProvider.GetHamannFiles();
|
||||
if (filelist != null && filelist.Any())
|
||||
if (filelist != null && filelist.Any()) {
|
||||
_AutoLoad(filelist);
|
||||
|
||||
}
|
||||
// Use Fallback library
|
||||
if (Library == null)
|
||||
if (Library == null)
|
||||
Library = HaDocument.Document.Create(new HaWeb.Settings.HaDocumentOptions() { AvailableYearRange = (_startYear, _endYear) });
|
||||
|
||||
}
|
||||
|
||||
public ILibrary ResetLibrary() {
|
||||
@@ -38,6 +36,7 @@ public class HaDocumentWrapper : IHaDocumentWrappper {
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (ModelState != null) ModelState.AddModelError("Error:", "Das Dokument konnte nicht geparst werden: " + ex.Message);
|
||||
Console.WriteLine(ex.Message);
|
||||
return null;
|
||||
}
|
||||
return Library;
|
||||
@@ -50,7 +49,10 @@ public class HaDocumentWrapper : IHaDocumentWrappper {
|
||||
private void _AutoLoad(List<IFileInfo> files) {
|
||||
var orderdlist = files.OrderByDescending(x => x.LastModified);
|
||||
foreach(var item in orderdlist) {
|
||||
if (SetLibrary(item.PhysicalPath) != null) return;
|
||||
if (SetLibrary(item.PhysicalPath) != null) {
|
||||
_xmlProvider.SetInProduction(item);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,4 +10,6 @@ public interface IXMLProvider {
|
||||
public Task Save(XMLRootDocument doc, string basefilepath, ModelStateDictionary ModelState);
|
||||
public Task<IFileInfo?> SaveHamannFile(XElement element, string basefilepath, ModelStateDictionary ModelState);
|
||||
public List<IFileInfo>? GetHamannFiles();
|
||||
public IFileInfo? GetInProduction();
|
||||
public void SetInProduction(IFileInfo info);
|
||||
}
|
||||
@@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
using HaWeb.Models;
|
||||
using System.Text;
|
||||
|
||||
public static class XMLFileHelpers {
|
||||
// File Signatures Database (https://www.filesignatures.net/)
|
||||
@@ -199,6 +200,20 @@ public static class XMLFileHelpers {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string? StreamToString(System.IO.Stream stream, ModelStateDictionary modelState) {
|
||||
string? ret = null;
|
||||
try {
|
||||
using (var rd = new StreamReader(stream, Encoding.UTF8)) {
|
||||
ret = rd.ReadToEnd();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
modelState.AddModelError("Error", "Reading of the message failed with " + ex.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsValidFileExtensionAndSignature(string fileName, Stream data, string[] permittedExtensions) {
|
||||
if (string.IsNullOrEmpty(fileName) || data == null || data.Length == 0)
|
||||
return false;
|
||||
|
||||
@@ -17,7 +17,7 @@ public class XMLProvider : IXMLProvider {
|
||||
_Roots = xmlservice.GetRootsDictionary();
|
||||
_Files = _ScanFiles();
|
||||
_HamannFiles = _ScanHamannFiles();
|
||||
|
||||
|
||||
if (_Files != null)
|
||||
foreach(var category in _Files)
|
||||
if (category.Value != null)
|
||||
@@ -26,6 +26,10 @@ public class XMLProvider : IXMLProvider {
|
||||
|
||||
public List<IFileInfo>? GetHamannFiles() => this._HamannFiles;
|
||||
|
||||
public IFileInfo? GetInProduction() => this._InProduction;
|
||||
|
||||
public void SetInProduction(IFileInfo info) => _InProduction = info;
|
||||
|
||||
public FileList? GetFiles(string prefix)
|
||||
=> _Files != null && _Files.ContainsKey(prefix) ? _Files[prefix] : null;
|
||||
|
||||
@@ -83,6 +87,7 @@ public class XMLProvider : IXMLProvider {
|
||||
}
|
||||
|
||||
if (_HamannFiles == null) _HamannFiles = new List<IFileInfo>();
|
||||
_HamannFiles.RemoveAll(x => x.Name == info.Name);
|
||||
_HamannFiles.Add(info);
|
||||
_InProduction = info;
|
||||
return info;
|
||||
|
||||
Reference in New Issue
Block a user