mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-29 09:15:33 +00:00
Person Pages
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
namespace HaWeb.FileHelpers;
|
||||
using HaDocument.Interfaces;
|
||||
using HaDocument.Models;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using System.Collections.Concurrent;
|
||||
@@ -13,19 +14,19 @@ public class HaDocumentWrapper : IHaDocumentWrappper {
|
||||
private ILibrary Library;
|
||||
private IXMLProvider _xmlProvider;
|
||||
private IXMLService _xmlService;
|
||||
|
||||
private string _filepath;
|
||||
|
||||
public int StartYear { get; private set; }
|
||||
public int EndYear { get; private set; }
|
||||
private int _startYear;
|
||||
private int _endYear;
|
||||
private List<Person>? _availablePersons;
|
||||
private Dictionary<string, Person>? _personsWithLetters;
|
||||
|
||||
// public List<SearchHelpers.CollectedItem>? SearchableLetters { get; private set; }
|
||||
|
||||
public HaDocumentWrapper(IXMLProvider xmlProvider, IXMLService service, IConfiguration configuration) {
|
||||
_xmlProvider = xmlProvider;
|
||||
_xmlService = service;
|
||||
StartYear = configuration.GetValue<int>("AvailableStartYear");
|
||||
EndYear = configuration.GetValue<int>("AvailableEndYear");
|
||||
_startYear = configuration.GetValue<int>("AvailableStartYear");
|
||||
_endYear = configuration.GetValue<int>("AvailableEndYear");
|
||||
var filelist = xmlProvider.GetHamannFiles();
|
||||
if (filelist != null && filelist.Any()) {
|
||||
_AutoLoad(filelist);
|
||||
@@ -40,39 +41,47 @@ public class HaDocumentWrapper : IHaDocumentWrappper {
|
||||
}
|
||||
}
|
||||
|
||||
public int GetStartYear() => StartYear;
|
||||
public List<Person>? GetAvailablePersons() => _availablePersons;
|
||||
|
||||
public int GetEndYear() => EndYear;
|
||||
public Dictionary<string, Person>? GetPersonsWithLetters() => _personsWithLetters;
|
||||
|
||||
public int GetStartYear() => _startYear;
|
||||
|
||||
public int GetEndYear() => _endYear;
|
||||
|
||||
public void SetEndYear(int end) {
|
||||
this.EndYear = end;
|
||||
this._endYear = end;
|
||||
SetLibrary(_filepath);
|
||||
}
|
||||
|
||||
public ILibrary ResetLibrary() {
|
||||
var options = new HaWeb.Settings.HaDocumentOptions() { AvailableYearRange = (StartYear, EndYear )};
|
||||
Library = HaDocument.Document.Create(options);
|
||||
_filepath = options.HamannXMLFilePath;
|
||||
return Library;
|
||||
}
|
||||
|
||||
public ILibrary? SetLibrary(string filepath, ModelStateDictionary? ModelState = null) {
|
||||
var sw = new System.Diagnostics.Stopwatch();
|
||||
sw.Start();
|
||||
// 1. Set ILibrary
|
||||
try {
|
||||
Library = HaDocument.Document.Create(new HaWeb.Settings.HaDocumentOptions() { HamannXMLFilePath = filepath, AvailableYearRange = (StartYear, EndYear) });
|
||||
Library = HaDocument.Document.Create(new HaWeb.Settings.HaDocumentOptions() { HamannXMLFilePath = filepath, AvailableYearRange = (_startYear, _endYear) });
|
||||
} catch (Exception ex) {
|
||||
if (ModelState != null) ModelState.AddModelError("Error", "Das Dokument konnte nicht geparst werden: " + ex.Message);
|
||||
return null;
|
||||
}
|
||||
sw.Stop();
|
||||
Console.WriteLine("ILIB: " + sw.ElapsedMilliseconds);
|
||||
sw.Restart();
|
||||
|
||||
// 1a. Set Available Persons
|
||||
var persons = Library.Metas.SelectMany(x => x.Value.Senders.Union(x.Value.Receivers)).Distinct();
|
||||
_availablePersons = persons.Select(x => Library.Persons[x]).OrderBy(x => x.Surname).ThenBy(x => x.Prename).ToList();
|
||||
|
||||
// 1b. Setup a Dictionary with available Person ovierview Pages
|
||||
|
||||
_personsWithLetters = new Dictionary<string, Person>();
|
||||
var availablePersonPages = Library.Persons.Where(x => !String.IsNullOrWhiteSpace(x.Value.Komm));
|
||||
foreach (var p in availablePersonPages) {
|
||||
if (!_personsWithLetters.ContainsKey(p.Value.Komm!)) {
|
||||
_personsWithLetters.Add(p.Value.Komm, p.Value);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Set Library in Production, collect some Objects
|
||||
if (_xmlService != null)
|
||||
_xmlService.SetInProduction(System.Xml.Linq.XDocument.Load(filepath, System.Xml.Linq.LoadOptions.PreserveWhitespace));
|
||||
sw.Stop();
|
||||
Console.WriteLine("COLLECTIONS: " + sw.ElapsedMilliseconds);
|
||||
|
||||
// 3. Set Filepath
|
||||
_filepath = filepath;
|
||||
return Library;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user