mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-29 09:15:33 +00:00
Initial replacement of old repository.
This commit is contained in:
24
HamannPrinter/.vscode/launch.json
vendored
Normal file
24
HamannPrinter/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.0/HamannPrinter.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"console": "internalConsole",
|
||||
"stopAtEntry": false
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach"
|
||||
}
|
||||
]
|
||||
}
|
||||
42
HamannPrinter/.vscode/tasks.json
vendored
Normal file
42
HamannPrinter/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/HamannPrinter.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "publish",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"publish",
|
||||
"${workspaceFolder}/HamannPrinter.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "watch",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"watch",
|
||||
"run",
|
||||
"${workspaceFolder}/HamannPrinter.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
9
HamannPrinter/App.xaml
Normal file
9
HamannPrinter/App.xaml
Normal file
@@ -0,0 +1,9 @@
|
||||
<Application x:Class="HamannPrinter.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:HamannPrinter"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
17
HamannPrinter/App.xaml.cs
Normal file
17
HamannPrinter/App.xaml.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace HamannPrinter
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
}
|
||||
15
HamannPrinter/Confix.cs
Normal file
15
HamannPrinter/Confix.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace HamannPrinter
|
||||
{
|
||||
public class Confix
|
||||
{
|
||||
public bool? LettersDocx { get; set; }
|
||||
public bool? VolumeDocx { get; set; }
|
||||
public bool? RegisterDocx { get; set; }
|
||||
public string HamannXmlPath { get; set; }
|
||||
public string OutputPath { get; set; }
|
||||
public (int, int) Years { get; set; }
|
||||
public string Editionsrichtlinien { get; set; }
|
||||
}
|
||||
}
|
||||
BIN
HamannPrinter/DocumentFormat.OpenXml.dll
Normal file
BIN
HamannPrinter/DocumentFormat.OpenXml.dll
Normal file
Binary file not shown.
39
HamannPrinter/DocxToPdf.Designer.cs
generated
Normal file
39
HamannPrinter/DocxToPdf.Designer.cs
generated
Normal file
@@ -0,0 +1,39 @@
|
||||
namespace HamannPrinter
|
||||
{
|
||||
partial class DocxToPdf
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "DocxToPdf";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
18
HamannPrinter/DocxToPdf.cs
Normal file
18
HamannPrinter/DocxToPdf.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace HamannPrinter
|
||||
{
|
||||
public partial class DocxToPdf : Form
|
||||
{
|
||||
public DocxToPdf()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
2667
HamannPrinter/Hamann2Word.cs
Normal file
2667
HamannPrinter/Hamann2Word.cs
Normal file
File diff suppressed because it is too large
Load Diff
22
HamannPrinter/HamannPrinter.csproj
Normal file
22
HamannPrinter/HamannPrinter.csproj
Normal file
@@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<UseWPF>true</UseWPF>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\HaDocument\HaDocument.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="DocumentFormat.OpenXml">
|
||||
<HintPath>DocumentFormat.OpenXml.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Office.Interop.Word">
|
||||
<HintPath>Microsoft.Office.Interop.Word.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
778
HamannPrinter/Helper.cs
Normal file
778
HamannPrinter/Helper.cs
Normal file
@@ -0,0 +1,778 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Xml.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using static HamannPrinter.Hamann2Word;
|
||||
using static HamannPrinter.Parser;
|
||||
using Comment = HaDocument.Models.Comment;
|
||||
|
||||
namespace HamannPrinter
|
||||
{
|
||||
static class Helper
|
||||
{
|
||||
|
||||
public static void Warn(string message)
|
||||
{
|
||||
MessageBox.Show(message,
|
||||
"Confirmation",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Exclamation);
|
||||
}
|
||||
|
||||
public static void Ok(string message)
|
||||
{
|
||||
MessageBox.Show(message,
|
||||
"Confirmation",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Asterisk);
|
||||
}
|
||||
|
||||
public static MessageBoxResult SayYesNo(string message)
|
||||
{
|
||||
var result = MessageBox.Show(message,
|
||||
"Confirmation",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String MakeZHString(LetterObj letter, bool withZH)
|
||||
{
|
||||
// TODO ONLY IF ZH != mull
|
||||
if (letter.Meta.ZH != null)
|
||||
{
|
||||
string bd = GetRoman(letter.Meta.ZH.Volume);
|
||||
string lastPg = GetLastPg(letter);
|
||||
string firstPg = letter.Meta.ZH.Page;
|
||||
string zh = withZH ? "ZH\u202F" : "";
|
||||
if (lastPg == null || lastPg == firstPg)
|
||||
{
|
||||
zh += bd + " " + firstPg;
|
||||
}
|
||||
else
|
||||
{
|
||||
zh += bd + " " + firstPg + "\u2012" + lastPg;
|
||||
}
|
||||
return zh;
|
||||
}
|
||||
else if (withZH)
|
||||
{
|
||||
return "nicht in ZH";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static WordprocessingDocument CreateOutputFile(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
var WordDoc = WordprocessingDocument.Create(path, WordprocessingDocumentType.Document);
|
||||
return WordDoc;
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
Logger.Out("Die Datei " + path + " kann nicht erstellt werden. Vielleicht ist sie geöffnet?\nBitte schließen und enter Drücken oder das Programm schließen.");
|
||||
Warn("Die Datei " + path + " kann nicht erstellt werden. Vielleicht ist sie geöffnet?\nBitte schließen und enter Drücken oder das Programm schließen.");
|
||||
return CreateOutputFile(path);
|
||||
}
|
||||
}
|
||||
public static void MakeFinalPageBreak(LetterObj letter)
|
||||
{
|
||||
var srcPara = new Paragraph(new Run(new Break() { Type = BreakValues.Page }));
|
||||
GetLastPara(letter.WordDoc).InsertAfterSelf(srcPara);
|
||||
}
|
||||
|
||||
public static void CorrectMarginLastSection(WordprocessingDocument Doc, bool nostandartlayout = false)
|
||||
{
|
||||
/*Das muss nach den footern angefügt werden, ich habe keine Ahnung, warum; eigentlich MUSS das auch vorher eingefügt werden können. Ich bin auf jeden Fall unfähig
|
||||
das richtig zu tun und füge diese Foramtierung für die letzte section hier ein, weil sonst komische leerseiten am ende der Dokumente auftauchen.*/
|
||||
//sectionproperties erzeugen
|
||||
SectionProperties sectionProperties = Doc.MainDocumentPart.Document.Body.AppendChild<SectionProperties>(new SectionProperties());
|
||||
//Seitenränder definieren
|
||||
if (nostandartlayout)
|
||||
{
|
||||
PageMargin pageMargin = new PageMargin() { Top = MarginTop, Right = MarginLeft, Bottom = MarginBottom, Left = MarginLeft, Footer = MarginFooter };
|
||||
sectionProperties.PrependChild(pageMargin);
|
||||
}
|
||||
else
|
||||
{
|
||||
PageMargin pageMargin = new PageMargin() { Top = MarginTop, Right = MarginRight, Bottom = MarginBottom, Left = MarginLeft, Footer = MarginFooter };
|
||||
sectionProperties.PrependChild(pageMargin);
|
||||
}
|
||||
//Columnen bestimmen
|
||||
sectionProperties.PrependChild<Columns>(new Columns() { ColumnCount = 1 });
|
||||
sectionProperties.AppendChild<SectionType>(new SectionType() { Val = SectionMarkValues.Continuous });
|
||||
var cols = sectionProperties.GetFirstChild<Columns>();
|
||||
cols.ColumnCount = 1;
|
||||
}
|
||||
|
||||
public static Paragraph GetLastPara(WordprocessingDocument wordDoc)
|
||||
{
|
||||
Paragraph lastParagraph = wordDoc.MainDocumentPart.Document.Body.Elements<Paragraph>().Last();
|
||||
return lastParagraph;
|
||||
}
|
||||
|
||||
public static string GetLastPg(LetterObj letter)
|
||||
{
|
||||
string page = null;
|
||||
if (letter.Text.Descendants("page").Any() && letter.Text.Descendants("page").Last().Attributes("autopsic").Any())
|
||||
page = letter.Text.Descendants("page").Last().Attribute("autopsic").Value;
|
||||
else if (letter.Text.Descendants("page").Any() && letter.Text.Descendants("page").Last().Attributes("index").Any())
|
||||
page = letter.Text?.Descendants("page")?.LastOrDefault()?.Attribute("index").Value;
|
||||
else
|
||||
page = null;
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
public static string GetRoman(string index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case "1":
|
||||
return "I";
|
||||
case "2":
|
||||
return "II";
|
||||
case "3":
|
||||
return "III";
|
||||
case "4":
|
||||
return "IV";
|
||||
case "5":
|
||||
return "V";
|
||||
case "6":
|
||||
return "VI";
|
||||
case "7":
|
||||
return "VII";
|
||||
default:
|
||||
Logger.Out("Kann BandZahl " + index + "nicht in römische Zahl auflösen.");
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetHighestParentNode(XNode xnode)
|
||||
{
|
||||
while (xnode.Parent != null)
|
||||
{
|
||||
xnode = xnode.Parent;
|
||||
}
|
||||
XElement xelem = xnode as XElement;
|
||||
return xelem.Name.LocalName;
|
||||
}
|
||||
|
||||
public static string GetPerson(string index)
|
||||
{
|
||||
var person = Letters.Persons[index];//.Where(x => x.Value.Index == index).First().Value;
|
||||
if (Letters.Persons.Where(x => x.Value.Index == index).First().Key != person.Index)
|
||||
{
|
||||
Logger.Out(Letters.Persons.Where(x => x.Value.Index == index).First().Key + " Index laut val= " + person.Index);
|
||||
}
|
||||
return person.Name;
|
||||
}
|
||||
|
||||
public static string GetPageXisOn(XElement lineElement, LetterObj letter)
|
||||
{
|
||||
string page = "";
|
||||
if (lineElement.ElementsBeforeSelf().Count() == 0 || lineElement.ElementsBeforeSelf().LastOrDefault(x => x.Name.LocalName == "page") == null)
|
||||
{
|
||||
// TODO: Only if ZH != Null
|
||||
page = letter.Meta.ZH.Page;
|
||||
}
|
||||
else
|
||||
{
|
||||
var pageTag = lineElement.ElementsBeforeSelf()?.Last(x => x.Name.LocalName == "page");
|
||||
page = pageTag.Attribute("autopsic").Value;
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
public static string GetPageAndLine(XElement editTag, LetterObj letter)
|
||||
{
|
||||
string line = "";
|
||||
var lineTag = GetLineXisIn(editTag);
|
||||
line = lineTag.Attribute("autopsic").Value;
|
||||
|
||||
string page = GetPageXisOn(lineTag, letter);
|
||||
return (page + ", " + line + ": ");
|
||||
}
|
||||
|
||||
static public Comment GetComment(XElement xelem)
|
||||
{
|
||||
//ref und subref id beziehen
|
||||
string refer = xelem.Attribute("ref").Value;
|
||||
string subref = xelem?.Attribute("subref")?.Value;
|
||||
Comment comm;
|
||||
//checken ob der ref als key in der kommentarliste existier
|
||||
if (Letters.Comments.ContainsKey(refer))
|
||||
{
|
||||
comm = Letters.Comments[refer];
|
||||
if (subref != null)
|
||||
{
|
||||
comm = GetSubcomment(comm, subref);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (subref != null && Letters.Comments.ContainsKey(subref))
|
||||
{
|
||||
comm = Letters.Comments[subref];
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Out("refer " + refer + "\nund subref " + subref + " existiert nicht als key in den comments.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return comm;
|
||||
}
|
||||
|
||||
public static Comment GetSubcomment(Comment comm, string subref)
|
||||
{
|
||||
Comment subcomm;
|
||||
if (comm.Kommentare.ContainsKey(subref))
|
||||
{
|
||||
subcomm = comm.Kommentare[subref];
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Out("subref " + subref + " existiert nicht als key in comments.");
|
||||
return null;
|
||||
}
|
||||
return subcomm;
|
||||
}
|
||||
|
||||
public static bool CheckIfTextnode(XElement xelem)
|
||||
{
|
||||
bool truth = false;
|
||||
string str = "";
|
||||
XNode xnode = xelem as XNode;
|
||||
var prev = xnode.PreviousNode;
|
||||
if (prev != null)
|
||||
{
|
||||
if (prev is XText)
|
||||
{
|
||||
str = (prev as XText).Value;
|
||||
Regex regex = new Regex("[Vv]gl\\.[ <]");
|
||||
Match match = regex.Match(str);
|
||||
return match.Success;
|
||||
}
|
||||
}
|
||||
return truth;
|
||||
}
|
||||
|
||||
public static bool CheckIfIntlinkBefore(XElement xelem)
|
||||
{
|
||||
bool truth = false;
|
||||
if (xelem.ElementsBeforeSelf().Any() && xelem.ElementsBeforeSelf().Last().Name.LocalName == "intlink")
|
||||
{
|
||||
truth = true;
|
||||
}
|
||||
return truth;
|
||||
}
|
||||
|
||||
public static string RemoveWhiteSpaceEditkomm(string str)
|
||||
{
|
||||
Regex regex = new Regex("(<\\s?editreason\\s?index\\s?=\\s?\"[0-9]*\"\\s?>)\\s+");
|
||||
Match match = regex.Match(str);
|
||||
if (match.Success)
|
||||
{
|
||||
return regex.Replace(str, "$1");
|
||||
}
|
||||
else
|
||||
{
|
||||
return str;
|
||||
}
|
||||
}
|
||||
public static string RemoveWhiteSpaceLinebreak(string str)
|
||||
{
|
||||
Regex regex = new Regex("(<line type=\\s?\"break\"\\s?/>)\\s*");
|
||||
Match match = regex.Match(str);
|
||||
if (match.Success)
|
||||
{
|
||||
return regex.Replace(str, "$1");
|
||||
}
|
||||
else
|
||||
{
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
public static string RemoveEdits(string str)
|
||||
{
|
||||
Regex openEdit = new Regex("<edit\\s?ref=\"[0-9]*\">");
|
||||
Match openMatch = openEdit.Match(str);
|
||||
Regex closeEdit = new Regex("</edit>");
|
||||
Match closeMatch = openEdit.Match(str);
|
||||
if (closeMatch.Success && openMatch.Success)
|
||||
{
|
||||
str = closeEdit.Replace(str, "");
|
||||
str = openEdit.Replace(str, "");
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public static bool CheckForContent(Paragraph para)
|
||||
{
|
||||
string text = para.Elements<Run>().Aggregate("", (ttext, r) => ttext += r.InnerText);
|
||||
if (text.Length > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void CheckLineTag(XElement xelem, WordprocessingDocument wordDoc)
|
||||
{
|
||||
|
||||
bool isFootNote = false;
|
||||
Paragraph newOne = null;
|
||||
|
||||
if (xelem.Ancestors().Any() && xelem.Ancestors().Where(x => x.Name.LocalName == "fn").Any())
|
||||
{
|
||||
isFootNote = true;
|
||||
}
|
||||
|
||||
if (xelem.Attribute("index") != null)
|
||||
{
|
||||
//coutable: Zeile ist eine der zu zählenden 5er Zeilen
|
||||
bool isCountable = CheckIndex(xelem);
|
||||
bool isTabulated = CheckIfTab(xelem);
|
||||
if (isCountable & isTabulated)
|
||||
{
|
||||
IfLine5(wordDoc, xelem, Int32.Parse(xelem.Attribute("index").Value));
|
||||
IfTab(wordDoc, xelem, isFootNote);
|
||||
return;
|
||||
}
|
||||
else if (isTabulated)
|
||||
{
|
||||
IfTab(wordDoc, xelem, isFootNote);
|
||||
return;
|
||||
|
||||
}
|
||||
else if (isCountable)
|
||||
{
|
||||
Paragraph counter = IfLine5(wordDoc, xelem, Int32.Parse(xelem.Attribute("index").Value));
|
||||
newOne = counter.InsertAfterSelf<Paragraph>(new Paragraph());
|
||||
}
|
||||
else
|
||||
{
|
||||
Paragraph lastParagraph = GetLastPara(wordDoc);
|
||||
newOne = lastParagraph.InsertAfterSelf<Paragraph>(new Paragraph());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Paragraph lastParagraph = GetLastPara(wordDoc);
|
||||
newOne = lastParagraph.InsertAfterSelf<Paragraph>(new Paragraph());
|
||||
}
|
||||
|
||||
if (newOne != null)
|
||||
{
|
||||
if (isFootNote)
|
||||
{
|
||||
ApplyParaStyle(newOne, "fußnote");
|
||||
}
|
||||
else
|
||||
{
|
||||
ApplyParaStyle(newOne, "stumpf");
|
||||
CheckLineType(xelem, newOne);
|
||||
}
|
||||
}
|
||||
else { Logger.Out("bei\n" + xelem + "\nist der neue Para 0"); }
|
||||
}
|
||||
|
||||
public static void CheckLineType(XElement xelem, Paragraph para)
|
||||
{
|
||||
if (xelem.Attribute("type") != null)
|
||||
{
|
||||
if (xelem.Attribute("type").Value == "twoStars")
|
||||
{
|
||||
para.AppendChild(new Run(new Text("**")));
|
||||
para.ParagraphProperties.AppendChild(new Justification() { Val = JustificationValues.Center });
|
||||
}
|
||||
if (xelem.Attribute("type").Value == "threeStars")
|
||||
{
|
||||
para.AppendChild(new Run(new Text("***")));
|
||||
para.ParagraphProperties.AppendChild(new Justification() { Val = JustificationValues.Center });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CheckIndex(XElement xelem)
|
||||
{
|
||||
if (xelem.Attribute("index") != null)
|
||||
{
|
||||
int number = 0;
|
||||
if (Int32.TryParse(xelem.Attribute("index").Value, out number))
|
||||
{
|
||||
if (number % 5 == 0 && number != 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CheckIfTab(XElement xelem)
|
||||
{
|
||||
if (xelem.Attribute("tab") != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void IfTab(WordprocessingDocument wordDoc, XElement xelem, bool fn = false)
|
||||
{
|
||||
//stellt die korrekten einzüge für tab/fn Zeilen her
|
||||
Paragraph lastParagraph = GetLastPara(wordDoc);
|
||||
int tabval = Int32.Parse(xelem.Attribute("tab").Value);
|
||||
Paragraph newLastParagraph = lastParagraph.InsertAfterSelf<Paragraph>(new Paragraph());
|
||||
ApplyParaStyle(newLastParagraph, "stumpf");
|
||||
CheckLineType(xelem, newLastParagraph);
|
||||
lastParagraph = newLastParagraph;
|
||||
switch (tabval)
|
||||
{
|
||||
case 1:
|
||||
if (fn == false)
|
||||
{
|
||||
ApplyParaStyle(lastParagraph, "einzug");
|
||||
}
|
||||
if (fn == true)
|
||||
{
|
||||
ApplyParaStyle(lastParagraph, "fußnote");
|
||||
lastParagraph.ParagraphProperties.AppendChild(new Indentation() { Left = MiddleLineHight });
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
ApplyParaStyle(lastParagraph, "doppeleinzug");
|
||||
break;
|
||||
case 3:
|
||||
ApplyParaStyle(lastParagraph, "dreifacheinzug");
|
||||
break;
|
||||
case 4:
|
||||
ApplyParaStyle(lastParagraph, "vierfacheinzug");
|
||||
break;
|
||||
case 5:
|
||||
ApplyParaStyle(lastParagraph, "fünffacheinzug");
|
||||
break;
|
||||
case 6:
|
||||
ApplyParaStyle(lastParagraph, "sechsfacheinzug");
|
||||
break;
|
||||
case 7:
|
||||
ApplyParaStyle(lastParagraph, "siebenfacheinzug");
|
||||
break;
|
||||
default:
|
||||
ApplyParaStyle(lastParagraph, "einzug");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void CheckPageTag(XElement xelem, WordprocessingDocument wordDoc)
|
||||
{
|
||||
//erstellt Textboxen für die Seitenzählung
|
||||
string pagenumber = "";
|
||||
if (xelem.Attributes("autopsic").Any())
|
||||
pagenumber = xelem.Attribute("autopsic").Value.ToString();
|
||||
else if (xelem.Attributes("index").Any())
|
||||
pagenumber = xelem.Attribute("index").Value.ToString();
|
||||
Paragraph counterParagraph = new Paragraph();
|
||||
ApplyParaStyle(counterParagraph, "seitenzählung");
|
||||
Run run = new Run(new Text("Seite " + pagenumber));
|
||||
counterParagraph.AppendChild<Run>(run);
|
||||
SmallFont(run);
|
||||
BoldRun(run);
|
||||
Paragraph lastParagraph = GetLastPara(wordDoc);
|
||||
lastParagraph.InsertAfterSelf<Paragraph>(counterParagraph);
|
||||
FrameCounterParagraph(counterParagraph);
|
||||
}
|
||||
|
||||
public static Paragraph IfLine5(WordprocessingDocument wordDoc, XElement xelem, int numbr)
|
||||
{
|
||||
Paragraph counterParagraph = new Paragraph();
|
||||
Run run = new Run(new Text(xelem.Attribute("autopsic").Value));
|
||||
counterParagraph.AppendChild<Run>(run);
|
||||
SmallFont(run);
|
||||
ApplyParaStyle(counterParagraph, "zeilenzählung");
|
||||
Paragraph lastParagraph = GetLastPara(wordDoc);
|
||||
lastParagraph.InsertAfterSelf<Paragraph>(counterParagraph);
|
||||
FrameCounterParagraph(counterParagraph);
|
||||
return counterParagraph;
|
||||
}
|
||||
|
||||
public static XElement StringToXElement(string s)
|
||||
{
|
||||
return XElement.Parse(s, LoadOptions.PreserveWhitespace);
|
||||
}
|
||||
|
||||
public static Run MakeTextRun(XNode node = null)
|
||||
{//erzeugt einen run der je nach parameter leer sein kann oder text enhält
|
||||
Run run = new Run();
|
||||
run.PrependChild(new RunProperties());
|
||||
if (node != null)
|
||||
{
|
||||
var xtext = (node as XText);
|
||||
string text = xtext.Value;
|
||||
run.AppendChild(new Text(text) { Space = SpaceProcessingModeValues.Preserve });
|
||||
}
|
||||
return run;
|
||||
}
|
||||
|
||||
public static Run MakeRun(Paragraph para, XNode xnode)
|
||||
{
|
||||
/*erzeugt einen run aus einer textnode als xelement und fügt ihn dem paragraph an*/
|
||||
var xtext = xnode as XText;
|
||||
string text = xtext.Value;
|
||||
Run run = new Run();
|
||||
RunProperties runProperties = run.PrependChild(new RunProperties());
|
||||
run.AppendChild(new Text(text) { Space = SpaceProcessingModeValues.Preserve });
|
||||
Paragraph para2 = para.Parent.Elements<Paragraph>().Last<Paragraph>();
|
||||
para2.AppendChild(run);
|
||||
return run;
|
||||
}
|
||||
|
||||
|
||||
public static void MakeTradition(LetterObj letter)
|
||||
{
|
||||
//fügt den absatz mit der überlieferung an das dokument an
|
||||
var lastPara = GetLastPara(letter.WordDoc);
|
||||
Paragraph traditonPara = new Paragraph(new Run(new Break()));
|
||||
lastPara.InsertAfterSelf<Paragraph>(traditonPara);
|
||||
CreateTraditionPara(letter, traditonPara);
|
||||
CreateColSection(letter.WordDoc, true);
|
||||
}
|
||||
|
||||
public static Paragraph CreateTraditionPara(LetterObj letter, Paragraph tradPara)
|
||||
{
|
||||
if (letter?.Tradition != null)
|
||||
{
|
||||
ApplyParaStyle(tradPara, "überlieferung");
|
||||
var tradString = letter.Tradition.ToString();
|
||||
XElement tradition = StringToXElement(RemoveWhiteSpaceLinebreak(tradString));
|
||||
ParseXElement(tradition, tradPara, letter);
|
||||
}
|
||||
return tradPara;
|
||||
}
|
||||
|
||||
public static void AddRefsToDict(string refer, string subref, Dictionary<string, Dictionary<string, List<Place>>> commRefs, Place place)
|
||||
{
|
||||
//übreprüft ob ref-/subref-ids schon im dictionary enthalten sind und fügt diese gegebenenfalls sammt Stelle des Kommentars hinzu
|
||||
if (commRefs.ContainsKey(refer))
|
||||
{
|
||||
if (commRefs[refer].ContainsKey(subref))
|
||||
{
|
||||
commRefs[refer][subref].Add(place);
|
||||
}
|
||||
else
|
||||
{
|
||||
var list = new List<Place> { place };
|
||||
commRefs[refer].Add(subref, list);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var dict = new Dictionary<string, List<Place>>();
|
||||
var list = new List<Place> { place };
|
||||
|
||||
if (subref == "0")
|
||||
{
|
||||
dict.Add("0", list);
|
||||
}
|
||||
else
|
||||
{
|
||||
dict.Add(subref, list);
|
||||
}
|
||||
commRefs.Add(refer, dict);
|
||||
}
|
||||
}
|
||||
|
||||
public static int MatchIdSubstrings(string source)
|
||||
{
|
||||
// teilt die Bibelreferenz-ids in substrings und gibt diese zurück, überflüssiger behelf, ersetzt durch .sort atribut
|
||||
|
||||
/*Regex stringParts = new Regex("([a-z]{1,4})-([a-z]{1,4})[0-9]{0,3}");
|
||||
Match stringMatch = stringParts.Match(source);
|
||||
string testament = stringMatch.Groups[1].Value;
|
||||
string exact = stringMatch.Groups[2].Value;
|
||||
Regex bookNumberPart = new Regex(".*-.*([0-9]{1,3})");
|
||||
Match bookNumberMatch = bookNumberPart.Match(source);
|
||||
string bookNumber = "0";
|
||||
if (bookNumberMatch.Success)
|
||||
{
|
||||
bookNumber = bookNumberMatch.Groups[1].Value;
|
||||
}
|
||||
Regex
|
||||
|
||||
berPart = new Regex(".*-.*-([0-9]{1,4})");
|
||||
Match lineNumberMatch = lineNumberPart.Match(source);
|
||||
string lineNumber = "0";
|
||||
if (lineNumberMatch.Success)
|
||||
{
|
||||
lineNumber = lineNumberMatch.Groups[1].Value;
|
||||
}
|
||||
return new string[] { testament, exact, bookNumber, lineNumber };*/
|
||||
Regex numberRegx = new Regex(@"(\d+)$");
|
||||
Match numberMatch = numberRegx.Match(source);
|
||||
string number = "0";
|
||||
if (numberMatch.Success)
|
||||
{
|
||||
number = numberMatch.Groups[1].Value;
|
||||
}
|
||||
return Int32.Parse(number);
|
||||
}
|
||||
|
||||
public static string[] MatchForschungSubstrings(string source)
|
||||
{
|
||||
// teilt die Bibliographie ids in substrings und gibt diese zurück, überflüssiger behelf, ersetzt durch .sort atribut
|
||||
Regex stringParts = new Regex("([a-z]{3})-(.)-([0-9]{4})([a-z]?)");
|
||||
Match stringMatch = stringParts.Match(source);
|
||||
string name = stringMatch.Groups[1].Value;
|
||||
string letter = stringMatch.Groups[2].Value;
|
||||
string year = stringMatch.Groups[3].Value;
|
||||
string numberInYear = "-";
|
||||
if (stringMatch.Groups[4].Value.Length != 0)
|
||||
{
|
||||
numberInYear = stringMatch.Groups[4].Value;
|
||||
}
|
||||
return new string[] { source, name, letter, year, numberInYear };
|
||||
}
|
||||
|
||||
public static void CorrectLinks(string comment, bool test = false)
|
||||
{
|
||||
/*da das hinzufügen von Links das öffnen des maindocument parts erfordert,
|
||||
* dieses aber zu IO-Errors führt, werden die Links nach erstellen des
|
||||
* Dokuments (bei nochmaligem öffnen und schließen) erzeugt
|
||||
KEINE TOLLE LÖSUNG, funktioniert aber gut*/
|
||||
|
||||
string wordPath = VolumesOutputDir + "HKB_" + comment + ".docx";
|
||||
if (test) { wordPath = comment; };
|
||||
using (WordprocessingDocument doc = WordprocessingDocument.Open(wordPath, true))
|
||||
{
|
||||
MainDocumentPart mainPart = doc.MainDocumentPart;
|
||||
foreach (Hyperlink link in mainPart.Document.Body.Descendants<Hyperlink>())
|
||||
{
|
||||
if (link.Id == null || link.Id == "")
|
||||
{
|
||||
|
||||
Logger.Out("defekter Link bei " + link.InnerText);
|
||||
}
|
||||
else
|
||||
{
|
||||
string url = link.Id;
|
||||
try
|
||||
{
|
||||
var rel = mainPart.AddHyperlinkRelationship(new Uri(url), true);
|
||||
link.Id = rel.Id;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Logger.Out("Diese URL ist im Eimer: " + url+ "\nObwohl ich sie lösche mag Word das Dokument danach nicht öffnen! Diese URL also bitte im XML korrigieren! \n"+exception.Message);
|
||||
link.Remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
mainPart.Document.Save();
|
||||
doc.Save();
|
||||
doc.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetTemporaryDirectory()
|
||||
{
|
||||
//erzeugt temporäres dir für das herstellen der Banddokumente, das später wieder gelöscht wird.
|
||||
//die temporären zh-Briefdateien werden dort bis zum mergen gespeichert
|
||||
string tempFolder = Path.GetTempFileName();
|
||||
try
|
||||
{
|
||||
File.Delete(tempFolder);
|
||||
Directory.CreateDirectory(tempFolder);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Logger.Out("Temporäres Verzeichnis " + tempFolder + " für die speicherung temporärer briefdokumente konnte nicht erstellt werden.");
|
||||
}
|
||||
|
||||
return tempFolder;
|
||||
}
|
||||
|
||||
public static void RemoveTempFolderFiles(Dictionary<int, string> outputPaths, string tempfolder)
|
||||
{
|
||||
foreach (var path in outputPaths.Where(x => x.Key != 0 && x.Key != 1000000000))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(path.Value);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Logger.Out("löschen der temporären Briefdatei " + path + "ist fehlgeschlagen.\n Ist keine katastrophe, sollte aber manuell nachgeholt werden.");
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
Directory.Delete(tempfolder);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Logger.Out("löschen des temporären Verzeichnisses " + tempfolder + "ist fehlgeschlagen.\n Ist keine katastrophe, sollte aber manuell nachgeholt werden.");
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
public static void MergeDocx(string year, Dictionary<int, string> outputPaths)
|
||||
{
|
||||
/*verbindet die einzelnen temporären ZH Briefdateien zu einer Banddatei
|
||||
die dauerhaften Brief.docx dateien können nicht gemergt werden, da sie die
|
||||
für Bände überflüssige source section am ende enthalten und alt chunks nicht
|
||||
verändert werden können*/
|
||||
Logger.Out("erstelle Jahr " + year);
|
||||
var OrderedPathKeys = outputPaths.Keys.ToList();
|
||||
OrderedPathKeys.Sort((a, b) => -1 * a.CompareTo(b));
|
||||
foreach (var key in OrderedPathKeys.Where(k => k != 0))
|
||||
{
|
||||
using (WordprocessingDocument doc = WordprocessingDocument.Open(@outputPaths[0], true))
|
||||
{
|
||||
MainDocumentPart mainPart = doc.MainDocumentPart;
|
||||
string altChunkId = "AltChunkId" + key;
|
||||
AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.WordprocessingML, altChunkId);
|
||||
using (FileStream fileStream = File.Open(@outputPaths[key], FileMode.Open))
|
||||
{
|
||||
chunk.FeedData(fileStream);
|
||||
}
|
||||
AltChunk altChunk = new AltChunk();
|
||||
altChunk.Id = altChunkId;
|
||||
mainPart.Document.Body.InsertAfter(altChunk, GetLastPara(doc));
|
||||
mainPart.Document.Save();
|
||||
doc.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
HamannPrinter/MainWindow.xaml
Normal file
29
HamannPrinter/MainWindow.xaml
Normal file
@@ -0,0 +1,29 @@
|
||||
<Window x:Class="HamannPrinter.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:HamannPrinter"
|
||||
mc:Ignorable="d"
|
||||
Title="MainWindow" Height="450" Width="800">
|
||||
<Grid>
|
||||
<Grid>
|
||||
<CheckBox x:Name="LetterDocs" Content="Brief.docx erzeugen" HorizontalAlignment="Left" Margin="40,34,0,0" VerticalAlignment="Top" Checked="SingleDocChanged" Unchecked="SingleDocChanged" IsChecked="True"/>
|
||||
<CheckBox x:Name="VolumeDocs" Content="Jahr.docx erzeugen" HorizontalAlignment="Left" Margin="40,59,0,0" VerticalAlignment="Top" Checked="VolDocChanged" Unchecked="VolDocChanged" IsChecked="True"/>
|
||||
<CheckBox x:Name="RegisterDocs" Content="Kommentar.docx erzeugen" HorizontalAlignment="Left" Margin="40,84,0,0" VerticalAlignment="Top" Unchecked="CommDocChanged" Checked="CommDocChanged" IsChecked="True"/>
|
||||
<Label Content="Jahre" HorizontalAlignment="Left" Margin="40,133,0,0" VerticalAlignment="Top" HorizontalContentAlignment="Left"/>
|
||||
<Label Content="Verzeichnis mit Hamann-XML-Teildateien:" HorizontalAlignment="Left" Margin="320,133,0,0" VerticalAlignment="Top"/>
|
||||
<TextBox x:Name="XmlFileBox" HorizontalAlignment="Left" Margin="320,158,0,0" Text="" TextWrapping="NoWrap" VerticalAlignment="Top" Width="342" Grid.ColumnSpan="2"/>
|
||||
<Button x:Name="XmlFileButton" Content="suchen" Grid.Column="1" HorizontalAlignment="Left" Margin="680,158,0,0" VerticalAlignment="Top" Click="XmlFileButton_Click"/>
|
||||
<Label Content="Ausgabeverzeichnis:" HorizontalAlignment="Left" Margin="320,183,0,0" VerticalAlignment="Top" Width="136"/>
|
||||
<TextBox x:Name="OutputDirBox" HorizontalAlignment="Left" Margin="320,208,0,0" Text="" TextWrapping="NoWrap" VerticalAlignment="Top" Width="342"/>
|
||||
<Button x:Name="OutputDirButton" Content="suchen" Grid.Column="1" HorizontalAlignment="Left" Margin="680,208,20,0" VerticalAlignment="Top" Click="OutputDirButton_Click"/>
|
||||
<Button Content="Dokumente erzeugen" HorizontalAlignment="Left" Margin="603,0,0,45" VerticalAlignment="Bottom" Click="Button_Click"/>
|
||||
<TextBlock HorizontalAlignment="Left" Margin="321,304,0,0" Text="Achtung! Auf keinen Fall sollte man während des Erstellens von PDF-Dateien Word öffnen oder geöffnet haben!" TextWrapping="Wrap" VerticalAlignment="Top" Width="364"/>
|
||||
<TextBox x:Name="StartYearTextBox" HorizontalAlignment="Left" Margin="102,158,0,0" Text="1751" TextWrapping="Wrap" VerticalAlignment="Top" Width="56" RenderTransformOrigin="0.474,0.709" TextInput="TextBox_TextInput"/>
|
||||
<TextBox x:Name="EndYearTextBox" HorizontalAlignment="Left" Margin="102,181,0,0" Text="1788" TextWrapping="Wrap" VerticalAlignment="Top" Width="56" RenderTransformOrigin="0.474,0.709" MaxLength="6" TextInput="EndYearTextBox_TextInput"/>
|
||||
<Label Content="und" HorizontalAlignment="Left" Margin="40,177,0,0" VerticalAlignment="Top" HorizontalContentAlignment="Left"/>
|
||||
<Label Content="zwischen" HorizontalAlignment="Left" Margin="40,155,0,0" VerticalAlignment="Top" HorizontalContentAlignment="Left" RenderTransformOrigin="0.418,1.293"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Window>
|
||||
248
HamannPrinter/MainWindow.xaml.cs
Normal file
248
HamannPrinter/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,248 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using static HamannPrinter.XMLMerger;
|
||||
|
||||
namespace HamannPrinter
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
///
|
||||
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
[DllImport("Kernel32")]
|
||||
public static extern void AllocConsole();
|
||||
|
||||
[DllImport("Kernel32")]
|
||||
public static extern void FreeConsole();
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
RegisterDocs.IsChecked = false;
|
||||
VolumeDocs.IsChecked = false;
|
||||
StartYearTextBox.Text = "1751";
|
||||
EndYearTextBox.Text = "1764";
|
||||
XmlFileBox.Text = @"C:\Users\simon\Desktop\Printer\XML"; // DEV
|
||||
OutputDirBox.Text = @"C:\Users\simon\Desktop\Printer\Ausg"; // DEV
|
||||
}
|
||||
|
||||
private void SingleDocChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
/*Wenn das Erstellen von Einzelbrief.Worddokumenten nicht ausgewählt ist, wird das Feld für das Erstellen von entpsrechenden Pdf Dateien deaktiviert.*/
|
||||
}
|
||||
|
||||
private void VolDocChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
/*Wenn das Erstellen von Band.Worddokumenten nicht ausgewählt ist, wird das Feld für das Erstellen von entpsrechenden Pdf Dateien deaktiviert.*/
|
||||
}
|
||||
|
||||
private void CommDocChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
/*Wenn das Erstellen von Kommentar.Worddokumenten nicht ausgewählt ist, wird das Feld für das Erstellen von entpsrechenden Pdf Dateien deaktiviert.*/
|
||||
|
||||
}
|
||||
|
||||
private void XmlFileButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
/*Wenn der such button für die xml-quell-datein ausgewählt wird, wird ein entsprechende
|
||||
* windows forms dialog gestartet. Das Ergebenis wird in der nebenstehenden Textbox angezeigt.*/
|
||||
using (var dialog = new System.Windows.Forms.FolderBrowserDialog())
|
||||
{
|
||||
System.Windows.Forms.DialogResult result = dialog.ShowDialog();
|
||||
if (result == System.Windows.Forms.DialogResult.OK)
|
||||
{
|
||||
XmlFileBox.Text = dialog.SelectedPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OutputDirButton_Click(object sender, RoutedEventArgs e)
|
||||
{/*wenn der suchen button für das ausgabe verzeichnis geklickt wird, startet ein entsprechender windows forms dialog.
|
||||
das ergebnis der user eingaben wird in der nebenstehenden textbox gespeichert.*/
|
||||
using (var dialog = new System.Windows.Forms.FolderBrowserDialog())
|
||||
{
|
||||
System.Windows.Forms.DialogResult result = dialog.ShowDialog();
|
||||
if (result == System.Windows.Forms.DialogResult.OK)
|
||||
{
|
||||
OutputDirBox.Text = dialog.SelectedPath;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
/*Routine für "Dokumente ezeugen"-Button */
|
||||
if (CheckInput())
|
||||
{
|
||||
/*startet Konsole für Fehlerausgabe. Die entpsrechenden Meldungen werden auch in einer Log-Datei im Ausgabeverzeichnis gespeichert.*/
|
||||
AllocConsole();
|
||||
this.IsEnabled = false;
|
||||
Confix confix = MakeConfix();
|
||||
if (!File.Exists(confix.HamannXmlPath))
|
||||
{
|
||||
Warn("Upsi!\nDie erstellte Datei \"" + confix.HamannXmlPath + "\" existiert nicht.");
|
||||
this.IsEnabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var parser = new Parser();
|
||||
parser.MakeDocuments(confix);
|
||||
this.IsEnabled = true;
|
||||
//this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckInput()
|
||||
{
|
||||
if (LetterDocs.IsChecked == true || VolumeDocs.IsChecked == true)
|
||||
{
|
||||
if (GetYears().Item1 <= GetYears().Item2)
|
||||
{
|
||||
if (CheckPaths())
|
||||
return true;
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Warn("Kein zu generierender Hamannband ausgewählt!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (RegisterDocs.IsChecked == true)
|
||||
{
|
||||
if (CheckPaths())
|
||||
return true;
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Warn("Kein zu generierender Dokumententyp ausgewählt!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckPaths()
|
||||
{
|
||||
string xmlPath = XmlFileBox.Text;
|
||||
string outPath = OutputDirBox.Text;
|
||||
if (!Directory.Exists(xmlPath))
|
||||
{
|
||||
Warn("Kein existierendes verzeichnis ausgewählt!");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!Directory.Exists(outPath))
|
||||
{
|
||||
Warn("Kein existierendes Ausgabeverzeichnis ausgewählt!");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void Warn(string message)
|
||||
{
|
||||
System.Windows.MessageBox.Show(message,
|
||||
"Confirmation",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Exclamation
|
||||
);
|
||||
}
|
||||
|
||||
private Confix MakeConfix()
|
||||
{
|
||||
var confix = new Confix()
|
||||
{
|
||||
Editionsrichtlinien = CheckForEditionsRichtlinien(),
|
||||
LettersDocx = LetterDocs.IsChecked,
|
||||
VolumeDocx = VolumeDocs.IsChecked,
|
||||
RegisterDocx = RegisterDocs.IsChecked,
|
||||
HamannXmlPath = GetHAMANNxml(),
|
||||
OutputPath = MakePath(OutputDirBox.Text),
|
||||
Years = GetYears(),
|
||||
};
|
||||
return confix;
|
||||
}
|
||||
|
||||
string CheckForEditionsRichtlinien()
|
||||
{
|
||||
string path = MakePath(XmlFileBox.Text);
|
||||
string file = path + "Editionsrichtlinien.docx";
|
||||
int stupidCounter = 0;
|
||||
while (!File.Exists(file))
|
||||
{
|
||||
if (stupidCounter > 2)
|
||||
{
|
||||
Warn("Das dauert jetzt zu lange. Um das noch einmal zusammenzufassen: in "+path+ " muss eine Datei namens \"Editionsrichtlinien.docx\" liegen, die hinten an die Banddokumente angefügt wird.\nDie ist nicht da oder hat einen falschen Namen oder etwas funktionier nicht. Wir beenden das besser.");
|
||||
Application.Current.Shutdown();
|
||||
System.Environment.Exit(0);
|
||||
}
|
||||
Warn("\"Editionsrichtlinien.docx\" im Verzeichnis "+path+" nicht gefunden. \nDiese Datei ist aber unbedingt nötig um Bände zu erstellen.\n(Du willst keine Bände erstellen? Pech, sie ist trotzdem nötig, weil Fritz nicht programmieren kann.)\nBitte die Datei in das Verzeichnis legen und dann auf \"Ok\" klicken.");
|
||||
++stupidCounter;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
string GetHAMANNxml()
|
||||
{
|
||||
string path = MakePath(XmlFileBox.Text);
|
||||
string file = path + "HAMANN.xml";
|
||||
if (File.Exists(file))
|
||||
{
|
||||
var answer = System.Windows.MessageBox.Show("HAMANN.xml gefunden. \nZuletzt bearbeitet: " + File.GetLastWriteTime(file) + "\n\nSoll diese Datei verwendet werden, ohne eine neue aus den Einzeldokumenten zusammenzusetzen?",
|
||||
"Confirmation",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
if (answer == MessageBoxResult.Yes) return file;
|
||||
File.Delete(file);
|
||||
}
|
||||
return new Concatinator(MakePath(XmlFileBox.Text)).HamannXmlFile;
|
||||
}
|
||||
|
||||
private string MakePath(string path)
|
||||
{
|
||||
if (!path.EndsWith(@"\")) path += @"\";
|
||||
return path;
|
||||
}
|
||||
|
||||
public (int, int) GetYears()
|
||||
{
|
||||
return (int.Parse(StartYearTextBox.Text), int.Parse(EndYearTextBox.Text));
|
||||
}
|
||||
|
||||
private void TextBox_TextInput(object sender, System.Windows.Input.TextCompositionEventArgs e)
|
||||
{
|
||||
if (!int.TryParse(e.Text, out _))
|
||||
{
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void EndYearTextBox_TextInput(object sender, System.Windows.Input.TextCompositionEventArgs e)
|
||||
{
|
||||
if (!int.TryParse(e.Text, out _))
|
||||
{
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
HamannPrinter/Microsoft.Office.Interop.Word.dll
Normal file
BIN
HamannPrinter/Microsoft.Office.Interop.Word.dll
Normal file
Binary file not shown.
339
HamannPrinter/Parser.cs
Normal file
339
HamannPrinter/Parser.cs
Normal file
@@ -0,0 +1,339 @@
|
||||
using System;
|
||||
using HaDocument.Interfaces;
|
||||
using HaDocument;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.Linq;
|
||||
|
||||
namespace HamannPrinter
|
||||
{
|
||||
public class Parser
|
||||
{
|
||||
class Options : IHaDocumentOptions
|
||||
{
|
||||
public string HamannXMLFilePath { get; set; }
|
||||
public string[] AvailableVolumes { get; set; } = { "1", "2", "3", "4", "5", "6", "7" };
|
||||
public bool NormalizeWhitespace { get; set; } = true;
|
||||
|
||||
public (int, int) AvailableYearRange {get; set; } = (1751, 1788);
|
||||
|
||||
public Options(string HamannXmlPath)
|
||||
{
|
||||
HamannXMLFilePath = HamannXmlPath;
|
||||
}
|
||||
}
|
||||
|
||||
public class DocOptions
|
||||
{
|
||||
|
||||
public string OutputDir { get; set; }
|
||||
public string VolumesOutputDir { get; set; }
|
||||
public string Editionsrichtlinien { get; set; }
|
||||
public string LineHight { get; set; } = "280";
|
||||
public string SmallDistance { get; set; } = "140";
|
||||
public string MiddleLineHight { get; set; } = "224";
|
||||
public string FontSize { get; set; } = "20";
|
||||
public string MiddleFontSize { get; set; } = "16";
|
||||
public string SmallFontSize { get; set; } = "12";
|
||||
public string BigFontSize { get; set; } = "32";
|
||||
public int MarginTop { get; set; } = 1416;
|
||||
public UInt32 MarginRight { get; set; } = 2600U;
|
||||
public int MarginBottom { get; set; } = 2132;
|
||||
public UInt32 MarginLeft { get; set; } = 1984U;
|
||||
public UInt32 MarginFooter { get; set; } = 1417U;
|
||||
public string ColumnDistance { get; set; } = "560";
|
||||
public string FooterToText { get; set; } = "420";
|
||||
public string NormalFont { get; set; } = "Linux Libertine G";
|
||||
public string SpecialFont { get; set; } = "Linux Biolinum";
|
||||
public string SuperValue { get; set; } = "6";
|
||||
public string SubValue { get; set; } = "-4";
|
||||
public (int, int) Years { get; set; }
|
||||
|
||||
public DocOptions((int, int) years, string outputDir, string editionsRichtlinien)
|
||||
{
|
||||
Editionsrichtlinien = editionsRichtlinien;
|
||||
Years = years;
|
||||
OutputDir = outputDir;
|
||||
VolumesOutputDir = System.IO.Directory.CreateDirectory(outputDir + @"bände_register\").FullName;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Logger
|
||||
{
|
||||
public static StringBuilder LogString = new StringBuilder();
|
||||
public static void Out(string str)
|
||||
{
|
||||
Console.WriteLine(str);
|
||||
LogString.Append(str).Append(Environment.NewLine);
|
||||
}
|
||||
}
|
||||
|
||||
public void MakeDocuments(Confix confix)
|
||||
{
|
||||
var hamannDoc = Document.Create(new Options(confix.HamannXmlPath));
|
||||
DocOptions docOpt = new DocOptions(confix.Years, confix.OutputPath, confix.Editionsrichtlinien);
|
||||
CheckXML(confix, docOpt, hamannDoc);
|
||||
Coordinator(docOpt, hamannDoc, hamannDoc, docOpt.Years, confix.LettersDocx, confix.VolumeDocx, confix.RegisterDocx);
|
||||
Helper.Ok("Fertig!");
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
public void CheckXML(Confix confix, DocOptions docOpt, ILibrary hamannDoc)
|
||||
{
|
||||
var errors = new StringBuilder();
|
||||
var document = XDocument.Load(confix.HamannXmlPath, LoadOptions.SetLineInfo);
|
||||
|
||||
var kommentare = document.Descendants("kommentar");
|
||||
var subsections = document.Descendants("subsection");
|
||||
var intlinks = document.Descendants("intlink");
|
||||
var links = document.Descendants("link");
|
||||
var marginals = document.Descendants("marginal");
|
||||
var hands = document.Descendants("hand");
|
||||
var edits = document.Descendants("edit");
|
||||
var editreasons = document.Descendants("editreason");
|
||||
|
||||
var ids = new HashSet<String>();
|
||||
foreach (var kommentar in kommentare)
|
||||
{
|
||||
if (kommentar.HasAttributes && kommentar.Attribute("id") != null)
|
||||
{
|
||||
if (!ids.Contains(kommentar.Attribute("id").Value))
|
||||
ids.Add(kommentar.Attribute("id").Value);
|
||||
else
|
||||
{
|
||||
errors.AppendLine("Kommentar-ID " + kommentar.Attribute("id").Value + " doppelt vergeben!");
|
||||
errors.AppendLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var kommentar in subsections)
|
||||
{
|
||||
if (kommentar.HasAttributes && kommentar.Attribute("id") != null)
|
||||
{
|
||||
if (!ids.Contains(kommentar.Attribute("id").Value))
|
||||
ids.Add(kommentar.Attribute("id").Value);
|
||||
else
|
||||
{
|
||||
errors.AppendLine("Kommentar-ID " + kommentar.Attribute("id").Value + " doppelt vergeben!");
|
||||
errors.AppendLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var link in intlinks)
|
||||
{
|
||||
if (link.HasAttributes && link.Attribute("letter") != null)
|
||||
{
|
||||
if (hamannDoc.Letters.ContainsKey(link.Attribute("letter").Value))
|
||||
{
|
||||
if (link.Attribute("page") != null)
|
||||
{
|
||||
var lettertext = XElement.Parse(hamannDoc.Letters[link.Attribute("letter").Value].Element);
|
||||
var lettertext2 = XElement.Parse(hamannDoc.Traditions[link.Attribute("letter").Value].Element);
|
||||
var page = lettertext.Descendants("page").Where(x => x.Attribute("index").Value.ToString() == link.Attribute("page").Value.ToString()).Union(lettertext2.Descendants("page").Where(x => x.Attribute("index").Value.ToString() == link.Attribute("page").Value.ToString()));
|
||||
if (page.Any())
|
||||
{
|
||||
if (link.Attribute("line") != null)
|
||||
{
|
||||
var elementsafter = lettertext.Descendants().SkipWhile(x => x.Name != "page" || !x.Attributes("index").Any() || x.Attribute("index").Value != link.Attribute("page").Value).TakeWhile(x => x.Name.ToString() != "page" || (x.Name.ToString() == "page" && x.Attribute("index").Value == link.Attribute("page").Value));
|
||||
var elementsafter2 = lettertext2.Descendants().SkipWhile(x => x.Name != "page" || !x.Attributes("index").Any() || x.Attribute("index").Value != link.Attribute("page").Value).TakeWhile(x => x.Name.ToString() != "page" || (x.Name.ToString() == "page" && x.Attribute("index").Value == link.Attribute("page").Value));
|
||||
var line = elementsafter.Where(x => x.Name == "line" && x.HasAttributes && x.Attributes("index").Any() && x.Attribute("index").Value == link.Attribute("line").Value).Union(elementsafter2.Where(x => x.Name == "line" && x.HasAttributes && x.Attributes("index").Any() && x.Attribute("index").Value == link.Attribute("line").Value));
|
||||
if (!line.Any())
|
||||
{
|
||||
var info = (IXmlLineInfo)link;
|
||||
errors.AppendLine(link.ToString() + " Z. " + info.LineNumber + " verweist auf eine nicht existierende Zeile (" + link.Attribute("line").Value + ") !");
|
||||
errors.AppendLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var info = (IXmlLineInfo)link;
|
||||
errors.AppendLine(link.ToString() + " Z. " + info.LineNumber + " verweist auf eine nicht existierende Seite (" + link.Attribute("page").Value + ") !");
|
||||
errors.AppendLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var info = (IXmlLineInfo)link;
|
||||
errors.AppendLine(link.ToString() + " Z. " + info.LineNumber + " verweist auf einen nicht existierenden Brief (" + link.Attribute("letter").Value + ") !");
|
||||
errors.AppendLine();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var info = (IXmlLineInfo)link;
|
||||
errors.AppendLine(link.ToString() + " Z. " + info.LineNumber + " hat kein letter-Attribut!");
|
||||
errors.AppendLine();
|
||||
}
|
||||
}
|
||||
|
||||
var marginalset = new HashSet<String>();
|
||||
foreach (var link in marginals)
|
||||
{
|
||||
if (link.HasAttributes && link.Attribute("index") != null) {
|
||||
if (marginalset.Contains(link.Attribute("index").Value.ToString())) {
|
||||
var info = (IXmlLineInfo)link;
|
||||
errors.AppendLine(link.ToString() + " Z. " + info.LineNumber + " hate eine bereits vergebene Indexnummer und wird ignoriert. (" + link.Attribute("index").Value + ") !");
|
||||
errors.AppendLine();
|
||||
} else
|
||||
marginalset.Add(link.Attribute("index").Value.ToString());
|
||||
}
|
||||
if (link.HasAttributes && link.Attribute("letter") != null)
|
||||
{
|
||||
if (hamannDoc.Letters.ContainsKey(link.Attribute("letter").Value))
|
||||
{
|
||||
if (link.Attribute("page") != null)
|
||||
{
|
||||
var lettertext = XElement.Parse(hamannDoc.Letters[link.Attribute("letter").Value].Element);
|
||||
var page = lettertext.Descendants("page").Where(x => x.Attribute("index").Value.ToString() == link.Attribute("page").Value.ToString());
|
||||
if (page.Any())
|
||||
{
|
||||
if (link.Attribute("line") != null)
|
||||
{
|
||||
var elementsafter = lettertext.Descendants().SkipWhile(x => x.Name != "page" || !x.Attributes("index").Any() || x.Attribute("index").Value != link.Attribute("page").Value).TakeWhile(x => x.Name.ToString() != "page" || (x.Name.ToString() == "page" && x.Attribute("index").Value == link.Attribute("page").Value));
|
||||
var line = elementsafter.Where(x => x.Name == "line" && x.HasAttributes && x.Attributes("index").Any() && x.Attribute("index").Value.ToString() == link.Attribute("line").Value.ToString());
|
||||
if (!line.Any())
|
||||
{
|
||||
var info = (IXmlLineInfo)link;
|
||||
errors.AppendLine(link.ToString() + " Z. " + info.LineNumber + " verweist auf eine nicht existierende Zeile (" + link.Attribute("line").Value + ") !");
|
||||
errors.AppendLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var info = (IXmlLineInfo)link;
|
||||
errors.AppendLine(link.ToString() + " Z. " + info.LineNumber + " verweist auf eine nicht existierende Seite (" + link.Attribute("page").Value + ") !");
|
||||
errors.AppendLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var info = (IXmlLineInfo)link;
|
||||
errors.AppendLine(link.ToString() + " Z. " + info.LineNumber + " verweist auf einen nicht existierenden Brief (" + link.Attribute("letter").Value + ") !");
|
||||
errors.AppendLine();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var info = (IXmlLineInfo)link;
|
||||
errors.AppendLine(link.ToString() + " Z. " + info.LineNumber + " hat kein letter-Attribut!");
|
||||
errors.AppendLine();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var link in links)
|
||||
{
|
||||
if (link.HasAttributes && link.Attribute("ref") != null)
|
||||
{
|
||||
if (!ids.Contains(link.Attribute("ref").Value))
|
||||
{
|
||||
var info = (IXmlLineInfo)link;
|
||||
errors.AppendLine(link.ToString() + " Z. " + info.LineNumber + " verweist auf einen nicht existierenden Kommentar (" + link.Attribute("ref").Value + ") !");
|
||||
errors.AppendLine();
|
||||
}
|
||||
}
|
||||
|
||||
if (link.HasAttributes && link.Attribute("subref") != null)
|
||||
{
|
||||
if (!ids.Contains(link.Attribute("subref").Value))
|
||||
{
|
||||
var info = (IXmlLineInfo)link;
|
||||
errors.AppendLine(link.ToString() + " Z. " + info.LineNumber + " verweist auf einen nicht existierenden Kommentar (" + link.Attribute("subref").Value + ") !");
|
||||
errors.AppendLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach (var hand in hands)
|
||||
{
|
||||
if (hand.HasAttributes && hand.Attribute("ref") != null)
|
||||
{
|
||||
if (!hamannDoc.HandPersons.ContainsKey(hand.Attribute("ref").Value))
|
||||
{
|
||||
var info = (IXmlLineInfo)hand;
|
||||
errors.AppendLine(hand.ToString() + " Z. " + info.LineNumber + " verweist auf einen nicht angelegte Person in den Handrefs (" + hand.Attribute("ref").Value + ") !");
|
||||
errors.AppendLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var edit in edits)
|
||||
{
|
||||
if (edit.HasAttributes && edit.Attribute("ref") != null)
|
||||
{
|
||||
if (!hamannDoc.Editreasons.ContainsKey(edit.Attribute("ref").Value))
|
||||
{
|
||||
var info = (IXmlLineInfo)edit;
|
||||
errors.AppendLine(edit.ToString() + " Z. " + info.LineNumber + " verweist auf eine nicht existierende Editreason (" + edit.Attribute("ref").Value + ") !");
|
||||
errors.AppendLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//foreach (var link in links)
|
||||
//{
|
||||
// if (link.HasAttributes && link.Attribute("subref") != null)
|
||||
// {
|
||||
// if (ids.Contains(link.Attribute("subref").Value))
|
||||
// ids.Remove(link.Attribute("subref").Value);
|
||||
// }
|
||||
// else if (link.HasAttributes && link.Attribute("ref") != null)
|
||||
// {
|
||||
// if (ids.Contains(link.Attribute("ref").Value))
|
||||
// ids.Remove(link.Attribute("ref").Value);
|
||||
// }
|
||||
|
||||
// if (ids.Any())
|
||||
// {
|
||||
// foreach (var id in ids)
|
||||
// {
|
||||
// errors.AppendLine("WARNUNG: Auf den Kommentar mit der ID " + id + " wird nirgends verwiesen.");
|
||||
// errors.AppendLine();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
System.IO.File.WriteAllText(docOpt.OutputDir + "errors.txt", errors.ToString());
|
||||
}
|
||||
|
||||
public void Coordinator(DocOptions docOpt, ILibrary hamannDoc, ILibrary lib, (int, int) years, bool? letterDocs, bool? volDocs, bool? registerDocs)
|
||||
{
|
||||
/* koordiniert das Erstellen der einzelnen Dokumenttypen/-sorten*/
|
||||
//try
|
||||
//{
|
||||
var h2w = new Hamann2Word(hamannDoc, docOpt);
|
||||
if (letterDocs == true || letterDocs == false) // DEV
|
||||
{
|
||||
Logger.Out("Erstelle docx für einzelbriefe");
|
||||
h2w.MakeLetterDocuments(lib, years);
|
||||
}
|
||||
if (volDocs == true)
|
||||
{
|
||||
Logger.Out("Erstelle docx für BandDateien");
|
||||
h2w.MakeYearDocuments(lib, years);
|
||||
}
|
||||
if (registerDocs == true)
|
||||
{
|
||||
Logger.Out("Erstelle docx für Register");
|
||||
Hamann2Word.MakeRegisterComms();
|
||||
}
|
||||
//}
|
||||
//catch (Exception ex)
|
||||
//{
|
||||
// Logger.Out(ex.Message);
|
||||
// System.IO.File.WriteAllText(Hamann2Word.OutputDir + "logfile.txt", Logger.LogString.ToString());
|
||||
// Environment.Exit(1);
|
||||
//}
|
||||
System.IO.File.WriteAllText(Hamann2Word.OutputDir + "logfile.txt", Logger.LogString.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
290
HamannPrinter/XMLMerger.cs
Normal file
290
HamannPrinter/XMLMerger.cs
Normal file
@@ -0,0 +1,290 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace HamannPrinter
|
||||
{
|
||||
public static class XMLMerger
|
||||
{
|
||||
class Merger
|
||||
{
|
||||
public Action<string[]> LogSink { get; set; } = null;
|
||||
|
||||
private bool _raised = false;
|
||||
|
||||
private XElement _opus = new XElement("opus");
|
||||
private XElement _data = new XElement("data");
|
||||
private XElement _definitions = new XElement("definitions");
|
||||
private XElement _descriptions = new XElement("descriptions");
|
||||
private XElement _traditions = new XElement("traditions");
|
||||
private XElement _document = new XElement("document");
|
||||
private XElement _kommentare = new XElement("kommentare");
|
||||
private XElement _marginalien = new XElement("marginalien");
|
||||
private XElement _edits = new XElement("edits");
|
||||
|
||||
|
||||
public Merger()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Returns a valid XML-File if there wer no errors and everything's there, otherwise null
|
||||
public XDocument GetXDocument()
|
||||
{
|
||||
_opus.Add(_document);
|
||||
_opus.Add(_kommentare);
|
||||
_opus.Add(_marginalien);
|
||||
_opus.Add(_edits);
|
||||
_opus.Add(_traditions);
|
||||
_data.Add(_definitions);
|
||||
_data.Add(_descriptions);
|
||||
_opus.Add(_data);
|
||||
if (_botched())
|
||||
{
|
||||
Console.WriteLine("Es wurden nicht alle notwendigen Elemente gefunden oder es gab Fehler beim Parsen der XML-Daten.");
|
||||
return null;
|
||||
}
|
||||
Console.WriteLine("Zusammensetzen des Dokuments erfolgreich!");
|
||||
return new XDocument(_opus);
|
||||
}
|
||||
|
||||
// Adds a document and parses it, catching all exceptions and writing to standard log
|
||||
public bool Add(string path)
|
||||
{
|
||||
Console.WriteLine(path + " wird geparst...");
|
||||
try
|
||||
{
|
||||
var currdoc = XDocument.Load(path, LoadOptions.PreserveWhitespace);
|
||||
if (currdoc.Root.Name != "opus" ||
|
||||
!currdoc.Root.Elements().Where(x => x.Name == "data" ||
|
||||
x.Name == "document" ||
|
||||
x.Name == "kommcat" ||
|
||||
x.Name == "marginalien" ||
|
||||
x.Name == "traditions" ||
|
||||
x.Name == "definitions" ||
|
||||
x.Name == "descriptions" ||
|
||||
x.Name == "edits").Any())
|
||||
{
|
||||
Console.WriteLine(path + " scheint keine Hamann-Datei zu sein",
|
||||
"Eine Hamann-Datei beginnt stets mit <opus>, gefolgt von <data> oder <document>.");
|
||||
return false;
|
||||
}
|
||||
_dataParser(currdoc.Root, path);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Fehler beim Parsen von " + path + ": ", ex.Message);
|
||||
_raised = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Adds and parses multiple documents
|
||||
public bool Add(params string[] path)
|
||||
{
|
||||
foreach (var s in path) this.Add(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Validates the document and checks if everything's there.
|
||||
private bool _botched()
|
||||
{
|
||||
if (!_traditions.Elements().Any())
|
||||
{
|
||||
Console.WriteLine("Keine Überlieferungsdaten gefunden!");
|
||||
return true;
|
||||
}
|
||||
if (!_descriptions.Elements().Any())
|
||||
{
|
||||
Console.WriteLine("Keine Metadaten der Briefe gefunden!");
|
||||
return true;
|
||||
}
|
||||
if (!_definitions.Elements().Any())
|
||||
{
|
||||
Console.WriteLine("Keine Referenzdaten für Personen- und Ortsnamen gefunden!");
|
||||
return true;
|
||||
}
|
||||
if (!_edits.Elements().Any())
|
||||
{
|
||||
Console.WriteLine("Keine Daten zu den Texteingriffen gefunden!");
|
||||
return true;
|
||||
}
|
||||
//if (!_data.Elements().Any())
|
||||
//{
|
||||
// Console.WriteLine("Fehler beim Zusammensetzen der Datei!");
|
||||
// return true;
|
||||
//}
|
||||
if (!_kommentare.Elements().Any())
|
||||
{
|
||||
Console.WriteLine("Keine Kommentare gefunden!");
|
||||
return true;
|
||||
}
|
||||
if (!_marginalien.Elements().Any())
|
||||
{
|
||||
Console.WriteLine("Keine Marginalien gefunden!");
|
||||
return true;
|
||||
}
|
||||
if (!_document.Elements().Any())
|
||||
{
|
||||
Console.WriteLine("Keine Brieftexte gefunden!");
|
||||
return true;
|
||||
}
|
||||
if (!_opus.Elements().Any())
|
||||
{
|
||||
Console.WriteLine("Fehler beim Zusammensetzen der Datei");
|
||||
return true;
|
||||
}
|
||||
if (_raised)
|
||||
{
|
||||
Console.WriteLine("Es gab ungültige XML-Daten oder Dateinamen.");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Sorts everything in it's prospective parent elements
|
||||
private void _dataParser(XElement data, string path)
|
||||
{
|
||||
foreach (var x in data.Elements())
|
||||
{
|
||||
if (!x.IsEmpty &&
|
||||
String.IsNullOrWhiteSpace(x.Value) &&
|
||||
x.Name == "definitions" ||
|
||||
x.Name == "traditions" ||
|
||||
x.Name == "descriptions" ||
|
||||
x.Name == "edits" ||
|
||||
x.Name == "kommentare" ||
|
||||
x.Name == "marginalien" ||
|
||||
x.Name == "document" ||
|
||||
x.Name == "data")
|
||||
{
|
||||
if (x.Name == "document" && x.Descendants("letterText").Any())
|
||||
{
|
||||
_document.Add(x.Elements());
|
||||
Console.WriteLine("Briefe gefunden.");
|
||||
continue;
|
||||
}
|
||||
if (x.Name == "kommentare" && x.Descendants("kommentar").Any())
|
||||
{
|
||||
_kommentare.Add(x.Elements("kommcat"));
|
||||
Console.WriteLine("Kommentare gefunden.");
|
||||
continue;
|
||||
}
|
||||
if (x.Name == "marginalien" && x.Descendants("marginal").Any())
|
||||
{
|
||||
_marginalien.Add(x.Elements("marginal"));
|
||||
Console.WriteLine("Marginalien gefunden.");
|
||||
continue;
|
||||
}
|
||||
if (x.Name == "traditions" && x.Elements("letterTradition").Any())
|
||||
{
|
||||
_traditions.Add(x.Elements("letterTradition"));
|
||||
Console.WriteLine("Angaben zur Überlieferung gefunden.");
|
||||
continue;
|
||||
}
|
||||
if (x.Name == "edits" && x.Elements("editreason").Any())
|
||||
{
|
||||
_edits.Add(x.Elements("editreason"));
|
||||
Console.WriteLine("Texteingriffe gefunden.");
|
||||
continue;
|
||||
}
|
||||
if (x.Name == "definitions" && x.Elements().Where(s => s.Name == "structureDefs" ||
|
||||
s.Name == "locationDefs" ||
|
||||
s.Name == "handDefs" ||
|
||||
s.Name == "personDefs").Any())
|
||||
{
|
||||
_definitions.Add(x.Elements().Where(s => s.Name == "structureDefs" ||
|
||||
s.Name == "locationDefs" ||
|
||||
s.Name == "handDefs" ||
|
||||
s.Name == "personDefs"));
|
||||
Console.WriteLine("Referenzdaten zu Personen, Quellen und Orten gefunden.");
|
||||
continue;
|
||||
}
|
||||
if (x.Name == "descriptions" && x.Elements("letterDesc").Any())
|
||||
{
|
||||
_descriptions.Add(x.Elements("letterDesc"));
|
||||
Console.WriteLine("Metadaten für Briefe gefunden.");
|
||||
continue;
|
||||
}
|
||||
if (x.Name == "data")
|
||||
{
|
||||
_dataParser(x, path);
|
||||
Console.WriteLine("<data> gefunden. Rekursion...");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Concatinator
|
||||
{
|
||||
private string SourceDirectory { get; set; }
|
||||
public string HamannXmlFile { get; set; }
|
||||
|
||||
public Concatinator(string sourcedir)
|
||||
{
|
||||
SourceDirectory = sourcedir;
|
||||
getFilePath(SourceDirectory);
|
||||
}
|
||||
|
||||
private void getFilePath(string source)
|
||||
{
|
||||
if (Directory.Exists(source))
|
||||
{
|
||||
var x = Directory.GetFiles(source + @"\", "*.xml");
|
||||
if (x.Length == 0)
|
||||
{
|
||||
Console.WriteLine("Keine XML-Dateien in " + source + @"\" + " gefunden.");
|
||||
}
|
||||
{
|
||||
foreach (var f in x)
|
||||
{
|
||||
Console.WriteLine("Datei " + f + " gefunden.");
|
||||
}
|
||||
var ret = ParseFiles(x);
|
||||
if (ret == null)
|
||||
{
|
||||
Console.WriteLine("Parsen der Dateien fehlgeschlagen. Sind die Briefe, Metadaten und Referenzdaten vorhanden?");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Parsen der Dateien erfolgreich. Briefe, Metadaten und Referenzen gefunden.");
|
||||
HamannXmlFile = ParseConcatinated(ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Verzeichnis nicht existent");
|
||||
}
|
||||
}
|
||||
|
||||
private string ParseConcatinated(XDocument document)
|
||||
{
|
||||
try
|
||||
{
|
||||
document.Save(SourceDirectory + @"\HAMANN.xml");
|
||||
Console.WriteLine("Die Quelldatei wurde unter " + SourceDirectory + @"\HAMANN.xml gespeichert.");
|
||||
return SourceDirectory + @"\HAMANN.xml";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Das Speichern von " + SourceDirectory + @"\HAMANN.xml" + " ist fehlgeschlagen", ex.Message);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
static public XDocument ParseFiles(string[] files)
|
||||
{
|
||||
|
||||
var merge = new Merger();
|
||||
merge.Add(files);
|
||||
return merge.GetXDocument();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user