CMIF implementiert

This commit is contained in:
Simon Martens
2024-11-18 17:25:09 +01:00
parent 822cad09de
commit 6f2a276772
9 changed files with 419 additions and 31 deletions

View File

@@ -3,10 +3,34 @@ using System.Collections.Generic;
using HaXMLReader.EvArgs;
namespace HaDocument.Models {
public class AdditionalDates {
public DateTime? NotBefore { get; } = null;
public DateTime? NotAfter { get; } = null;
public DateTime? From { get; } = null;
public DateTime? To { get; } = null;
public string? Cert { get; } = null;
public AdditionalDates(
DateTime? notBefore,
DateTime? notAfter,
DateTime? from,
DateTime? to,
string? cert
) {
NotBefore = notBefore;
NotAfter = notAfter;
From = from;
To = to;
Cert = cert;
}
}
public class Meta {
public string ID { get; } = "";
public string Date { get; } = "";
public DateTime Sort { get; } = new DateTime(1700, 1, 1);
public AdditionalDates? AdditionalDates { get; } = null;
public int Order { get; } = -1;
public string Location { get; } = "";
public List<string> Senders { get; } = null;
@@ -14,12 +38,12 @@ namespace HaDocument.Models {
public bool? hasOriginal { get; }
public bool? isProofread { get; }
public bool? isDraft { get; }
public ZHInfo ZH { get; } = null;
public ZHInfo? ZH { get; } = null;
public Meta(
string id,
string date,
DateTime sort,
string id,
string date,
DateTime sort,
int order,
bool? hasOriginal,
bool? isProofread,
@@ -27,7 +51,8 @@ namespace HaDocument.Models {
string location,
List<string> senders,
List<string> receivers,
ZHInfo ZH
ZHInfo? ZH,
AdditionalDates? additionalDates = null
) {
ID = id;
Date = date;
@@ -40,7 +65,8 @@ namespace HaDocument.Models {
this.isProofread = isProofread;
this.isDraft = isDraft;
this.ZH = ZH;
this.AdditionalDates = additionalDates;
}
}
}
}

View File

@@ -8,6 +8,7 @@ namespace HaDocument.Models {
public string? Surname { get; }
public string? Komm { get; }
public string? Reference { get; }
public bool IsOrg { get; } = false;
public XElement? XElement { get; }
public Person(
@@ -17,7 +18,8 @@ namespace HaDocument.Models {
string? surname,
string? komm,
string? reference,
XElement? xElement = null
XElement? xElement = null,
bool IsOrg = false
) {
Index = index;
Name = name;
@@ -25,11 +27,14 @@ namespace HaDocument.Models {
Surname = surname;
Komm = komm;
Reference = reference;
this.XElement = xElement;
this.IsOrg = IsOrg;
}
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;
var org = element.HasAttributes && element.Attribute("org")?.Value == "true";
return new Person(
element.Attribute("index")!.Value,
element.Attribute("name")!.Value,
@@ -37,8 +42,9 @@ namespace HaDocument.Models {
element.Attribute("nachname")?.Value,
element.Attribute("komm")?.Value,
element.Attribute("ref")?.Value,
element
element,
org
);
}
}
}
}

View File

@@ -25,7 +25,8 @@ namespace HaDocument.Reactors {
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 AdditionalDates? AdditionalDates { get; set; } = null;
private bool dateChanged { get; set; } = false;
private string Location { get; set; } = "";
private List<string> Senders { get; set; } = null;
private List<string> Receivers { get; set; } = null;
@@ -42,9 +43,9 @@ namespace HaDocument.Reactors {
protected override void Listen(object sender, Tag tag) {
if (
!tag.EndTag &&
!tag.EndTag &&
!tag.IsEmpty &&
tag.Name =="letterDesc" &&
tag.Name == "letterDesc" &&
!String.IsNullOrWhiteSpace(tag["letter"])
) {
Activate(_reader, tag);
@@ -52,7 +53,7 @@ namespace HaDocument.Reactors {
}
protected override void Activate(IReader reader, Tag tag) {
if (!_active && reader != null && tag != null) {
if (!_active && reader != null && tag != null) {
Reset();
_active = true;
ID = tag["letter"];
@@ -76,8 +77,7 @@ namespace HaDocument.Reactors {
}
private void OnTag(object _, Tag tag) {
switch (tag.Name)
{
switch (tag.Name) {
case "begin":
Page = tag["page"];
Volume = tag["vol"];
@@ -101,6 +101,14 @@ namespace HaDocument.Reactors {
int res2 = 0;
Int32.TryParse(tag["order"], out res2);
Order = res2;
AdditionalDates = new AdditionalDates(
GetDateTime(tag["notBefore"]),
GetDateTime(tag["notAfter"]),
GetDateTime(tag["from"]),
GetDateTime(tag["to"]),
tag["cert"]
);
break;
case "hasOriginal":
var val = tag["value"];
@@ -135,10 +143,10 @@ namespace HaDocument.Reactors {
}
break;
case "dateChanged":
dateChanged = tag["value"].ToLower() == "true" ? true : false;
dateChanged = tag["value"].ToLower() == "true" ? true : false;
break;
case "alternativeLineNumbering":
AltLineNumbering = tag["value"].ToLower() == "true" ? true : false;
AltLineNumbering = tag["value"].ToLower() == "true" ? true : false;
break;
case "letterDesc":
if (tag.EndTag) Deactivate();
@@ -148,6 +156,11 @@ namespace HaDocument.Reactors {
private void Add() {
var ZHInfo = !inZH ? null : new ZHInfo(AltLineNumbering, dateChanged, Volume, Page);
if (AdditionalDates != null) {
if (AdditionalDates.NotBefore == null && AdditionalDates.NotAfter == null && AdditionalDates.From == null && AdditionalDates.To == null && AdditionalDates.Cert == null) {
AdditionalDates = null;
}
}
var meta = new Meta(
ID,
Date,
@@ -159,7 +172,8 @@ namespace HaDocument.Reactors {
Location,
Senders,
Receivers,
ZHInfo
ZHInfo,
AdditionalDates
);
if (
_availableVolumes.Contains(Volume) ||
@@ -179,6 +193,7 @@ namespace HaDocument.Reactors {
isProofread = null;
isDraft = null;
dateChanged = false;
AdditionalDates = null;
ID = "";
Volume = "";
Page = "";
@@ -190,5 +205,12 @@ namespace HaDocument.Reactors {
Senders = new List<string>();
Receivers = new List<string>();
}
private DateTime? GetDateTime(string date) {
DateTime res;
var ret = System.DateTime.TryParse(date, out res);
if (ret) return res;
else return null;
}
}
}
}

View File

@@ -17,6 +17,7 @@ namespace HaDocument.Reactors {
private string Surname = "";
private string? Reference;
private string? Komm;
private bool IsOrg = false;
internal PersonDefsReactor(IReader reader, IntermediateLibrary lib) : base(reader, lib) {
lib.Persons = new Dictionary<string, Person>();
@@ -25,9 +26,9 @@ namespace HaDocument.Reactors {
}
protected override void Listen(object sender, Tag tag) {
if (!tag.EndTag &&
if (!tag.EndTag &&
tag.IsEmpty &&
tag.Name == "personDef" &&
tag.Name == "personDef" &&
!String.IsNullOrWhiteSpace(tag["index"]) &&
!String.IsNullOrWhiteSpace(tag["name"])
) {
@@ -44,6 +45,7 @@ namespace HaDocument.Reactors {
Prename = tag["vorname"];
Surname = tag["nachname"];
Reference = String.IsNullOrWhiteSpace(tag["ref"]) ? null : tag["ref"];
IsOrg = tag["org"] == "true";
if (!String.IsNullOrWhiteSpace(tag["komm"])) Komm = tag["komm"];
Add();
_active = false;
@@ -57,10 +59,11 @@ namespace HaDocument.Reactors {
Surname = "";
Reference = null;
Komm = null;
IsOrg = false;
}
public void Add() {
CreatedInstances.Add(Index, new Person(Index, Name, Prename, Surname, Komm, Reference));
CreatedInstances.Add(Index, new Person(Index, Name, Prename, Surname, Komm, Reference, null, IsOrg));
}
}
}
}