Indexnumber parsing disabled

This commit is contained in:
Simon Martens
2023-09-16 15:43:11 +02:00
parent f054c8913d
commit d86d508786
58 changed files with 447 additions and 297 deletions

View File

@@ -16,7 +16,7 @@ namespace HaDocument.Comparers
else if (first.Order != second.Order)
return first.Order.CompareTo(second.Order);
else
return String.Compare(first.Index, second.Index);
return String.Compare(first.ID, second.ID);
}
}
}

View File

@@ -13,8 +13,8 @@ namespace HaDocument.Comparers
{
var firstNumber = 0;
var secondNumber = 0;
Int32.TryParse(first.Index, out firstNumber);
Int32.TryParse(second.Index, out secondNumber);
Int32.TryParse(first.ID, out firstNumber);
Int32.TryParse(second.ID, out secondNumber);
return firstNumber.CompareTo(secondNumber);
//var firstIndex = from c in first.Meta.Autopsic

View File

@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HaDocumentV6", "HaDocumentV6.csproj", "{2D3B1B5C-5E0B-4050-A102-E44F025511BE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2D3B1B5C-5E0B-4050-A102-E44F025511BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D3B1B5C-5E0B-4050-A102-E44F025511BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D3B1B5C-5E0B-4050-A102-E44F025511BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D3B1B5C-5E0B-4050-A102-E44F025511BE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E81F4186-AD0D-41A1-BA1B-93C1C7FEE7C7}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,5 @@
using System.Xml.Linq;
public interface IHaElement {
}

View File

@@ -11,7 +11,7 @@ namespace HaDocument.Interfaces {
ImmutableDictionary<string, Person> Persons { get; }
ImmutableDictionary<string, Meta> Metas { get; }
ImmutableDictionary<string, Meta> ExcludedMetas { get; }
ImmutableDictionary<string, Marginal> Marginals { get; }
ImmutableDictionary<string, List<Marginal>> Marginals { get; }
ImmutableDictionary<string, Location> Locations { get; }
ImmutableDictionary<string, Letter> Letters { get; }
ImmutableDictionary<string, Person> HandPersons { get; }
@@ -24,7 +24,6 @@ namespace HaDocument.Interfaces {
ImmutableDictionary<string, Lookup<string, Comment>> CommentsByCategoryLetter { get; }
Lookup<string, Comment> CommentsByCategory { get; }
Lookup<string, Marginal> MarginalsByLetter { get; }
Lookup<string, Editreason> EditreasonsByLetter { get; }
ImmutableSortedSet<Meta> MetasByDate { get; }
ILookup<int, Meta> MetasByYear { get; }

View File

@@ -1,6 +0,0 @@
namespace HaDocument.Interfaces;
public interface ISearchable {
public string Element { get; }
public string Index { get; }
}

View File

@@ -1,17 +1,34 @@
using System.Xml.Linq;
namespace HaDocument.Models {
public class App {
public string Index { get; } = "";
public string Name { get; } = "";
public string Category { get; } = "";
public XElement? XElement { get; }
public App(
string index,
string name,
string category
string category,
XElement? xElement = null
) {
Index = index;
Name = name;
Category = category;
XElement = xElement;
}
public static App? FromXElement(XElement element) {
if (!element.HasAttributes || element.Name != "appDef") return null;
if (element.Attribute("index")?.Value == null || element.Attribute("name")?.Value == null || element.Attribute("category")?.Value == null) return null;
return new App(
element.Attribute("index")!.Value,
element.Attribute("name")!.Value,
element.Attribute("category")!.Value,
element
);
}
}
}

View File

@@ -1,24 +1,68 @@
using System.Xml.Linq;
namespace HaDocument.Models {
public class Backlink {
public string Index { get; } = "";
public string Href { get; } = "";
public string Letter { get; } = "";
public string Page { get; } = "";
public string Line { get; } = "";
public string MarginalIndex { get; } = "";
public string? Letter { get; } = "";
public string? Page { get; } = "";
public string? Line { get; } = "";
public string? Comment { get; }
public Backlink(
string index,
string letter,
string page,
string line,
string marginalindex
string href,
string? letter,
string? page,
string? line,
string? comment = null
) {
Index = index;
Href = href;
Letter = letter;
Page = page;
Line = line;
MarginalIndex = marginalindex;
Comment = comment;
}
public static Backlink? FromXElement(XElement element) {
if (!element.HasAttributes || element.Name != "link") return null;
if (element.Attribute("ref")?.Value == null && element.Attribute("subref")?.Value == null) return null;
if (element.Ancestors("marginal") == null || !element.Ancestors("marginal").Any()) {
var marginal = element.Ancestors("marginal").First();
if (Marginal.FromXElement(marginal) == null) return null;
return new Backlink(
element.Attribute("subref")?.Value ?? element.Attribute("ref")!.Value,
marginal.Attribute("letter")!.Value,
marginal.Attribute("page")!.Value,
marginal.Attribute("line")!.Value
);
}
if (element.Ancestors("subsection") != null || !element.Ancestors("subsection").Any()) {
var subsection = element.Ancestors("subsection").First();
if (subsection.Attribute("id")?.Value == null) return null;
return new Backlink(
element.Attribute("subref")?.Value ?? element.Attribute("ref")!.Value,
null,
null,
null,
subsection.Attribute("id")!.Value
);
}
if (element.Ancestors("kommentar") != null || !element.Ancestors("kommentar").Any()) {
var kommentar = element.Ancestors("kommentar").First();
if (kommentar.Attribute("id")?.Value == null) return null;
return new Backlink(
element.Attribute("subref")?.Value ?? element.Attribute("ref")!.Value,
null,
null,
null,
kommentar.Attribute("id")!.Value
);
}
return null;
}
}
}

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Collections.Immutable;
namespace HaDocument.Models{
public class Comment : HaDocument.Interfaces.ISearchable {
public class Comment {
public string Element { get; } = "";
public string Index { get; } = "";
public string Type { get; } = "";

View File

@@ -1,5 +1,7 @@
using System.Xml.Linq;
namespace HaDocument.Models {
public class Editreason : HaDocument.Interfaces.ISearchable {
public class Editreason {
public string Index { get; } = "";
public string Element { get; } = "";
public string Letter { get; } = "";
@@ -28,5 +30,9 @@ namespace HaDocument.Models {
EndLine = endline;
Reference = reference;
}
public static Editreason? FromXElement(XElement element) {
throw new NotImplementedException("We need two Elements for editreason");
}
}
}

View File

@@ -1,15 +0,0 @@
using System;
using HaXMLReader.EvArgs;
using System.Collections.Generic;
namespace HaDocument.Models {
public abstract class HaModel {
protected static List<(Func<Tag, bool>, Action<Tag>)> FieldActions = null;
internal static void AddAction(Func<Tag, bool> If, Action<Tag> Then) {
if (If == null || Then == null) throw new ArgumentNullException();
if (FieldActions == null) FieldActions = new List<(Func<Tag, bool>, Action<Tag>)>();
FieldActions.Add((If, Then));
}
}
}

View File

@@ -1,5 +1,5 @@
namespace HaDocument.Models {
public class Hand : HaModel {
public class Hand {
public string Letter { get; } = "";
public string Person { get; } = "";
public string StartPage { get; } = "";

View File

@@ -9,7 +9,7 @@ namespace HaDocument.Models
public Dictionary<string, Person> Persons;
public Dictionary<string, Meta> Metas;
public Dictionary<string, Meta> ExcludedMetas;
public Dictionary<string, Marginal> Marginals;
public Dictionary<string, List<Marginal>> Marginals;
public Dictionary<string, Location> Locations;
public Dictionary<string, Letter> Letters;
public Dictionary<string, Person> HandPersons;

View File

@@ -1,14 +1,29 @@
using System.Xml.Linq;
namespace HaDocument.Models {
public class Letter : HaModel, HaDocument.Interfaces.ISearchable {
public string Index { get; } = "";
public class Letter {
public string ID { get; } = "";
public string Element { get; } = "";
public XElement? XElement { get; }
public Letter(
string index,
string element
string id,
string element,
XElement? xelement = null
) {
Index = index;
ID = id;
Element = element;
XElement = xelement;
}
public static Letter? FromXElement(XElement element) {
if (!element.HasAttributes || element.IsEmpty || element.Name != "letterText") return null;
if (element.Attribute("letter")?.Value == null) return null;
return new Letter(
element.Attribute("letter")!.Value,
element.ToString(),
element
);
}
}
}

View File

@@ -15,7 +15,7 @@ namespace HaDocument.Models
public ImmutableDictionary<string, Person> Persons { get; }
public ImmutableDictionary<string, Meta> Metas { get; }
public ImmutableDictionary<string, Meta> ExcludedMetas { get; }
public ImmutableDictionary<string, Marginal> Marginals { get; }
public ImmutableDictionary<string, List<Marginal>> Marginals { get; }
public ImmutableDictionary<string, Location> Locations { get; }
public ImmutableDictionary<string, Letter> Letters { get; }
public ImmutableDictionary<string, Person> HandPersons { get; }
@@ -35,8 +35,6 @@ namespace HaDocument.Models
public Lookup<string, Comment> CommentsByCategory { get; }
// Auswählen von Subkommentaren nach ID
public ImmutableDictionary<string, Comment> SubCommentsByID { get; }
// Auswählen von Marginalien nach Briefen
public Lookup<string, Marginal> MarginalsByLetter { get; }
// Ausw?hlen von Edits nach Briefen
public Lookup<string, Editreason> EditreasonsByLetter { get; }
// Auswählen von Briefen nach autoptischer Numemr und in zeitlich sortierter Reihenfolge.
@@ -51,7 +49,7 @@ namespace HaDocument.Models
Dictionary<string, Person> persons,
Dictionary<string, Meta> meta,
Dictionary<string, Meta> excludedMeta,
Dictionary<string, Marginal> marginals,
Dictionary<string, List<Marginal>> marginals,
Dictionary<string, Location> locations,
Dictionary<string, Letter> letters,
Dictionary<string, Person> handPersons,
@@ -95,7 +93,6 @@ namespace HaDocument.Models
CommentsByLetter_builder.Add(ts.Key, (Lookup<string, Comment>)ts.ToLookup(x => x.Index.Substring(0, 1).ToUpper()));
}
CommentsByCategoryLetter = CommentsByLetter_builder.ToImmutableDictionary();
MarginalsByLetter = (Lookup<string, Marginal>)Marginals.Values.ToLookup(x => x.Letter);
EditreasonsByLetter = (Lookup<string, Editreason>)Editreasons.Values.ToLookup(x => x.Letter);
MetasByDate = Metas.Values.ToImmutableSortedSet<Meta>(new DefaultComparer());
MetasByYear = Metas.Values.ToLookup(x => x.Sort.Year);

View File

@@ -1,14 +1,33 @@
using System.Xml.Linq;
namespace HaDocument.Models {
public class Location {
public string Index { get; } = "";
public string Name { get; } = "";
public string? Reference { get; }
public XElement? XElement { get; }
public Location(
string index,
string name
string name,
string? reference,
XElement? xelement = null
) {
Index = index;
Name = name;
XElement = xelement;
Reference = reference;
}
public static Location? FromXElement(XElement element) {
if (!element.HasAttributes || element.Name != "locationDef") return null;
if (element.Attribute("index")?.Value == null || element.Attribute("name")?.Value == null) return null;
return new Location(
element.Attribute("index")!.Value,
element.Attribute("name")!.Value,
element.Attribute("ref")?.Value,
element
);
}
}
}

View File

@@ -1,23 +1,41 @@
using System.Xml.Linq;
namespace HaDocument.Models {
public class Marginal : HaDocument.Interfaces.ISearchable {
public string Index { get; } = "";
public class Marginal {
public string? Sort { get; } = "";
public string Letter { get; } = "";
public string Page { get; } = "";
public string Line { get; } = "";
public string Element { get; } = "";
public XElement? XElement { get; }
public Marginal(
string index,
string letter,
string page,
string line,
string element
string? sort,
string element,
XElement? xelement = null
) {
Index = index;
Letter = letter;
Page = page;
Line = line;
Sort = sort;
Element = element;
XElement = xelement;
}
public static Marginal? FromXElement(XElement element) {
if (!element.HasAttributes || element.Name != "marginal" || element.IsEmpty) return null;
if (element.Attribute("letter")?.Value == null || element.Attribute("page")?.Value == null || element.Attribute("line")?.Value == null) return null;
return new Marginal(
element.Attribute("letter")!.Value,
element.Attribute("page")!.Value,
element.Attribute("line")!.Value,
element.Attribute("sort")?.Value,
element.ToString(),
element
);
}
}
}

View File

@@ -4,35 +4,32 @@ using HaXMLReader.EvArgs;
namespace HaDocument.Models {
public class Meta {
public string Index { get; } = "";
public string Autopsic { get; } = "";
public string ID { get; } = "";
public string Date { get; } = "";
public DateTime Sort { get; } = new DateTime(1700, 1, 1);
public int Order { get; } = -1;
public string Location { get; } = "";
public List<string> Senders { get; } = null;
public List<string> Receivers { get; } = null;
public OptionalBool hasOriginal { get; } = OptionalBool.None;
public OptionalBool isProofread { get; } = OptionalBool.None;
public OptionalBool isDraft { get; } = OptionalBool.None;
public bool? hasOriginal { get; }
public bool? isProofread { get; }
public bool? isDraft { get; }
public ZHInfo ZH { get; } = null;
public Meta(
string index,
string autopsic,
string id,
string date,
DateTime sort,
int order,
OptionalBool hasOriginal,
OptionalBool isProofread,
OptionalBool isDraft,
bool? hasOriginal,
bool? isProofread,
bool? isDraft,
string location,
List<string> senders,
List<string> receivers,
ZHInfo ZH
) {
Index = index;
Autopsic = autopsic;
ID = id;
Date = date;
Sort = sort;
Order = order;

View File

@@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace HaDocument.Models
{
public enum OptionalBool
{
True,
False,
None
}
}

View File

@@ -1,23 +1,44 @@
using System.Xml.Linq;
namespace HaDocument.Models {
public class Person {
public string Index { get; } = "";
public string Name { get; } = "";
public string Prename { get; } = "";
public string Surname { get; } = "";
public string Index { get; } = string.Empty;
public string Name { get; } = string.Empty;
public string? Prename { get; }
public string? Surname { get; }
public string? Komm { get; }
public string? Reference { get; }
public XElement? XElement { get; }
public Person(
string index,
string name,
string prename,
string surname,
string? komm
string? prename,
string? surname,
string? komm,
string? reference,
XElement? xElement = null
) {
Index = index;
Name = name;
Prename = prename;
Surname = surname;
Komm = komm;
Reference = reference;
}
public static Person? FromXElement(XElement element) {
if (!element.HasAttributes || (element.Name != "personDef" && element.Name != "handDef")) return null;
if (element.Attribute("index")?.Value == null || element.Attribute("name")?.Value == null) return null;
return new Person(
element.Attribute("index")!.Value,
element.Attribute("name")!.Value,
element.Attribute("vorname")?.Value,
element.Attribute("nachname")?.Value,
element.Attribute("komm")?.Value,
element.Attribute("ref")?.Value,
element
);
}
}
}

View File

@@ -1,14 +1,30 @@
using System.Xml.Linq;
namespace HaDocument.Models {
public class Tradition : HaDocument.Interfaces.ISearchable {
public string Index { get; } = "";
public class Tradition {
public string ID { get; } = "";
public string Element { get; } = "";
public XElement? XElement { get; }
public Tradition(
string index,
string element
string id,
string element,
XElement? xelement = null
) {
Index = index;
ID = id;
Element = element;
XElement = xelement;
}
public static Tradition? FromXElement(XElement element) {
if (!element.HasAttributes || element.IsEmpty || element.Name != "letterTradition") return null;
if (element.Attribute("letter")?.Value == null) return null;
return new Tradition(
element.Attribute("letter")!.Value,
element.ToString(),
element
);
}
}
}

View File

@@ -70,14 +70,14 @@ namespace HaDocument.Reactors {
!tag.IsEmpty &&
tag.Name == "letterText"
) {
letter = tag["index"];
letter = tag["letter"];
}
else if (
!tag.EndTag &&
!tag.IsEmpty &&
tag.Name == "letterTradition"
) {
letter = tag["ref"];
letter = tag["letter"];
}
else if (
!tag.EndTag &&

View File

@@ -13,7 +13,6 @@ namespace HaDocument.Reactors {
// State
private string Index;
private string Name;
private string? Komm;
internal HandDefsReactor(IReader reader, IntermediateLibrary lib) : base(reader, lib) {
lib.HandPersons = new Dictionary<string, Person>();
@@ -39,7 +38,6 @@ namespace HaDocument.Reactors {
_active = true;
Index = tag["index"];
Name = tag["name"];
if (!String.IsNullOrWhiteSpace(tag["komm"])) Komm = tag["komm"];
Add();
_active = false;
}
@@ -51,7 +49,7 @@ namespace HaDocument.Reactors {
}
protected void Add() {
CreatedInstances.Add(Index, new Person(Index, Name, "", "", Komm));
CreatedInstances.Add(Index, new Person(Index, Name, null, null, null, null));
}
}
}

View File

@@ -16,7 +16,7 @@ namespace HaDocument.Reactors
internal Dictionary<string, Dictionary<string, HashSet<string>>> CreatedStructure;
// State
private string Index = "";
private string Letter = "";
private ElementStringBinder _element = null;
private bool _normalizeWhitespace = false;
@@ -49,12 +49,12 @@ namespace HaDocument.Reactors
!tag.EndTag &&
!tag.IsEmpty &&
tag.Name == "letterText" &&
!String.IsNullOrWhiteSpace(tag["index"])
!String.IsNullOrWhiteSpace(tag["letter"])
)
{
Activate(_reader, tag);
if (!CreatedStructure.ContainsKey(tag["index"]))
this.CreatedStructure.Add(tag["index"], new Dictionary<string, HashSet<string>>());
if (!CreatedStructure.ContainsKey(tag["letter"]))
this.CreatedStructure.Add(tag["letter"], new Dictionary<string, HashSet<string>>());
}
else if (
!tag.EndTag &&
@@ -64,9 +64,9 @@ namespace HaDocument.Reactors
)
{
_line = tag["index"];
if (!CreatedStructure[Index][_page].Contains(_line))
if (!CreatedStructure[Letter][_page].Contains(_line))
{
CreatedStructure[Index][_page].Add(_line);
CreatedStructure[Letter][_page].Add(_line);
}
}
else if (
@@ -77,8 +77,8 @@ namespace HaDocument.Reactors
)
{
_page = tag["index"];
if (!CreatedStructure[Index].ContainsKey(_page))
CreatedStructure[Index].Add(_page, new HashSet<string>());
if (!CreatedStructure[Letter].ContainsKey(_page))
CreatedStructure[Letter].Add(_page, new HashSet<string>());
}
else if (
_active &&
@@ -100,7 +100,7 @@ namespace HaDocument.Reactors
{
if (_hands == null)
_hands = new List<Hand>();
_hands.Add(new Hand(Index, _person, _handstartpg, _handstartln, _page, _line));
_hands.Add(new Hand(Letter, _person, _handstartpg, _handstartln, _page, _line));
}
}
@@ -110,7 +110,7 @@ namespace HaDocument.Reactors
{
_active = true;
_reader = reader;
Index = tag["index"];
Letter = tag["letter"];
_element = new ElementStringBinder(reader, tag, Add, _normalizeWhitespace);
}
}
@@ -119,23 +119,23 @@ namespace HaDocument.Reactors
{
if (String.IsNullOrWhiteSpace(text)) return;
var letter = new Letter(
Index,
Letter,
text
);
CreatedInstances.TryAdd(Index, letter);
CreatedInstances.TryAdd(Letter, letter);
if (_hands != null)
{
if (!CreatedHands.ContainsKey(Index))
CreatedHands.Add(Index, _hands);
if (!CreatedHands.ContainsKey(Letter))
CreatedHands.Add(Letter, _hands);
else
CreatedHands[Index].AddRange(_hands);
CreatedHands[Letter].AddRange(_hands);
}
Reset();
}
protected override void Reset()
{
Index = "";
Letter = "";
_active = false;
_element = null;
_hands = null;

View File

@@ -14,6 +14,7 @@ namespace HaDocument.Reactors {
// State
private string Index;
private string Name;
private string? Reference;
internal LocationDefsReactor(IReader reader, IntermediateLibrary lib) : base(reader, lib) {
lib.Locations = new Dictionary<string, Location>();
@@ -39,6 +40,7 @@ namespace HaDocument.Reactors {
_active = true;
Index = tag["index"];
Name = tag["name"];
Reference = String.IsNullOrWhiteSpace(tag["ref"]) ? null : tag["ref"];
Add();
_active = false;
}
@@ -47,10 +49,11 @@ namespace HaDocument.Reactors {
protected override void Reset() {
Index = "";
Name = "";
Reference = null;
}
protected void Add() {
CreatedInstances.Add(Index, new Location(Index, Name));
CreatedInstances.Add(Index, new Location(Index, Name, Reference));
}
}
}

View File

@@ -6,12 +6,12 @@ using System;
namespace HaDocument.Reactors {
class MarginalReactor : Reactor {
internal Dictionary<string, Marginal> CreatedInstances;
internal Dictionary<string, List<Marginal>> CreatedInstances;
internal Dictionary<string, List<Backlink>> CreatedBacklinks;
private bool _normalizeWhitespace = false;
// State
private string Index = "";
private string? Sort = "";
private string Letter = "";
private string Page = "";
private string Line = "";
@@ -20,8 +20,8 @@ namespace HaDocument.Reactors {
internal MarginalReactor(IReader reader, IntermediateLibrary lib, bool normalizeWhitespace) : base(reader, lib) {
_normalizeWhitespace = normalizeWhitespace;
lib.Marginals = new Dictionary<string, Marginal>();
lib.Backlinks = new Dictionary<string, List<Backlink>>();
lib.Marginals = new ();
lib.Backlinks = new ();
CreatedBacklinks = lib.Backlinks;
CreatedInstances = lib.Marginals;
reader.OpenTag += Listen;
@@ -32,7 +32,6 @@ namespace HaDocument.Reactors {
!tag.EndTag &&
!tag.IsEmpty &&
tag.Name == "marginal" &&
!String.IsNullOrEmpty(tag["index"]) &&
!String.IsNullOrWhiteSpace(tag["letter"]) &&
!String.IsNullOrWhiteSpace(tag["page"]) &&
!String.IsNullOrWhiteSpace(tag["line"])
@@ -45,7 +44,7 @@ namespace HaDocument.Reactors {
if (!_active && reader != null && tag != null) {
_active = true;
_reader = reader;
Index = tag["index"];
Sort = tag["sort"];
Letter = tag["letter"];
Page = tag["page"];
Line = tag["line"];
@@ -67,7 +66,7 @@ namespace HaDocument.Reactors {
if (!String.IsNullOrWhiteSpace(id)) {
if (!CreatedBacklinks.ContainsKey(id))
CreatedBacklinks.Add(id, new List<Backlink>());
CreatedBacklinks[id].Add(new Backlink(id, Letter, Page, Line, Index));
CreatedBacklinks[id].Add(new Backlink(id, Letter, Page, Line));
}
}
}
@@ -75,18 +74,19 @@ namespace HaDocument.Reactors {
private void Add(string element) {
if (String.IsNullOrWhiteSpace(element)) return;
var marg = new Marginal(
Index,
Letter,
Page,
Line,
String.IsNullOrWhiteSpace(Sort) ? null : Sort,
element
);
CreatedInstances.TryAdd(Index, marg);
if (!CreatedInstances.ContainsKey(Letter)) CreatedInstances.Add(Letter, new());
CreatedInstances[Letter].Add(marg);
Reset();
}
protected override void Reset() {
Index = "";
Sort = "";
_active = false;
_element = null;
_reader.Tag -= OnTag;

View File

@@ -14,8 +14,7 @@ namespace HaDocument.Reactors {
private (int, int) _availableYearRange;
// State
private string Index { get; set; } = "";
private string Autopsic { get; set; } = "";
private string ID { get; set; } = "";
private string Volume { get; set; } = "";
private string Page { get; set; } = "";
private string Date { get; set; } = "";
@@ -23,9 +22,9 @@ namespace HaDocument.Reactors {
private int Order { get; set; } = -1;
private bool AltLineNumbering { get; set; } = false;
private bool inZH { get; set; } = false;
private OptionalBool hasOriginal { get; set; } = OptionalBool.None;
private OptionalBool isProofread { get; set; } = OptionalBool.None;
private OptionalBool isDraft { get; set; } = OptionalBool.None;
private bool? hasOriginal { get; set; } = null;
private bool? isProofread { get; set; } = null;
private bool? isDraft { get; set; } = null;
private bool dateChanged {get; set; } = false;
private string Location { get; set; } = "";
private List<string> Senders { get; set; } = null;
@@ -46,7 +45,7 @@ namespace HaDocument.Reactors {
!tag.EndTag &&
!tag.IsEmpty &&
tag.Name =="letterDesc" &&
!String.IsNullOrWhiteSpace(tag["ref"])
!String.IsNullOrWhiteSpace(tag["letter"])
) {
Activate(_reader, tag);
}
@@ -56,7 +55,7 @@ namespace HaDocument.Reactors {
if (!_active && reader != null && tag != null) {
Reset();
_active = true;
Index = tag["ref"];
ID = tag["letter"];
reader.Tag += OnTag;
_reader = reader;
}
@@ -79,10 +78,6 @@ namespace HaDocument.Reactors {
private void OnTag(object _, Tag tag) {
switch (tag.Name)
{
case "autopsic":
Autopsic = tag["value"];
if (String.IsNullOrWhiteSpace(Autopsic)) Abort();
break;
case "begin":
Page = tag["page"];
Volume = tag["vol"];
@@ -110,29 +105,29 @@ namespace HaDocument.Reactors {
case "hasOriginal":
var val = tag["value"];
if (val.ToLower() == "true")
hasOriginal = OptionalBool.True;
hasOriginal = true;
else if (val.ToLower() == "false")
hasOriginal = OptionalBool.False;
hasOriginal = false;
else
hasOriginal = OptionalBool.None;
hasOriginal = null;
break;
case "isProofread":
var val2 = tag["value"];
if (val2.ToLower() == "true")
isProofread = OptionalBool.True;
isProofread = true;
else if (val2.ToLower() == "false")
isProofread = OptionalBool.False;
isProofread = false;
else
isProofread = OptionalBool.None;
isProofread = null;
break;
case "isDraft":
var val3 = tag["value"];
if (val3.ToLower() == "true")
isDraft = OptionalBool.True;
isDraft = true;
else if (val3.ToLower() == "false")
isDraft = OptionalBool.False;
isDraft = false;
else
isDraft = OptionalBool.None;
isDraft = null;
break;
case "ZHInfo":
if (!tag.EndTag) {
@@ -154,8 +149,7 @@ namespace HaDocument.Reactors {
private void Add() {
var ZHInfo = !inZH ? null : new ZHInfo(AltLineNumbering, dateChanged, Volume, Page);
var meta = new Meta(
Index,
Autopsic,
ID,
Date,
Sort,
Order,
@@ -172,21 +166,20 @@ namespace HaDocument.Reactors {
(Sort.Year >= _availableYearRange.Item1 && Sort.Year <= _availableYearRange.Item2) ||
(_availableVolumes == null && _availableYearRange.Item1 == 0 && _availableYearRange.Item2 == 0)
) {
CreatedInstances.TryAdd(meta.Index, meta);
CreatedInstances.TryAdd(meta.ID, meta);
}
else {
ExcludedInstances.TryAdd(meta.Index, meta);
ExcludedInstances.TryAdd(meta.ID, meta);
}
}
protected override void Reset() {
inZH = true;
hasOriginal = OptionalBool.None;
isProofread = OptionalBool.None;
isDraft = OptionalBool.None;
hasOriginal = null;
isProofread = null;
isDraft = null;
dateChanged = false;
Index = "";
Autopsic = "";
ID = "";
Volume = "";
Page = "";
Date = "";

View File

@@ -15,6 +15,7 @@ namespace HaDocument.Reactors {
private string Name;
private string Prename = "";
private string Surname = "";
private string? Reference;
private string? Komm;
internal PersonDefsReactor(IReader reader, IntermediateLibrary lib) : base(reader, lib) {
@@ -42,6 +43,7 @@ namespace HaDocument.Reactors {
Name = tag["name"];
Prename = tag["vorname"];
Surname = tag["nachname"];
Reference = String.IsNullOrWhiteSpace(tag["ref"]) ? null : tag["ref"];
if (!String.IsNullOrWhiteSpace(tag["komm"])) Komm = tag["komm"];
Add();
_active = false;
@@ -53,11 +55,12 @@ namespace HaDocument.Reactors {
Name = "";
Prename = "";
Surname = "";
Reference = null;
Komm = null;
}
public void Add() {
CreatedInstances.Add(Index, new Person(Index, Name, Prename, Surname, Komm));
CreatedInstances.Add(Index, new Person(Index, Name, Prename, Surname, Komm, Reference));
}
}
}

View File

@@ -14,7 +14,7 @@ namespace HaDocument.Reactors
private bool _normalizeWhitespace = false;
// State
private string Index = "";
private string ID = "";
private string _page = "";
private string _line = "";
@@ -46,7 +46,7 @@ namespace HaDocument.Reactors
if (!tag.EndTag &&
!tag.IsEmpty &&
tag.Name == "letterTradition" &&
!String.IsNullOrWhiteSpace(tag["ref"])
!String.IsNullOrWhiteSpace(tag["letter"])
)
{
Activate(_reader, tag);
@@ -57,33 +57,33 @@ namespace HaDocument.Reactors
tag.Name == "ZHText"
)
{
if (!CreatedStructure.ContainsKey(tag["index"]))
this.CreatedStructure.Add(tag["index"], new Dictionary<string, HashSet<string>>());
if (!CreatedStructure.ContainsKey(tag["letter"]))
this.CreatedStructure.Add(tag["letter"], new Dictionary<string, HashSet<string>>());
}
else if (
!tag.EndTag &&
_active &&
tag.Name == "line" &&
!String.IsNullOrWhiteSpace(tag["index"])
!String.IsNullOrWhiteSpace(tag["letter"])
)
{
_line = tag["index"];
if (!CreatedStructure[Index][_page].Contains(_line))
_line = tag["letter"];
if (!CreatedStructure[ID][_page].Contains(_line))
{
CreatedStructure[Index][_page].Add(_line);
CreatedStructure[ID][_page].Add(_line);
}
}
else if (
!tag.EndTag &&
_active &&
tag.Name == "page" &&
!String.IsNullOrWhiteSpace(tag["index"])
!String.IsNullOrWhiteSpace(tag["letter"])
)
{
_page = tag["index"];
if (!CreatedStructure[Index].ContainsKey(_page))
_page = tag["letter"];
if (!CreatedStructure[ID].ContainsKey(_page))
{
CreatedStructure[Index].Add(_page, new HashSet<string>());
CreatedStructure[ID].Add(_page, new HashSet<string>());
}
}
else if (
@@ -106,7 +106,7 @@ namespace HaDocument.Reactors
{
if (_hands == null)
_hands = new List<Hand>();
_hands.Add(new Hand(Index, _person, _handstartpg, _handstartln, _page, _line));
_hands.Add(new Hand(ID, _person, _handstartpg, _handstartln, _page, _line));
}
}
@@ -115,7 +115,7 @@ namespace HaDocument.Reactors
if (!_active && reader != null && tag != null)
{
_active = true;
Index = tag["ref"];
ID = tag["letter"];
_element = new ElementStringBinder(reader, tag, Add, _normalizeWhitespace);
}
}
@@ -124,22 +124,22 @@ namespace HaDocument.Reactors
{
if (String.IsNullOrWhiteSpace(element)) return;
var reason = new Tradition(
Index,
ID,
element);
CreatedInstances.TryAdd(Index, reason);
CreatedInstances.TryAdd(ID, reason);
if (_hands != null)
{
if (!CreatedHands.ContainsKey(Index))
CreatedHands.Add(Index, _hands);
if (!CreatedHands.ContainsKey(ID))
CreatedHands.Add(ID, _hands);
else
CreatedHands[Index].AddRange(_hands);
CreatedHands[ID].AddRange(_hands);
}
Reset();
}
protected override void Reset()
{
Index = "";
ID = "";
_page = "";
_line = "";
_active = false;

View File

@@ -33,24 +33,22 @@ public class Briefecontroller : Controller {
// Normalisation and Validation, (some) data aquisition
if (id == null) return Redirect(url + defaultID);
id = id.ToLower();
var preliminarymeta = lib.Metas.Where(x => x.Value.Autopsic == id);
if (preliminarymeta == null || !preliminarymeta.Any()) return error404();
Meta? meta;
if (!lib.Metas.TryGetValue(id, out meta)) return error404();
// Get all neccessary data
var index = preliminarymeta.First().Key;
var meta = preliminarymeta.First().Value;
var text = lib.Letters.ContainsKey(index) ? lib.Letters[index] : null;
var marginals = lib.MarginalsByLetter.Contains(index) ? lib.MarginalsByLetter[index] : null;
var tradition = lib.Traditions.ContainsKey(index) ? lib.Traditions[index] : null;
var editreasons = lib.Editreasons.ContainsKey(index) ? lib.EditreasonsByLetter[index] : null; // TODO: Order
var hands = lib.Hands.ContainsKey(index) ? lib.Hands[index] : null;
var text = lib.Letters.ContainsKey(id) ? lib.Letters[id] : null;
var marginals = lib.Marginals.ContainsKey(id) ? lib.Marginals[id] : null;
var tradition = lib.Traditions.ContainsKey(id) ? lib.Traditions[id] : null;
var editreasons = lib.Editreasons.ContainsKey(id) ? lib.EditreasonsByLetter[id] : null; // TODO: Order
var hands = lib.Hands.ContainsKey(id) ? lib.Hands[id] : null;
var nextmeta = meta != lib.MetasByDate.Last() ? lib.MetasByDate.ItemRef(lib.MetasByDate.IndexOf(meta) + 1) : null;
var prevmeta = meta != lib.MetasByDate.First() ? lib.MetasByDate.ItemRef(lib.MetasByDate.IndexOf(meta) - 1) : null;
// More Settings and variables
ViewData["Title"] = "HKB Brief " + id.ToLower();
ViewData["SEODescription"] = "HKB Brief " + id.ToLower();
ViewData["Filename"] = "HKB_" + meta.Autopsic + ".pdf";
ViewData["Filename"] = "HKB_" + meta.ID + ".pdf";
if (!string.IsNullOrWhiteSpace(search)) {
ViewData["Mark"] = search;
}
@@ -58,9 +56,9 @@ public class Briefecontroller : Controller {
// Model creation
var hasMarginals = false;
if (marginals != null && marginals.Any()) hasMarginals = true;
var model = new BriefeViewModel(id, index, GenerateMetaViewModel(lib, meta, true));
if (nextmeta != null) model.MetaData.Next = (GenerateMetaViewModel(lib, nextmeta, false), url + nextmeta.Autopsic);
if (prevmeta != null) model.MetaData.Prev = (GenerateMetaViewModel(lib, prevmeta, false), url + prevmeta.Autopsic);
var model = new BriefeViewModel(id, id, GenerateMetaViewModel(lib, meta, true));
if (nextmeta != null) model.MetaData.Next = (GenerateMetaViewModel(lib, nextmeta, false), url + nextmeta.ID);
if (prevmeta != null) model.MetaData.Prev = (GenerateMetaViewModel(lib, prevmeta, false), url + prevmeta.ID);
if (hands != null && hands.Any()) model.ParsedHands = HaWeb.HTMLHelpers.LetterHelpers.CreateHands(lib, hands);
if (editreasons != null && editreasons.Any()) model.ParsedEdits = HaWeb.HTMLHelpers.LetterHelpers.CreateEdits(lib, _readerService, editreasons);
model.DefaultCategory = lib.Apps.ContainsKey("-1") ? lib.Apps["-1"].Category : null;
@@ -130,8 +128,8 @@ public class Briefecontroller : Controller {
}
internal static BriefeMetaViewModel GenerateMetaViewModel(ILibrary lib, Meta meta, bool generatePersonLinks) {
var hasText = lib.Letters.ContainsKey(meta.Index) ? true : false;
var hasMarginals = lib.MarginalsByLetter.Contains(meta.Index) ? true : false;
var hasText = lib.Letters.ContainsKey(meta.ID) ? true : false;
var hasMarginals = lib.Marginals.ContainsKey(meta.ID) ? true : false;
var senders = meta.Senders.Select(x => lib.Persons[x]).ToList() ?? new List<Person>();
var receivers = meta.Receivers.Select(x => lib.Persons[x]).ToList() ?? new List<Person>();
var zhstring = meta.ZH != null ? HaWeb.HTMLHelpers.LetterHelpers.CreateZHString(meta) : null;

View File

@@ -30,7 +30,7 @@ public class IndexController : Controller {
if (String.IsNullOrWhiteSpace(letterno)) return _error404();
letterno = letterno.Trim();
var lib = _lib.GetLibrary();
var letter = lib.Metas.Where(x => x.Value.Autopsic == letterno);
var letter = lib.Metas.ContainsKey(letterno) ? lib.Metas[letterno] : null;
if (letter != null)
return RedirectToAction("Index", "Briefe", new { id = letterno });
return _error404();
@@ -50,7 +50,7 @@ public class IndexController : Controller {
if (letters != null && letters.Any() && letters.Count == 1) {
string? autopsic = null;
if (lib.Metas.ContainsKey(letters.First())) {
autopsic = lib.Metas[letters.First()].Autopsic;
autopsic = lib.Metas[letters.First()].ID;
}
if (autopsic == null) return _error404();
return RedirectToAction("Index", "Briefe", new { id = autopsic });

View File

@@ -41,7 +41,7 @@ public class SucheController : Controller {
// Letter & comment search and search result creation
var resletter = _xmlService.SearchCollection("letters", search, _readerService, null);
List<(string Index, List<(string Page, string Line, string Preview, string Identifier)> Results)>? rescomments = null;
List<(CollectedItem, List<(string Page, string Line, string Preview, string Identifier)> Results)>? rescomments = null;
if (comments == true)
rescomments = _xmlService.SearchCollection("marginals", search, _readerService, lib);
@@ -54,17 +54,15 @@ public class SucheController : Controller {
if (resletter != null)
metas.AddRange(
resletter
.Select(x => x.Index)
.Select(x => x.Item.ID)
.Where(x => lib.Metas.ContainsKey(x))
.Select(x => lib.Metas[x])
);
if (rescomments != null)
metas.AddRange(
rescomments
.Where(x => lib.Marginals.ContainsKey(x.Index))
.Select(x => lib.Marginals[x.Index])
.Where(x => lib.Metas.ContainsKey(x.Letter))
.Select(x => lib.Metas[x.Letter])
.Where(x => lib.Metas.ContainsKey(x.Item1.ID.Split('-').First()))
.Select(x => lib.Metas[x.Item1.ID.Split('-').First()])
);
// Return
@@ -83,14 +81,12 @@ public class SucheController : Controller {
search = search.Trim();
// Search
List<(string Index, List<(string Page, string Line, string Preview, string Identifier)> Results)>? res = null;
res = _xmlService.SearchCollection("register-comments", search, _readerService, lib);
var res = _xmlService.SearchCollection("register-comments", search, _readerService, lib);
if (res == null || !res.Any())
return _paginateSendRegister(lib, search, SearchType.Register, SearchResultType.NotFound, null);
// Return
return _paginateSendRegister(lib, search, SearchType.Register, SearchResultType.Success, _createComments("neuzeit", res.Select((x) => (x.Index, x.Results.Select((y) => y.Identifier).ToList())).OrderBy(x => x.Index).ToList()));
return _paginateSendRegister(lib, search, SearchType.Register, SearchResultType.Success, _createComments("neuzeit", res.Select((x) => (x.Item.ID, x.Results.Select((y) => y.Identifier).ToList())).OrderBy(x => x.ID).ToList()));
}
@@ -105,13 +101,12 @@ public class SucheController : Controller {
search = search.Trim();
// Search
List<(string Index, List<(string Page, string Line, string Preview, string Identifier)> Results)>? res = null;
res = _xmlService.SearchCollection("forschung-comments", search, _readerService, lib);
var res = _xmlService.SearchCollection("forschung-comments", search, _readerService, lib);
if (res == null || !res.Any())
return _paginateSendRegister(lib, search, SearchType.Science, SearchResultType.NotFound, null);
// Return
return _paginateSendRegister(lib, search, SearchType.Science, SearchResultType.Success, _createComments("neuzeit", res.Select((x) => (x.Index, x.Results.Select((y) => y.Identifier).ToList())).OrderBy(x => x.Index).ToList()));
return _paginateSendRegister(lib, search, SearchType.Science, SearchResultType.Success, _createComments("neuzeit", res.Select((x) => (x.Item.ID, x.Results.Select((y) => y.Identifier).ToList())).OrderBy(x => x.ID).ToList()));
}
@@ -122,8 +117,8 @@ public class SucheController : Controller {
bool? comments,
SearchResultType SRT,
List<Meta>? metas,
List<(string Index, List<(string Page, string Line, string Preview, string Identifier)> Results)>? resletters,
List<(string Index, List<(string Page, string Line, string Preview, string Identifier)> Results)>? rescomments
List<(CollectedItem, List<(string Page, string Line, string Preview, string Identifier)> Results)>? resletters,
List<(CollectedItem, List<(string Page, string Line, string Preview, string Identifier)> Results)>? rescomments
) {
// Sorting, get Pages & Error Checking
var metasbyyear = metas!.Distinct().ToLookup(x => x.Sort.Year).OrderBy(x => x.Key).ToList();
@@ -148,31 +143,31 @@ public class SucheController : Controller {
Dictionary<string, List<(Marginal, string)>>? parsedMarginals = null;
if (resletters != null)
foreach (var res in resletters) {
if (!searchResults.ContainsKey(res.Index))
searchResults.Add(res.Index, new List<SearchResult>());
if (!searchResults.ContainsKey(res.Item1.ID))
searchResults.Add(res.Item1.ID, new List<SearchResult>());
foreach (var r in res.Results) {
if(!searchResults[res.Index].Where(x => x.Page == r.Page && x.Line == r.Line).Any())
searchResults[res.Index].Add(new SearchResult(search, res.Index) { Page = r.Page, Line = r.Line, Preview = r.Preview });
if(!searchResults[res.Item1.ID].Where(x => x.Page == r.Page && x.Line == r.Line).Any())
searchResults[res.Item1.ID].Add(new SearchResult(search, res.Item1.ID) { Page = r.Page, Line = r.Line, Preview = r.Preview });
}
if (searchResults[res.Index].Any()) {
searchResults[res.Index] = searchResults[res.Index].OrderBy(x => HaWeb.HTMLHelpers.ConversionHelpers.RomanOrNumberToInt(x.Page)).ThenBy(x => HaWeb.HTMLHelpers.ConversionHelpers.RomanOrNumberToInt(x.Line)).ToList();
if (searchResults[res.Item1.ID].Any()) {
searchResults[res.Item1.ID] = searchResults[res.Item1.ID].OrderBy(x => HaWeb.HTMLHelpers.ConversionHelpers.RomanOrNumberToInt(x.Page)).ThenBy(x => HaWeb.HTMLHelpers.ConversionHelpers.RomanOrNumberToInt(x.Line)).ToList();
}
}
if (rescomments != null) {
var marginals = rescomments.Where(x => lib.Marginals.ContainsKey(x.Index)).Select(x => lib.Marginals[x.Index]).ToLookup(x => x.Letter);
var shownletters = letters!.SelectMany(x => x.LetterList.Select(y => y.Meta.Index)).ToHashSet();
var marginals = rescomments.Select(x => Marginal.FromXElement(x.Item1.Element)).ToLookup(x => x.Letter);
var shownletters = letters!.SelectMany(x => x.LetterList.Select(y => y.Meta.ID)).ToHashSet();
var shownmarginals = marginals!.Where(x => shownletters.Contains(x.Key)).Select(x => (x.Key, x.ToList())).ToList();
var previews = _xmlService != null ? _xmlService.GetPreviews(shownmarginals, _readerService ,lib) : null;
if (previews != null)
foreach (var p in previews) {
if (!searchResults.ContainsKey(p.Index))
searchResults.Add(p.Index, new List<SearchResult>());
if (!searchResults.ContainsKey(p.Item.ID))
searchResults.Add(p.Item.ID, new List<SearchResult>());
foreach (var res in p.Results) {
if (!searchResults[p.Index].Where(x => x.Page == res.Page && x.Line == res.Line).Any())
searchResults[p.Index].Add(new SearchResult(search, p.Index) { Page = res.Page, Line = res.Line, Preview = res.Preview });
if (!searchResults[p.Item.ID].Where(x => x.Page == res.Page && x.Line == res.Line).Any())
searchResults[p.Item.ID].Add(new SearchResult(search, p.Item.ID) { Page = res.Page, Line = res.Line, Preview = res.Preview });
}
if (searchResults[p.Index].Any()) {
searchResults[p.Index] = searchResults[p.Index].OrderBy(x => HaWeb.HTMLHelpers.ConversionHelpers.RomanOrNumberToInt(x.Page)).ThenBy(x => HaWeb.HTMLHelpers.ConversionHelpers.RomanOrNumberToInt(x.Line)).ToList();
if (searchResults[p.Item.ID].Any()) {
searchResults[p.Item.ID] = searchResults[p.Item.ID].OrderBy(x => HaWeb.HTMLHelpers.ConversionHelpers.RomanOrNumberToInt(x.Page)).ThenBy(x => HaWeb.HTMLHelpers.ConversionHelpers.RomanOrNumberToInt(x.Line)).ToList();
}
}

View File

@@ -38,10 +38,10 @@ public static class CommentHelpers {
sb.Append(HTMLHelpers.TagHelpers.CreateEndElement(DEFAULTELEMENT));
arrow = true;
}
sb.Append(HTMLHelpers.TagHelpers.CreateElement("a", LETLINKCLASS, "/HKB/Briefe/" + let.Autopsic + "#" + blk.Page + "-" + blk.Line));
sb.Append(HTMLHelpers.TagHelpers.CreateElement("a", LETLINKCLASS, "/HKB/Briefe/" + let.ID + "#" + blk.Page + "-" + blk.Line));
var linkstring = string.Empty;
var pglnstring = string.Empty;
linkstring += let.Autopsic;
linkstring += let.ID;
pglnstring += "&nbsp;(&#8239;" + blk.Page + "/" + blk.Line + "&#8239;)";
linkstring += pglnstring;
sb.Append(linkstring);

View File

@@ -46,12 +46,12 @@ public class LinkHelper {
new HaWeb.HTMLHelpers.TagHelpers.Attribute() { Name = "rel", Value = "noopener noreferrer" }));
if (tag.Name == "intlink" && tag.Values.ContainsKey("letter") && _lib.Metas.ContainsKey(tag["letter"])) {
var letter = _lib.Metas[tag["letter"]];
_sb.Append(HTMLHelpers.TagHelpers.CreateElement("a", LETLINKCLASS, "/HKB/Briefe/" + letter.Autopsic + "#" + tag["page"] + "-" + tag["line"]));
_sb.Append(HTMLHelpers.TagHelpers.CreateElement("a", LETLINKCLASS, "/HKB/Briefe/" + letter.ID + "#" + tag["page"] + "-" + tag["line"]));
if (!tag.Values.ContainsKey("linktext") || tag.Values["linktext"] == "true") {
var linkstring = string.Empty;
var ZHstring = string.Empty;
var pglnstring = string.Empty;
linkstring += "HKB&nbsp;" + letter.Autopsic;
linkstring += "HKB&nbsp;" + letter.ID;
if (tag.Values.ContainsKey("page")) {
pglnstring += tag["page"];
if (tag.Values.ContainsKey("line")) {

View File

@@ -6,29 +6,29 @@ using HaWeb.XMLParser;
using System.Xml.Linq;
public class CollectedItem : ISearchable {
public string Index { get; private set; }
public string ID { get; private set; }
public string? SearchText { get; private set; }
public IDictionary<string, string>? Fields { get; private set; }
public XElement ELement { get; private set; }
public XElement Element { get; private set; }
public IXMLCollection Collection { get; private set; }
public IDictionary<string, CollectedItem>? Items { get; set; }
public CollectedItem(
string index,
string id,
XElement element,
IXMLCollection collection,
IDictionary<string, string>? fields,
string? searchtext = null
) {
this.Index = index;
this.ID = id;
this.SearchText = searchtext;
this.Collection = collection;
this.ELement = element;
this.Fields = fields;
this.Element = element;
}
public string? this[string v] {
get {
if (Fields == null && Collection.GenerateDataFields != null)
Fields = Collection.GenerateDataFields(this.Element);
if (Fields != null && Fields.ContainsKey(v))
return Fields[v];
return null;

View File

@@ -63,7 +63,7 @@ ChangeToken.OnChange(
);
app.UseWebSockets( new WebSocketOptions {
KeepAliveInterval = TimeSpan.FromMinutes(180)
KeepAliveInterval = TimeSpan.FromMinutes(180),
});
app.UseMiddleware<WebSocketMiddleware>();

View File

@@ -1,6 +1,6 @@
namespace HaWeb.SearchHelpers;
public interface ISearchable {
public string Index { get; }
public string ID { get; }
public string? SearchText { get; }
}

View File

@@ -10,8 +10,8 @@ public class LetterDescNode : INodeRule
Documents = new[] { "metadaten" },
XPath = "//letterDesc"
};
public string[]? Attributes { get; } = { "ref" };
public string? uniquenessAttribute => "ref" ;
public string[]? Attributes { get; } = { "letter" };
public string? uniquenessAttribute => "letter" ;
public List<(string, HamannXPath, string)>? References { get; } = new List<(string, HamannXPath, string)>()
{
};

View File

@@ -10,8 +10,8 @@ public class LetterTextNode : INodeRule
Documents = new[] { "brieftext" },
XPath = "//letterText"
};
public string[]? Attributes { get; } = { "index" };
public string? uniquenessAttribute => "index" ;
public string[]? Attributes { get; } = { "letter" };
public string? uniquenessAttribute => "letter" ;
public List<(string, HamannXPath, string)>? References { get; } = new List<(string, HamannXPath, string)>()
{
};

View File

@@ -10,8 +10,8 @@ public class LetterTraditionNode : INodeRule
Documents = new[] { "ueberlieferung" },
XPath = "//letterTradition"
};
public string[]? Attributes { get; } = { "ref" };
public string? uniquenessAttribute => "ref" ;
public string[]? Attributes { get; } = { "letter" };
public string? uniquenessAttribute => "letter" ;
public List<(string, HamannXPath, string)>? References { get; } = new List<(string, HamannXPath, string)>()
{
};

View File

@@ -10,8 +10,8 @@ public class MarginalNode : INodeRule
Documents = new[] { "stellenkommentar" },
XPath = "//marginal"
};
public string[]? Attributes { get; } = { "index", "letter", "page", "line" };
public string? uniquenessAttribute => "index";
public string[]? Attributes { get; } = { "letter", "page", "line" };
public string? uniquenessAttribute { get; }
public List<(string, HamannXPath, string)>? References { get; } = new List<(string, HamannXPath, string)>()
{
};

View File

@@ -16,7 +16,7 @@ public class StructureCollection : ICollectionRule {
public IEnumerable<(string, XElement, XMLRootDocument)> GenerateIdentificationStrings(IEnumerable<(XElement, XMLRootDocument)> list) {
foreach (var e in list) {
var id = e.Item1.Name == "letterText" ? e.Item1.Attribute("index")!.Value : e.Item1.Attribute("ref")!.Value;
var id = e.Item1.Attribute("letter")!.Value;
var currpage = String.Empty;
var currline = String.Empty;
foreach (var el in e.Item1.Descendants()) {

View File

@@ -233,7 +233,7 @@ public class TextRules {
{
if(reader.State.ParsedMarginals == null) reader.State.ParsedMarginals = new List<(string, string, string)>();
var sb2 = new StringBuilder();
margs = margs.OrderBy(x => Int32.Parse(x.Index));
if (margs.Count() > 1) margs = margs.OrderBy(x => Int32.Parse(x.Sort));
sb.Append(HaWeb.HTMLHelpers.TagHelpers.CreateElement(DEFAULTELEMENT, CSSClasses.COMMENTMARKERCLASS, "ma-" + reader.State.currpage + "-" + reader.State.currline));
sb.Append(HaWeb.HTMLHelpers.TagHelpers.CreateEndElement(DEFAULTELEMENT));
sb.Append(HaWeb.HTMLHelpers.TagHelpers.CreateElement(DEFAULTELEMENT, CSSClasses.MARGINGALBOXCLASS));

View File

@@ -14,24 +14,26 @@ public class BackLinkCollection : HaWeb.XMLParser.IXMLCollection {
public bool Searchable { get; } = true;
public static Func<XElement, string?> GetKey { get; } = (elem) => {
var margid = (string?)elem.Ancestors("marginal").First().Attribute("index");
if (String.IsNullOrWhiteSpace(margid)) return null;
return margid + _random.Next().ToString();
var letter = (string?)elem.Attribute("letter");
var page = (string?)elem.Attribute("page");
var line = (string?)elem.Attribute("line");
if (letter == null) return null;
var index = letter + "-" + page ?? "" + "-" + line ?? "";
if (String.IsNullOrWhiteSpace(index)) return null;
return index + _random.Next().ToString();
};
public static IDictionary<string, string>? GetDataFields(XElement element) {
var res = new Dictionary<string, string>();
var marg = element.Ancestors("marginal").First();
var index = (string?)marg.Attribute("index");
var letter = (string?)marg.Attribute("letter");
var page = (string?)marg.Attribute("page");
var line = (string?)marg.Attribute("line");
var refere = (string?)element.Attribute("ref");
var subref = (string?)element.Attribute("subref");
if (index == null || letter == null || (refere == null && subref == null)) return null;
if (letter == null || (refere == null && subref == null)) return null;
if (subref != null) res.Add("ref", subref);
else res.Add("ref", refere!);
res.Add("index", index);
res.Add("letter", letter);
if (page != null) res.Add("page", page);
if (line != null) res.Add("line", line);

View File

@@ -22,9 +22,9 @@ public static class CommentCollectionHelpers {
public static IDictionary<string, ILookup<string, CollectedItem>>? GetLookups(IEnumerable<CollectedItem> items) {
var res = new Dictionary<string, ILookup<string, CollectedItem>>();
var lemmas = items.Where(x => !String.IsNullOrWhiteSpace(x.Index));
var lemmas = items.Where(x => !String.IsNullOrWhiteSpace(x.ID));
if (lemmas != null && lemmas.Any())
res.Add("lemma", lemmas.ToLookup(x => x.Index.Substring(0, 1).ToUpper()));
res.Add("lemma", lemmas.ToLookup(x => x.ID.Substring(0, 1).ToUpper()));
// If we use lemmas
// var lemmas = items.Where(x => x.Fields != null && x.Fields.ContainsKey("lemma"));
// if (lemmas != null && lemmas.Any())

View File

@@ -13,7 +13,7 @@ public class LetterCollection : HaWeb.XMLParser.IXMLCollection {
public bool Searchable { get; } = true;
public static Func<XElement, string?> GetKey { get; } = (elem) => {
var index = elem.Attribute("index");
var index = elem.Attribute("letter");
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
return index.Value;
else return null;

View File

@@ -13,9 +13,14 @@ public class MarginalCollection : HaWeb.XMLParser.IXMLCollection {
public bool Searchable { get; } = true;
public static Func<XElement, string?> GetKey { get; } = (elem) => {
var index = elem.Attribute("index");
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
return index.Value;
var letter = (string?)elem.Attribute("letter");
var page = (string?)elem.Attribute("page");
var line = (string?)elem.Attribute("line");
var sort = (string?)elem.Attribute("sort");
if (letter == null || page == null || line == null) return null;
var index = letter + "-" + page + "-" + line + sort ?? "";
if (index != null && !String.IsNullOrWhiteSpace(index))
return index;
else return null;
};
@@ -24,10 +29,12 @@ public class MarginalCollection : HaWeb.XMLParser.IXMLCollection {
var letter = (string?)element.Attribute("letter");
var page = (string?)element.Attribute("page");
var line = (string?)element.Attribute("line");
var sort = (string?)element.Attribute("sort");
if (letter == null || page == null || line == null) return null;
res.Add("letter", letter);
res.Add("page", page);
res.Add("line", line);
if (sort != null) res.Add("sort", sort);
return res;
}

View File

@@ -13,7 +13,7 @@ public class MetaCollection : HaWeb.XMLParser.IXMLCollection {
public bool Searchable { get; } = false;
public static Func<XElement, string?> GetKey { get; } = (elem) => {
var index = elem.Attribute("ref");
var index = elem.Attribute("letter");
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
return index.Value;
return null;

View File

@@ -13,7 +13,7 @@ public class TraditionCollection : HaWeb.XMLParser.IXMLCollection {
public bool Searchable { get; } = true;
public static Func<XElement, string?> GetKey { get; } = (elem) => {
var index = elem.Attribute("ref");
var index = elem.Attribute("letter");
if (index != null && !String.IsNullOrWhiteSpace(index.Value))
return index.Value;
return null;

View File

@@ -53,7 +53,7 @@
{
<a class="ml-1" href="@Model.PDFFilePath">
<div class="inline-block bg-slate-100 hover:bg-slate-200 border px-1.5 rounded">Brief @Model.MetaData.Meta.Autopsic</div>
<div class="inline-block bg-slate-100 hover:bg-slate-200 border px-1.5 rounded">Brief @Model.MetaData.Meta.ID</div>
</a>
}
@@ -73,7 +73,7 @@
@if (Model.MetaData.Prev != null)
{
<a href="@Model.MetaData.Prev.Value.Item2">
@Model.MetaData.Prev.Value.Model.Meta.Autopsic
@Model.MetaData.Prev.Value.Model.Meta.ID
</a>
}
@@ -84,7 +84,7 @@
@if (Model.MetaData.Next != null)
{
<a href="@Model.MetaData.Next.Value.Item2">
▶ @Model.MetaData.Next.Value.Model.Meta.Autopsic
▶ @Model.MetaData.Next.Value.Model.Meta.ID
</a>
}
</div>

View File

@@ -56,7 +56,7 @@
@foreach (var year in Model.Letters) {
foreach (var letter in year.LetterList) {
<div class="ha-letterlistentry">
<a asp-controller="Briefe" asp-action="Index" asp-route-id="@letter.Meta.Autopsic">
<a asp-controller="Briefe" asp-action="Index" asp-route-id="@letter.Meta.ID">
@await Html.PartialAsync("/Views/Shared/_LetterHead.cshtml", (letter, true, false))
</a>
</div>

View File

@@ -84,27 +84,27 @@
@foreach (var year in Model.Letters) {
foreach (var letter in year.LetterList) {
<div class="ha-letterlistentry">
<a asp-controller="Briefe" asp-action="Index" asp-route-id="@letter.Meta.Autopsic">
<a asp-controller="Briefe" asp-action="Index" asp-route-id="@letter.Meta.ID">
@Html.Partial("/Views/Shared/_LetterHead.cshtml", (letter, true, false))
</a>
@if (Model.SearchResults != null && Model.SearchResults.ContainsKey(letter.Meta.Index)) {
@if (Model.SearchResults != null && Model.SearchResults.ContainsKey(letter.Meta.ID)) {
<div class="ha-letterlistsearchresults">
@foreach (var sr in Model.SearchResults[letter.Meta.Index])
@foreach (var sr in Model.SearchResults[letter.Meta.ID])
{
<div class="ha-letterlistsearchresult">
<div class="ha-searchresultlocation">
<a asp-controller="Briefe" asp-action="Index" asp-route-id="@letter.Meta.Autopsic" asp-route-search="@Model.ActiveSearch" asp-fragment="@sr.Page-@sr.Line">
HKB @letter.Meta.Autopsic @sr.Page/@sr.Line
<a asp-controller="Briefe" asp-action="Index" asp-route-id="@letter.Meta.ID" asp-route-search="@Model.ActiveSearch" asp-fragment="@sr.Page-@sr.Line">
HKB @letter.Meta.ID @sr.Page/@sr.Line
</a>
</div>
<div class="ha-searchresultpreview">
<a asp-controller="Briefe" asp-action="Index" asp-route-id="@letter.Meta.Autopsic" asp-route-search="@Model.ActiveSearch" asp-fragment="@sr.Page-@sr.Line">
<a asp-controller="Briefe" asp-action="Index" asp-route-id="@letter.Meta.ID" asp-route-search="@Model.ActiveSearch" asp-fragment="@sr.Page-@sr.Line">
@sr.Preview
</a>
@if (Model.Marginals != null && Model.Marginals.Any()) {
@if (Model.Marginals.ContainsKey(letter.Meta.Index)) {
@foreach (var c in Model.Marginals[letter.Meta.Index]) {
@if (Model.Marginals.ContainsKey(letter.Meta.ID)) {
@foreach (var c in Model.Marginals[letter.Meta.ID]) {
@if (c.Item1.Page == sr.Page && c.Item1.Line == sr.Line) {
<div class="ha-seachresultmarginal">
<div class="ha-searchresultcommentpill">Kommentar</div>

View File

@@ -4,7 +4,7 @@
@if (!Model.Compact) {
<div class="ha-letternumber">
<div class="ha-letternumberinline">
@Model.Letter.Meta.Autopsic
@Model.Letter.Meta.ID
</div>
</div>
}
@@ -20,7 +20,7 @@
</div>
<div class="ha-metadatapersons">
@foreach(var pair in Model.Letter.SenderReceiver) {
@if (Model.Letter.Meta.isDraft == HaDocument.Models.OptionalBool.True) {
@if (Model.Letter.Meta.isDraft.HasValue && Model.Letter.Meta.isDraft.Value) {
<span>@Html.Raw(pair.Sender)</span>
<div class="ha-tooltip">

View File

@@ -18,7 +18,7 @@
</div>
}
@if (Model.Letter.Meta.hasOriginal != HaDocument.Models.OptionalBool.True) {
@if (Model.Letter.Meta.hasOriginal.HasValue && Model.Letter.Meta.hasOriginal.Value == true) {
<div class="ha-tooltip">
<div class="ha-pill">
<span class="ha-cross">Orig</span>

View File

@@ -80,13 +80,13 @@ public class WebSocketMiddleware : IMiddleware {
await webSocket.SendAsync(_SerializeToBytes(new { Ping = true}), WebSocketMessageType.Text, true, CancellationToken.None);
}
result = await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
} catch (ConnectionAbortedException ex) {
} catch (WebSocketException ex) {
_openSockets!.Remove(webSocket);
}
}
try {
await webSocket.CloseAsync(result.CloseStatus.Value, result.CloseStatusDescription, CancellationToken.None);
} catch (ConnectionAbortedException ex) {
} catch (WebSocketException ex) {
_openSockets.Remove(webSocket);
}
_openSockets!.Remove(webSocket);
@@ -127,7 +127,7 @@ public class WebSocketMiddleware : IMiddleware {
foreach (var socket in _openSockets) {
try {
await socket.SendAsync(_SerializeToBytes(msg), WebSocketMessageType.Text, true, CancellationToken.None);
} catch (ConnectionAbortedException ex) {
} catch (WebSocketException ex) {
_openSockets.Remove(socket);
}
}

View File

@@ -19,7 +19,9 @@ public interface IXMLInteractionService {
public void CreateSearchables(XDocument document); // XMLFileProvider
public Dictionary<string, SyntaxCheckModel>? Test(XMLParsingState? state, string gitcommit); // XMLFileProvider (optimal), Controller (right now)
// Controller
public List<(string Index, List<(string Page, string Line, string Preview, string Identifier)> Results)>? SearchCollection(string collection, string searchword, IReaderService reader, ILibrary? lib);
public List<(CollectedItem Item, List<(string Page, string Line, string Preview, string? Identifier)> Results)>? SearchCollection(string collection, string searchword, IReaderService reader, ILibrary? lib);
// Controller
public List<(string Index, List<(string Page, string Line, string Preview, string Identifier)> Results)>? GetPreviews(List<(string, List<Marginal>)> places, IReaderService reader, ILibrary lib);
public List<(CollectedItem Item, List<(string Page, string Line, string Preview, string? Identifier)> Results)>? GetPreviews(List<(string, List<Marginal>)> places, IReaderService reader, ILibrary lib);
public CollectedItem? GetCollectedItem(string collection, string id);
}

View File

@@ -166,10 +166,10 @@ public class XMLInteractionService : IXMLInteractionService {
return opus;
}
public List<(string Index, List<(string Page, string Line, string Preview, string Identifier)> Results)>? GetPreviews(List<(string, List<Marginal>)> places, IReaderService reader, ILibrary lib) {
if (!_Collection.ContainsKey("letters")) return null;
public List<(CollectedItem Item, List<(string Page, string Line, string Preview, string? Identifier)> Results)>? GetPreviews(List<(string, List<Marginal>)> places, IReaderService reader, ILibrary lib) {
if (_Collection == null || !_Collection.ContainsKey("letters")) return null;
var searchableObjects = _Collection["letters"].Items;
var res = new ConcurrentBag<(string Index, List<(string Page, string Line, string preview, string identifier)> Results)>();
var res = new ConcurrentBag<(CollectedItem item, List<(string Page, string Line, string preview, string? identifier)> Results)>();
Parallel.ForEach(places, (obj) => {
var text = searchableObjects[obj.Item1];
@@ -180,7 +180,7 @@ public class XMLInteractionService : IXMLInteractionService {
rd.Read();
res.Add((
obj.Item1,
text,
obj.Item2.Select(x => (
x.Page,
x.Line,
@@ -190,7 +190,7 @@ public class XMLInteractionService : IXMLInteractionService {
.Select(y => y.Text)
.FirstOrDefault(string.Empty)
: string.Empty,
String.Empty
(string?)null
) ).ToList()
));
});
@@ -198,10 +198,17 @@ public class XMLInteractionService : IXMLInteractionService {
return res.ToList();
}
public List<(string Index, List<(string Page, string Line, string Preview, string Identifier)> Results)>? SearchCollection(string collection, string searchword, IReaderService reader, ILibrary lib) {
if (!_Collection.ContainsKey(collection)) return null;
public CollectedItem? GetCollectedItem(string collection, string id) {
if (_Collection == null || !_Collection.ContainsKey(collection)) return null;
var objects = _Collection[collection].Items;
if (objects == null || !objects.ContainsKey(id)) return null;
return objects[id];
}
public List<(CollectedItem Item, List<(string Page, string Line, string Preview, string? Identifier)> Results)>? SearchCollection(string collection, string searchword, IReaderService reader, ILibrary? lib) {
if (_Collection == null || !_Collection.ContainsKey(collection)) return null;
var searchableObjects = _Collection[collection].Items;
var res = new ConcurrentBag<(string Index, List<(string Page, string Line, string preview, string identifier)> Results)>();
var res = new ConcurrentBag<(CollectedItem item, List<(string Page, string Line, string preview, string? identifier)> Results)>();
var sw = StringHelpers.NormalizeWhiteSpace(searchword.Trim());
// Non Parallel:
@@ -236,7 +243,7 @@ public class XMLInteractionService : IXMLInteractionService {
rd.Read();
if (state.Results != null)
res.Add((
obj.Value.Index,
obj.Value,
state.Results.Select(x => (
x.Page,
x.Line,
@@ -272,10 +279,7 @@ public class XMLInteractionService : IXMLInteractionService {
var searchtext = coll.Value.Searchable ?
StringHelpers.NormalizeWhiteSpace(e.ToString(), ' ', false) :
null;
var datafileds = coll.Value.GenerateDataFields != null ?
coll.Value.GenerateDataFields(e) :
null;
items[k] = new CollectedItem(k, e, coll.Value, datafileds, searchtext);
items[k] = new CollectedItem(k, e, coll.Value, searchtext);
}
}
if (items.Any()) {

View File

@@ -18,7 +18,7 @@
"BareRepositoryPathLinux": "/var/www/vhosts/development.hamann-ausgabe.de/httpdocs/Bare/",
"BareRepositoryPathWindows": "C:/Users/simon/source/hamann-xml/.git/",
"WorkingTreePathLinux": "/var/www/vhosts/development.hamann-ausgabe.de/httpdocs/Repo/",
"WorkingTreePathWindows": "C:/Users/simon/source/hamann-xml/",
"WorkingTreePathWindows": "C:/Users/simon/source/hamann-xml/transformations_2023-9-14_test/",
"RepositoryBranch": "testdata",
"RepositoryURL": "https://github.com/Theodor-Springmann-Stiftung/hamann-xml",
"StoredPDFPathWindows": "",