diff --git a/HaDocumentV6/Comparers/DefaultComparer.cs b/HaDocumentV6/Comparers/DefaultComparer.cs index 70cc53b..32e19c8 100644 --- a/HaDocumentV6/Comparers/DefaultComparer.cs +++ b/HaDocumentV6/Comparers/DefaultComparer.cs @@ -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); } } } diff --git a/HaDocumentV6/Comparers/ZHComparer.cs b/HaDocumentV6/Comparers/ZHComparer.cs index 43c9c19..022aacf 100644 --- a/HaDocumentV6/Comparers/ZHComparer.cs +++ b/HaDocumentV6/Comparers/ZHComparer.cs @@ -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 diff --git a/HaDocumentV6/HaDocumentV6.sln b/HaDocumentV6/HaDocumentV6.sln new file mode 100644 index 0000000..d91a858 --- /dev/null +++ b/HaDocumentV6/HaDocumentV6.sln @@ -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 diff --git a/HaDocumentV6/Interfaces/IHaElement.cs b/HaDocumentV6/Interfaces/IHaElement.cs new file mode 100644 index 0000000..401f046 --- /dev/null +++ b/HaDocumentV6/Interfaces/IHaElement.cs @@ -0,0 +1,5 @@ +using System.Xml.Linq; + +public interface IHaElement { + +} \ No newline at end of file diff --git a/HaDocumentV6/Interfaces/ILibrary.cs b/HaDocumentV6/Interfaces/ILibrary.cs index b156e96..9bf9802 100644 --- a/HaDocumentV6/Interfaces/ILibrary.cs +++ b/HaDocumentV6/Interfaces/ILibrary.cs @@ -11,7 +11,7 @@ namespace HaDocument.Interfaces { ImmutableDictionary Persons { get; } ImmutableDictionary Metas { get; } ImmutableDictionary ExcludedMetas { get; } - ImmutableDictionary Marginals { get; } + ImmutableDictionary> Marginals { get; } ImmutableDictionary Locations { get; } ImmutableDictionary Letters { get; } ImmutableDictionary HandPersons { get; } @@ -24,7 +24,6 @@ namespace HaDocument.Interfaces { ImmutableDictionary> CommentsByCategoryLetter { get; } Lookup CommentsByCategory { get; } - Lookup MarginalsByLetter { get; } Lookup EditreasonsByLetter { get; } ImmutableSortedSet MetasByDate { get; } ILookup MetasByYear { get; } diff --git a/HaDocumentV6/Interfaces/ISearchable.cs b/HaDocumentV6/Interfaces/ISearchable.cs deleted file mode 100644 index a10caff..0000000 --- a/HaDocumentV6/Interfaces/ISearchable.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace HaDocument.Interfaces; - -public interface ISearchable { - public string Element { get; } - public string Index { get; } -} \ No newline at end of file diff --git a/HaDocumentV6/Models/App.cs b/HaDocumentV6/Models/App.cs index 984dca0..f39c9fe 100644 --- a/HaDocumentV6/Models/App.cs +++ b/HaDocumentV6/Models/App.cs @@ -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 + ); } } } \ No newline at end of file diff --git a/HaDocumentV6/Models/Backlink.cs b/HaDocumentV6/Models/Backlink.cs index 51f1eec..6bf48b2 100644 --- a/HaDocumentV6/Models/Backlink.cs +++ b/HaDocumentV6/Models/Backlink.cs @@ -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; } } } \ No newline at end of file diff --git a/HaDocumentV6/Models/Comment.cs b/HaDocumentV6/Models/Comment.cs index a1293d0..0236b11 100644 --- a/HaDocumentV6/Models/Comment.cs +++ b/HaDocumentV6/Models/Comment.cs @@ -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; } = ""; diff --git a/HaDocumentV6/Models/Editreason.cs b/HaDocumentV6/Models/Editreason.cs index 895d1e6..e3051a5 100644 --- a/HaDocumentV6/Models/Editreason.cs +++ b/HaDocumentV6/Models/Editreason.cs @@ -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"); + } } } \ No newline at end of file diff --git a/HaDocumentV6/Models/HaModel.cs b/HaDocumentV6/Models/HaModel.cs deleted file mode 100644 index 9d944cd..0000000 --- a/HaDocumentV6/Models/HaModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using HaXMLReader.EvArgs; -using System.Collections.Generic; - -namespace HaDocument.Models { - public abstract class HaModel { - protected static List<(Func, Action)> FieldActions = null; - - internal static void AddAction(Func If, Action Then) { - if (If == null || Then == null) throw new ArgumentNullException(); - if (FieldActions == null) FieldActions = new List<(Func, Action)>(); - FieldActions.Add((If, Then)); - } - } -} diff --git a/HaDocumentV6/Models/Hand.cs b/HaDocumentV6/Models/Hand.cs index 944a40d..097bed8 100644 --- a/HaDocumentV6/Models/Hand.cs +++ b/HaDocumentV6/Models/Hand.cs @@ -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; } = ""; diff --git a/HaDocumentV6/Models/IntermediateLibrary.cs b/HaDocumentV6/Models/IntermediateLibrary.cs index f129602..bd45f69 100644 --- a/HaDocumentV6/Models/IntermediateLibrary.cs +++ b/HaDocumentV6/Models/IntermediateLibrary.cs @@ -9,7 +9,7 @@ namespace HaDocument.Models public Dictionary Persons; public Dictionary Metas; public Dictionary ExcludedMetas; - public Dictionary Marginals; + public Dictionary> Marginals; public Dictionary Locations; public Dictionary Letters; public Dictionary HandPersons; diff --git a/HaDocumentV6/Models/Letter.cs b/HaDocumentV6/Models/Letter.cs index 26bd63e..4dff311 100644 --- a/HaDocumentV6/Models/Letter.cs +++ b/HaDocumentV6/Models/Letter.cs @@ -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 + ); } } } \ No newline at end of file diff --git a/HaDocumentV6/Models/Library.cs b/HaDocumentV6/Models/Library.cs index 21a84b4..77e79e6 100644 --- a/HaDocumentV6/Models/Library.cs +++ b/HaDocumentV6/Models/Library.cs @@ -15,7 +15,7 @@ namespace HaDocument.Models public ImmutableDictionary Persons { get; } public ImmutableDictionary Metas { get; } public ImmutableDictionary ExcludedMetas { get; } - public ImmutableDictionary Marginals { get; } + public ImmutableDictionary> Marginals { get; } public ImmutableDictionary Locations { get; } public ImmutableDictionary Letters { get; } public ImmutableDictionary HandPersons { get; } @@ -35,8 +35,6 @@ namespace HaDocument.Models public Lookup CommentsByCategory { get; } // Auswählen von Subkommentaren nach ID public ImmutableDictionary SubCommentsByID { get; } - // Auswählen von Marginalien nach Briefen - public Lookup MarginalsByLetter { get; } // Ausw?hlen von Edits nach Briefen public Lookup EditreasonsByLetter { get; } // Auswählen von Briefen nach autoptischer Numemr und in zeitlich sortierter Reihenfolge. @@ -51,7 +49,7 @@ namespace HaDocument.Models Dictionary persons, Dictionary meta, Dictionary excludedMeta, - Dictionary marginals, + Dictionary> marginals, Dictionary locations, Dictionary letters, Dictionary handPersons, @@ -95,7 +93,6 @@ namespace HaDocument.Models CommentsByLetter_builder.Add(ts.Key, (Lookup)ts.ToLookup(x => x.Index.Substring(0, 1).ToUpper())); } CommentsByCategoryLetter = CommentsByLetter_builder.ToImmutableDictionary(); - MarginalsByLetter = (Lookup)Marginals.Values.ToLookup(x => x.Letter); EditreasonsByLetter = (Lookup)Editreasons.Values.ToLookup(x => x.Letter); MetasByDate = Metas.Values.ToImmutableSortedSet(new DefaultComparer()); MetasByYear = Metas.Values.ToLookup(x => x.Sort.Year); diff --git a/HaDocumentV6/Models/Location.cs b/HaDocumentV6/Models/Location.cs index 8e1db38..5a024ee 100644 --- a/HaDocumentV6/Models/Location.cs +++ b/HaDocumentV6/Models/Location.cs @@ -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 + ); } } } \ No newline at end of file diff --git a/HaDocumentV6/Models/Marginal.cs b/HaDocumentV6/Models/Marginal.cs index 2d19736..42625d4 100644 --- a/HaDocumentV6/Models/Marginal.cs +++ b/HaDocumentV6/Models/Marginal.cs @@ -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 + ); } } } \ No newline at end of file diff --git a/HaDocumentV6/Models/Meta.cs b/HaDocumentV6/Models/Meta.cs index 2c13b0c..a20d8d1 100644 --- a/HaDocumentV6/Models/Meta.cs +++ b/HaDocumentV6/Models/Meta.cs @@ -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 Senders { get; } = null; public List 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 senders, List receivers, ZHInfo ZH ) { - Index = index; - Autopsic = autopsic; + ID = id; Date = date; Sort = sort; Order = order; diff --git a/HaDocumentV6/Models/OptionalBool.cs b/HaDocumentV6/Models/OptionalBool.cs deleted file mode 100644 index bb37fdc..0000000 --- a/HaDocumentV6/Models/OptionalBool.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace HaDocument.Models -{ - public enum OptionalBool - { - True, - False, - None - } -} diff --git a/HaDocumentV6/Models/Person.cs b/HaDocumentV6/Models/Person.cs index fab0d1c..8ed0f3b 100644 --- a/HaDocumentV6/Models/Person.cs +++ b/HaDocumentV6/Models/Person.cs @@ -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 + ); } } } \ No newline at end of file diff --git a/HaDocumentV6/Models/Tradition.cs b/HaDocumentV6/Models/Tradition.cs index 2bbf85f..67b5111 100644 --- a/HaDocumentV6/Models/Tradition.cs +++ b/HaDocumentV6/Models/Tradition.cs @@ -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 + ); } } } \ No newline at end of file diff --git a/HaDocumentV6/Reactors/EditreasonReactor.cs b/HaDocumentV6/Reactors/EditreasonReactor.cs index 0a60b18..8da509d 100644 --- a/HaDocumentV6/Reactors/EditreasonReactor.cs +++ b/HaDocumentV6/Reactors/EditreasonReactor.cs @@ -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 && diff --git a/HaDocumentV6/Reactors/HandDefsReactor.cs b/HaDocumentV6/Reactors/HandDefsReactor.cs index 2144b0b..02e6d83 100644 --- a/HaDocumentV6/Reactors/HandDefsReactor.cs +++ b/HaDocumentV6/Reactors/HandDefsReactor.cs @@ -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(); @@ -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)); } } } \ No newline at end of file diff --git a/HaDocumentV6/Reactors/LetterReactor.cs b/HaDocumentV6/Reactors/LetterReactor.cs index 4a254b6..4cd53d0 100644 --- a/HaDocumentV6/Reactors/LetterReactor.cs +++ b/HaDocumentV6/Reactors/LetterReactor.cs @@ -16,7 +16,7 @@ namespace HaDocument.Reactors internal Dictionary>> 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>()); + if (!CreatedStructure.ContainsKey(tag["letter"])) + this.CreatedStructure.Add(tag["letter"], new Dictionary>()); } 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()); + if (!CreatedStructure[Letter].ContainsKey(_page)) + CreatedStructure[Letter].Add(_page, new HashSet()); } else if ( _active && @@ -100,7 +100,7 @@ namespace HaDocument.Reactors { if (_hands == null) _hands = new List(); - _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; diff --git a/HaDocumentV6/Reactors/LocationDefsReactor.cs b/HaDocumentV6/Reactors/LocationDefsReactor.cs index 878f6aa..d3102ac 100644 --- a/HaDocumentV6/Reactors/LocationDefsReactor.cs +++ b/HaDocumentV6/Reactors/LocationDefsReactor.cs @@ -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(); @@ -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)); } } } \ No newline at end of file diff --git a/HaDocumentV6/Reactors/MarginalReactor.cs b/HaDocumentV6/Reactors/MarginalReactor.cs index 5a20795..8bef552 100644 --- a/HaDocumentV6/Reactors/MarginalReactor.cs +++ b/HaDocumentV6/Reactors/MarginalReactor.cs @@ -6,12 +6,12 @@ using System; namespace HaDocument.Reactors { class MarginalReactor : Reactor { - internal Dictionary CreatedInstances; + internal Dictionary> CreatedInstances; internal Dictionary> 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(); - lib.Backlinks = new Dictionary>(); + 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()); - 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; diff --git a/HaDocumentV6/Reactors/MetaReactor.cs b/HaDocumentV6/Reactors/MetaReactor.cs index 3fa0fa4..08c0499 100644 --- a/HaDocumentV6/Reactors/MetaReactor.cs +++ b/HaDocumentV6/Reactors/MetaReactor.cs @@ -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 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 = ""; diff --git a/HaDocumentV6/Reactors/PersonDefsReactor.cs b/HaDocumentV6/Reactors/PersonDefsReactor.cs index a596fb1..7fe08ff 100644 --- a/HaDocumentV6/Reactors/PersonDefsReactor.cs +++ b/HaDocumentV6/Reactors/PersonDefsReactor.cs @@ -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)); } } } \ No newline at end of file diff --git a/HaDocumentV6/Reactors/TraditionsReactor.cs b/HaDocumentV6/Reactors/TraditionsReactor.cs index 98d37c2..43d5af6 100644 --- a/HaDocumentV6/Reactors/TraditionsReactor.cs +++ b/HaDocumentV6/Reactors/TraditionsReactor.cs @@ -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>()); + if (!CreatedStructure.ContainsKey(tag["letter"])) + this.CreatedStructure.Add(tag["letter"], new Dictionary>()); } 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()); + CreatedStructure[ID].Add(_page, new HashSet()); } } else if ( @@ -106,7 +106,7 @@ namespace HaDocument.Reactors { if (_hands == null) _hands = new List(); - _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; diff --git a/HaWeb/Controllers/BriefeContoller.cs b/HaWeb/Controllers/BriefeContoller.cs index d971e74..8d73369 100644 --- a/HaWeb/Controllers/BriefeContoller.cs +++ b/HaWeb/Controllers/BriefeContoller.cs @@ -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(); var receivers = meta.Receivers.Select(x => lib.Persons[x]).ToList() ?? new List(); var zhstring = meta.ZH != null ? HaWeb.HTMLHelpers.LetterHelpers.CreateZHString(meta) : null; diff --git a/HaWeb/Controllers/IndexController.cs b/HaWeb/Controllers/IndexController.cs index 9514eda..f246e16 100644 --- a/HaWeb/Controllers/IndexController.cs +++ b/HaWeb/Controllers/IndexController.cs @@ -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 }); diff --git a/HaWeb/Controllers/SucheController.cs b/HaWeb/Controllers/SucheController.cs index 17ee90c..ed4323e 100644 --- a/HaWeb/Controllers/SucheController.cs +++ b/HaWeb/Controllers/SucheController.cs @@ -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? 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>? parsedMarginals = null; if (resletters != null) foreach (var res in resletters) { - if (!searchResults.ContainsKey(res.Index)) - searchResults.Add(res.Index, new List()); + if (!searchResults.ContainsKey(res.Item1.ID)) + searchResults.Add(res.Item1.ID, new List()); 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()); + if (!searchResults.ContainsKey(p.Item.ID)) + searchResults.Add(p.Item.ID, new List()); 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(); } } diff --git a/HaWeb/HTMLHelpers/CommentHelper.cs b/HaWeb/HTMLHelpers/CommentHelper.cs index 68625fb..71d4c0f 100644 --- a/HaWeb/HTMLHelpers/CommentHelper.cs +++ b/HaWeb/HTMLHelpers/CommentHelper.cs @@ -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 += " ( " + blk.Page + "/" + blk.Line + " )"; linkstring += pglnstring; sb.Append(linkstring); diff --git a/HaWeb/HTMLHelpers/LinkHelper.cs b/HaWeb/HTMLHelpers/LinkHelper.cs index 36fd396..b820ad2 100644 --- a/HaWeb/HTMLHelpers/LinkHelper.cs +++ b/HaWeb/HTMLHelpers/LinkHelper.cs @@ -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 " + letter.Autopsic; + linkstring += "HKB " + letter.ID; if (tag.Values.ContainsKey("page")) { pglnstring += tag["page"]; if (tag.Values.ContainsKey("line")) { diff --git a/HaWeb/Models/CollectedItem.cs b/HaWeb/Models/CollectedItem.cs index 4d43101..2721551 100644 --- a/HaWeb/Models/CollectedItem.cs +++ b/HaWeb/Models/CollectedItem.cs @@ -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? Fields { get; private set; } - public XElement ELement { get; private set; } + public XElement Element { get; private set; } public IXMLCollection Collection { get; private set; } public IDictionary? Items { get; set; } public CollectedItem( - string index, + string id, XElement element, IXMLCollection collection, - IDictionary? 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; diff --git a/HaWeb/Program.cs b/HaWeb/Program.cs index 58d245a..c2e5645 100644 --- a/HaWeb/Program.cs +++ b/HaWeb/Program.cs @@ -63,7 +63,7 @@ ChangeToken.OnChange( ); app.UseWebSockets( new WebSocketOptions { - KeepAliveInterval = TimeSpan.FromMinutes(180) + KeepAliveInterval = TimeSpan.FromMinutes(180), }); app.UseMiddleware(); diff --git a/HaWeb/SearchHelpers/ISearchable.cs b/HaWeb/SearchHelpers/ISearchable.cs index 59e300c..e688aa2 100644 --- a/HaWeb/SearchHelpers/ISearchable.cs +++ b/HaWeb/SearchHelpers/ISearchable.cs @@ -1,6 +1,6 @@ namespace HaWeb.SearchHelpers; public interface ISearchable { - public string Index { get; } + public string ID { get; } public string? SearchText { get; } } \ No newline at end of file diff --git a/HaWeb/Settings/NodeRules/LetterDescNode.cs b/HaWeb/Settings/NodeRules/LetterDescNode.cs index 515c757..c800dd7 100644 --- a/HaWeb/Settings/NodeRules/LetterDescNode.cs +++ b/HaWeb/Settings/NodeRules/LetterDescNode.cs @@ -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)>() { }; diff --git a/HaWeb/Settings/NodeRules/LetterTextNode.cs b/HaWeb/Settings/NodeRules/LetterTextNode.cs index 0014d6a..bf7aa6e 100644 --- a/HaWeb/Settings/NodeRules/LetterTextNode.cs +++ b/HaWeb/Settings/NodeRules/LetterTextNode.cs @@ -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)>() { }; diff --git a/HaWeb/Settings/NodeRules/LetterTraditionNode.cs b/HaWeb/Settings/NodeRules/LetterTraditionNode.cs index 8c4a79f..43d7439 100644 --- a/HaWeb/Settings/NodeRules/LetterTraditionNode.cs +++ b/HaWeb/Settings/NodeRules/LetterTraditionNode.cs @@ -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)>() { }; diff --git a/HaWeb/Settings/NodeRules/MarginalNode.cs b/HaWeb/Settings/NodeRules/MarginalNode.cs index cbce3d8..713625e 100644 --- a/HaWeb/Settings/NodeRules/MarginalNode.cs +++ b/HaWeb/Settings/NodeRules/MarginalNode.cs @@ -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)>() { }; diff --git a/HaWeb/Settings/NodeRules/StructureCollection.cs b/HaWeb/Settings/NodeRules/StructureCollection.cs index d08c343..f971f65 100644 --- a/HaWeb/Settings/NodeRules/StructureCollection.cs +++ b/HaWeb/Settings/NodeRules/StructureCollection.cs @@ -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()) { diff --git a/HaWeb/Settings/ParsingRules/TextRules.cs b/HaWeb/Settings/ParsingRules/TextRules.cs index b43d666..fae1b27 100644 --- a/HaWeb/Settings/ParsingRules/TextRules.cs +++ b/HaWeb/Settings/ParsingRules/TextRules.cs @@ -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)); diff --git a/HaWeb/Settings/XMLCollections/BacklinkCollection.cs b/HaWeb/Settings/XMLCollections/BacklinkCollection.cs index 2f7d28b..77bc878 100644 --- a/HaWeb/Settings/XMLCollections/BacklinkCollection.cs +++ b/HaWeb/Settings/XMLCollections/BacklinkCollection.cs @@ -14,24 +14,26 @@ public class BackLinkCollection : HaWeb.XMLParser.IXMLCollection { public bool Searchable { get; } = true; public static Func 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? GetDataFields(XElement element) { var res = new Dictionary(); 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); diff --git a/HaWeb/Settings/XMLCollections/CommentCollections.cs b/HaWeb/Settings/XMLCollections/CommentCollections.cs index 25a7666..39c3ede 100644 --- a/HaWeb/Settings/XMLCollections/CommentCollections.cs +++ b/HaWeb/Settings/XMLCollections/CommentCollections.cs @@ -22,9 +22,9 @@ public static class CommentCollectionHelpers { public static IDictionary>? GetLookups(IEnumerable items) { var res = new Dictionary>(); - 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()) diff --git a/HaWeb/Settings/XMLCollections/LetterCollection.cs b/HaWeb/Settings/XMLCollections/LetterCollection.cs index 322dbdf..dfc8c9b 100644 --- a/HaWeb/Settings/XMLCollections/LetterCollection.cs +++ b/HaWeb/Settings/XMLCollections/LetterCollection.cs @@ -13,7 +13,7 @@ public class LetterCollection : HaWeb.XMLParser.IXMLCollection { public bool Searchable { get; } = true; public static Func 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; diff --git a/HaWeb/Settings/XMLCollections/MarginalCollection.cs b/HaWeb/Settings/XMLCollections/MarginalCollection.cs index a57f06f..ce7f1f4 100644 --- a/HaWeb/Settings/XMLCollections/MarginalCollection.cs +++ b/HaWeb/Settings/XMLCollections/MarginalCollection.cs @@ -13,9 +13,14 @@ public class MarginalCollection : HaWeb.XMLParser.IXMLCollection { public bool Searchable { get; } = true; public static Func 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; } diff --git a/HaWeb/Settings/XMLCollections/MetaCollection.cs b/HaWeb/Settings/XMLCollections/MetaCollection.cs index ce7ae6b..8b0c8e1 100644 --- a/HaWeb/Settings/XMLCollections/MetaCollection.cs +++ b/HaWeb/Settings/XMLCollections/MetaCollection.cs @@ -13,7 +13,7 @@ public class MetaCollection : HaWeb.XMLParser.IXMLCollection { public bool Searchable { get; } = false; public static Func 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; diff --git a/HaWeb/Settings/XMLCollections/TraditionCollection.cs b/HaWeb/Settings/XMLCollections/TraditionCollection.cs index 2089be3..5b82a4d 100644 --- a/HaWeb/Settings/XMLCollections/TraditionCollection.cs +++ b/HaWeb/Settings/XMLCollections/TraditionCollection.cs @@ -13,7 +13,7 @@ public class TraditionCollection : HaWeb.XMLParser.IXMLCollection { public bool Searchable { get; } = true; public static Func 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; diff --git a/HaWeb/Views/HKB/Dynamic/Briefe.cshtml b/HaWeb/Views/HKB/Dynamic/Briefe.cshtml index 75a8d43..3511a90 100644 --- a/HaWeb/Views/HKB/Dynamic/Briefe.cshtml +++ b/HaWeb/Views/HKB/Dynamic/Briefe.cshtml @@ -53,7 +53,7 @@ { -
Brief @Model.MetaData.Meta.Autopsic
+
Brief @Model.MetaData.Meta.ID
} @@ -73,7 +73,7 @@ @if (Model.MetaData.Prev != null) { - @Model.MetaData.Prev.Value.Model.Meta.Autopsic ◀ + @Model.MetaData.Prev.Value.Model.Meta.ID ◀ } @@ -84,7 +84,7 @@ @if (Model.MetaData.Next != null) { - ▶ @Model.MetaData.Next.Value.Model.Meta.Autopsic + ▶ @Model.MetaData.Next.Value.Model.Meta.ID } diff --git a/HaWeb/Views/HKB/Dynamic/Index.cshtml b/HaWeb/Views/HKB/Dynamic/Index.cshtml index 5452cad..875bd22 100644 --- a/HaWeb/Views/HKB/Dynamic/Index.cshtml +++ b/HaWeb/Views/HKB/Dynamic/Index.cshtml @@ -56,7 +56,7 @@ @foreach (var year in Model.Letters) { foreach (var letter in year.LetterList) { diff --git a/HaWeb/Views/HKB/Dynamic/Suche.cshtml b/HaWeb/Views/HKB/Dynamic/Suche.cshtml index 9d5bfb5..47e6be8 100644 --- a/HaWeb/Views/HKB/Dynamic/Suche.cshtml +++ b/HaWeb/Views/HKB/Dynamic/Suche.cshtml @@ -84,27 +84,27 @@ @foreach (var year in Model.Letters) { foreach (var letter in year.LetterList) {
- + @Html.Partial("/Views/Shared/_LetterHead.cshtml", (letter, true, false)) - @if (Model.SearchResults != null && Model.SearchResults.ContainsKey(letter.Meta.Index)) { + @if (Model.SearchResults != null && Model.SearchResults.ContainsKey(letter.Meta.ID)) {
- @foreach (var sr in Model.SearchResults[letter.Meta.Index]) + @foreach (var sr in Model.SearchResults[letter.Meta.ID]) {
- + @sr.Preview @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) {
Kommentar
diff --git a/HaWeb/Views/Shared/_LetterHead.cshtml b/HaWeb/Views/Shared/_LetterHead.cshtml index cf2d7f3..ee57029 100644 --- a/HaWeb/Views/Shared/_LetterHead.cshtml +++ b/HaWeb/Views/Shared/_LetterHead.cshtml @@ -4,7 +4,7 @@ @if (!Model.Compact) {
- @Model.Letter.Meta.Autopsic + @Model.Letter.Meta.ID
} @@ -20,7 +20,7 @@
@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) { @Html.Raw(pair.Sender)
↛ diff --git a/HaWeb/Views/Shared/_Pills.cshtml b/HaWeb/Views/Shared/_Pills.cshtml index ba32432..4546dae 100644 --- a/HaWeb/Views/Shared/_Pills.cshtml +++ b/HaWeb/Views/Shared/_Pills.cshtml @@ -18,7 +18,7 @@
} - @if (Model.Letter.Meta.hasOriginal != HaDocument.Models.OptionalBool.True) { + @if (Model.Letter.Meta.hasOriginal.HasValue && Model.Letter.Meta.hasOriginal.Value == true) {
Orig diff --git a/HaWeb/WebSockets/WebSocketMiddleware.cs b/HaWeb/WebSockets/WebSocketMiddleware.cs index 6858e52..bafc314 100644 --- a/HaWeb/WebSockets/WebSocketMiddleware.cs +++ b/HaWeb/WebSockets/WebSocketMiddleware.cs @@ -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(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); } } diff --git a/HaWeb/XMLParser/IXMLInteractionService.cs b/HaWeb/XMLParser/IXMLInteractionService.cs index d46c91b..9a78119 100644 --- a/HaWeb/XMLParser/IXMLInteractionService.cs +++ b/HaWeb/XMLParser/IXMLInteractionService.cs @@ -19,7 +19,9 @@ public interface IXMLInteractionService { public void CreateSearchables(XDocument document); // XMLFileProvider public Dictionary? 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)> places, IReaderService reader, ILibrary lib); + public List<(CollectedItem Item, List<(string Page, string Line, string Preview, string? Identifier)> Results)>? GetPreviews(List<(string, List)> places, IReaderService reader, ILibrary lib); + + public CollectedItem? GetCollectedItem(string collection, string id); } \ No newline at end of file diff --git a/HaWeb/XMLParser/XMLInteractionService.cs b/HaWeb/XMLParser/XMLInteractionService.cs index bbf7c0b..2133898 100644 --- a/HaWeb/XMLParser/XMLInteractionService.cs +++ b/HaWeb/XMLParser/XMLInteractionService.cs @@ -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)> 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)> 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()) { diff --git a/HaWeb/appsettings.Development.json b/HaWeb/appsettings.Development.json index a62a36b..52e886b 100644 --- a/HaWeb/appsettings.Development.json +++ b/HaWeb/appsettings.Development.json @@ -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": "",