201122PX Preparations for MV list, added SVG generation code

This commit is contained in:
phantomix 2020-11-22 22:44:15 +01:00
parent 096706b69c
commit 0cbe0545b1
5 changed files with 213 additions and 3 deletions

View File

@ -73,6 +73,7 @@ namespace dezentrale
Export = 3,
Import = 4,
BankImport = 5,
Test = 255,
}
public static eMode ProgramMode = eMode.Gui;
@ -150,6 +151,7 @@ namespace dezentrale
case "mode":
switch (argv.ToLower())
{
case "test": ProgramMode = eMode.Test; break;
case "cl": ProgramMode = eMode.CommandLine; break;
case "gui": ProgramMode = eMode.Gui; break;
case "cronjob":
@ -190,6 +192,9 @@ namespace dezentrale
switch (ProgramMode)
{
case eMode.Test:
model.svg.SvgFile.Test("SvgFileTest.svg");
break;
case eMode.Gui:
frmMain w = new frmMain();
Application.Run(w);

View File

@ -198,6 +198,8 @@
<Compile Include="core\ReplaceReflectEntity.cs" />
<Compile Include="view\frmMvInvitation.cs" />
<Compile Include="core\MvInvitationProcess.cs" />
<Compile Include="model\Mv.cs" />
<Compile Include="model\svg\SvgFile.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
@ -214,6 +216,7 @@
<ItemGroup />
<ItemGroup>
<Folder Include="core\" />
<Folder Include="model\svg\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

36
model/Mv.cs Normal file
View File

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
namespace dezentrale.model
{
public class MvInvitedMember
{
public int MemberNumber { get; set; }
public DateTime InvitationDate { get; set; }
public string AuthCode { get; set; } = "";
public bool AttendedMv { get; set; } = false;
}
public class MvAttachment
{
public string FileName { get; set; }
public byte[] Blob { get; set; }
}
public class Mv : XmlData
{
public DateTime EventDate { get; set; }
public string Headline { get; set; }
public string Introduction { get; set; }
public string Place { get; set; }
public bool GenerateAuthCode { get; set; }
public string Agenda { get; set; }
public string AdditionalInfo { get; set; }
public List<MvInvitedMember> Invited { get; set; } = new List<MvInvitedMember>();
public List<MvAttachment> Attachments { get; set; } = new List<MvAttachment>();
public FormMail BuildInvitation()
{
return null;
}
}
}

164
model/svg/SvgFile.cs Normal file
View File

@ -0,0 +1,164 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
namespace dezentrale.model.svg
{
public class SvgAnchor : SvgElement
{
[XmlAttribute] public string href { get; set; } = null;
}
public class SvgDefs : SvgElement
{
}
public class SvgGroup : SvgElement
{
}
public class SvgPath : SvgElement
{
[XmlAttribute] public string d { get; set; } = null;
//helper methods for building the path ;-)
}
public class SvgRect : SvgElement
{
[XmlAttribute] public string x { get; set; } = null;
[XmlAttribute] public string y { get; set; } = null;
[XmlAttribute] public string width { get; set; } = null;
[XmlAttribute] public string height { get; set; } = null;
}
public class SvgText : SvgElement
{
[XmlText] public string Text { get; set; } = null;
}
public class SvgUse : SvgElement
{
[XmlAttribute( AttributeName = "href",
Namespace = "http://www.w3.org/1999/xlink",
Form = XmlSchemaForm.Qualified)]
public string href { get; set; } = null;
}
public abstract class SvgElement
{
//Generic SVG Element properties
[XmlAttribute] public string id { get; set; } = null;
[XmlAttribute] public string transform { get; set; } = null;
[XmlAttribute] public string fill { get; set; } = null;
[XmlAttribute] public string stroke { get; set; } = null;
[XmlAttribute("stroke-width")] public string stroke_width { get; set; } = null;
[XmlAttribute("stroke-linejoin")] public string stroke_linejoin { get; set; } = null;
[XmlElement("a", typeof(SvgAnchor))]
[XmlElement("defs", typeof(SvgDefs))] //It would be better to have defs as a separate svg section
[XmlElement("g", typeof(SvgGroup))]
[XmlElement("path", typeof(SvgPath))]
[XmlElement("rect", typeof(SvgRect))]
[XmlElement("text", typeof(SvgText))]
[XmlElement("use", typeof(SvgUse))]
public List<SvgElement> Elements { get; set; } = new List<SvgElement>();
}
[XmlRoot("svg")]
public class SvgFile : SvgElement
{
//SVG root node properties
[XmlAttribute] public string version { get; set; } = null;
[XmlAttribute] public string viewBox { get; set; } = null;
[XmlAttribute] public string preserveAspectRatio { get; set; } = null;
//[XmlAttribute("xmlns")] public string xmlns { get; set; } = "http://www.w3.org/2000/svg";
//[XmlAttribute("")]
//[XmlAttribute] public string viewBox { get; set; } = null;
[XmlAttribute] public string width { get; set; } = null;
[XmlAttribute] public string height { get; set; } = null;
[XmlElement] public string title { get; set; } = null;
[XmlElement] public string desc { get; set; } = null;
public bool SaveToFile(string fileName, Type[] extraTypes = null)
{
try
{
//if (this == null) //if (ds == null) throw new NullReferenceException("XmlData.SaveToFile(fileName, ds): ds == null");
Console.WriteLine($"SvgFile.SaveToFile({fileName})");
XmlSerializerNamespaces ns = new XmlSerializerNamespaces
(new[] { //XmlQualifiedName.Empty,
//new XmlQualifiedName("", "http://www.w3.org/2000/svg"),
new XmlQualifiedName("xlink", "http://www.w3.org/1999/xlink"),
});
//ns.Add("", "");
/*XmlSerializer ser;
if (extraTypes != null)
ser = new XmlSerializer(this.GetType(), extraTypes);
else
ser = new XmlSerializer(this.GetType());*/
XmlSerializer ser = new XmlSerializer(this.GetType(), "http://www.w3.org/2000/svg");
/*XmlWriterSettings settings = new XmlWriterSettings()
{
Indent = true,
//OmitXmlDeclaration = true,
};
FileStream fs;
fs = new FileStream(fileName, FileMode.Create);
using (XmlWriter writer = XmlWriter.Create(fs, settings))
{
ser.Serialize(writer, this, ns);
}*/
FileStream fs;
fs = new FileStream(fileName, FileMode.Create);
ser.Serialize(fs, this, ns);
fs.Close();
}
catch (Exception e)
{
throw e.InnerException ?? e;
}
return true;
}
public static void Test(string filename)
{
//See https://upload.wikimedia.org/wikipedia/commons/2/28/HelloWorld.svg
SvgFile svgFile = new SvgFile()
{
viewBox = "0 0 52 26",
Elements =
{
new SvgRect() {y="0", x="0", height="26", width="52"},
new SvgGroup()
{
fill="#0f0",
Elements =
{
new SvgPath() { d = "m6.5938,2.7256,0,3.252-1.5,0,0-3.252zm-3,0,0,3.252-1.5,0,0-3.252z" },
new SvgPath() { d = "m8.7617,2.7256,1.7285,0,0,3.334,2.1621,0,0-3.334,1.7285,0,0,8.748-1.7285,0,0-3.8906-2.1621,0,0,3.8906-1.7285,0z" },
new SvgPath() { d = "m21.635,11.151c-0.3984,0.164-0.8047,0.2871-1.2187,0.3691-0.4141,0.082-0.8516,0.1231-1.3125,0.1231-1.0977,0-1.9366-0.294-2.5166-0.8819-0.5801-0.5879-0.8701-1.4346-0.8701-2.54,0-1.0703,0.2793-1.916,0.8378-2.5371,0.5586-0.62109,1.3204-0.93163,2.2852-0.93164,0.9727,0,1.7275,0.28809,2.2647,0.86426,0.5371,0.57617,0.8056,1.3877,0.8056,2.4346v0.69726h-4.4473c0,0.51563,0.1563,0.90039,0.4571,1.1543s0.75,0.38091,1.3476,0.38091c0.3946,0,0.7832-0.057,1.1661-0.1699,0.3828-0.1133,0.7831-0.29304,1.2011-0.53913zm-1.453-3.6911c-0.008-0.4531-0.124-0.7959-0.349-1.0283s-0.556-0.3486-0.993-0.3486c-0.3945,0-0.709,0.12012-0.9434,0.36036-0.2343,0.24024-0.373,0.58105-0.416,1.0224z" },
new SvgPath() { d = "m24.664,8.7373,0-5.0625-1.7402,0,0-1.3184,3.457,0,0,6.3808c0,0.51563,0.08,0.88087,0.2403,1.0957,0.1601,0.21492,0.4316,0.32232,0.8144,0.32232h1.3711v1.3183h-1.8516c-0.8164,0-1.4023-0.2109-1.7578-0.6328-0.354-0.421-0.532-1.1222-0.532-2.1027z" },
new SvgPath() { d = "m31.883,8.7373,0-5.0625-1.7403,0,0-1.3184,3.4571,0,0,6.3808c0,0.51563,0.08,0.88087,0.2402,1.0957,0.1602,0.21492,0.4316,0.32232,0.8145,0.32232h1.371v1.3183h-1.8515c-0.8164,0-1.4024-0.2109-1.7578-0.6328-0.3555-0.4219-0.5332-1.123-0.5332-2.1035z" },
new SvgPath() { d = "m40.443,6.1474c-0.4101,0-0.7324,0.18067-0.9668,0.54199-0.2344,0.36134-0.3515,0.86426-0.3515,1.5088s0.1171,1.1475,0.3515,1.5088c0.2344,0.3614,0.5567,0.542,0.9668,0.542,0.4141,0,0.7383-0.1806,0.9727-0.542,0.2343-0.36132,0.3515-0.86425,0.3515-1.5088,0-0.64452-0.1172-1.1474-0.3515-1.5088-0.234-0.3613-0.559-0.542-0.973-0.542zm-3.0351,2.0508c0-1.0586,0.2744-1.8974,0.8232-2.5166,0.5488-0.61913,1.2861-0.9287,2.2119-0.92871,0.9297,0,1.669,0.30959,2.2178,0.92871,0.5488,0.61915,0.8232,1.458,0.8232,2.5166s-0.2744,1.8975-0.8232,2.5166c-0.5488,0.6192-1.2881,0.9288-2.2178,0.9288-0.9258,0-1.6631-0.3096-2.2119-0.9288-0.5488-0.6191-0.8232-1.458-0.8232-2.5166z" },
new SvgPath() { d = "m7.959,14.726,1.5118,0,0.62685,6.4219,0.7559-4.1543,1.4355,0,0.8789,4.1543,0.4922-6.4219,1.5235,0-1.0079,8.748-1.6113,0-0.9961-4.5937-0.9316,4.5937-1.5996,0z" },
new SvgPath() { d = "m18.787,18.148c-0.4102,0-0.7325,0.1806-0.9668,0.542-0.2344,0.3613-0.3516,0.8642-0.3516,1.5087,0,0.6446,0.1172,1.1475,0.3516,1.5088,0.2343,0.3614,0.5566,0.542,0.9668,0.542,0.414,0,0.7382-0.1806,0.9726-0.542,0.2344-0.3613,0.3516-0.8642,0.3516-1.5088,0-0.6445-0.1172-1.1474-0.3516-1.5087-0.2344-0.3614-0.5586-0.542-0.9726-0.542zm-3.0352,2.0507c0-1.0585,0.2744-1.8974,0.8233-2.5166,0.5488-0.6191,1.2861-0.9287,2.2119-0.9287,0.9297,0,1.6689,0.3096,2.2177,0.9287,0.5489,0.6192,0.8233,1.4581,0.8233,2.5166,0,1.0586-0.2744,1.8975-0.8233,2.5166-0.5488,0.6192-1.288,0.9288-2.2177,0.9288-0.9258,0-1.6631-0.3096-2.2119-0.9288-0.5489-0.6191-0.8233-1.458-0.8233-2.5166z" },
new SvgPath() { d = "m29.141,18.722c-0.1875-0.1719-0.4073-0.3008-0.6592-0.3867-0.252-0.086-0.5283-0.1289-0.8291-0.1289-0.3633,0-0.6807,0.063-0.9521,0.1904-0.2715,0.1269-0.4815,0.3115-0.6299,0.5537-0.094,0.1484-0.1592,0.3281-0.1963,0.5391-0.037,0.2109-0.056,0.5312-0.056,0.9609v3.0234h-1.7168v-6.5625h1.7168v1.0196c0.168-0.375,0.4258-0.6651,0.7735-0.8702,0.3476-0.205,0.7539-0.3076,1.2187-0.3076,0.2344,0,0.4639,0.028,0.6885,0.085s0.4385,0.1396,0.6416,0.249z" },
new SvgPath() { d = "m31.883,20.737,0-5.0625-1.7403,0,0-1.3184,3.4571,0,0,6.3809c0,0.5156,0.08,0.8809,0.2402,1.0957,0.1602,0.2149,0.4316,0.3223,0.8145,0.3223h1.371v1.3183h-1.8515c-0.8164,0-1.4024-0.2109-1.7578-0.6328-0.3555-0.4219-0.5332-1.123-0.5332-2.1035z" },
new SvgPath() { d = "m41.469,17.843,0-3.4864,1.7109,0,0,9.1172-1.7109,0,0-0.9726c-0.1836,0.3789-0.4209,0.664-0.7119,0.8554-0.291,0.1915-0.6338,0.2872-1.0283,0.2872-0.75,0-1.3321-0.3008-1.7461-0.9024-0.4141-0.6016-0.6211-1.4492-0.6211-2.543,0-1.1093,0.2099-1.9609,0.6299-2.5546,0.4199-0.5938,1.0185-0.8907,1.7959-0.8907,0.3515,0,0.667,0.091,0.9463,0.2725,0.2792,0.1816,0.5244,0.4541,0.7353,0.8174zm-2.3754,2.3809c0,0.6328,0.1054,1.1289,0.3164,1.4882,0.2109,0.3594,0.5019,0.5391,0.873,0.5391s0.6641-0.1797,0.8789-0.5391c0.2149-0.3593,0.3223-0.8554,0.3223-1.4882s-0.1074-1.1289-0.3223-1.4883c-0.2148-0.3594-0.5078-0.5391-0.8789-0.5391s-0.6621,0.1797-0.873,0.5391c-0.211,0.3594-0.3164,0.8555-0.3164,1.4883z" },
new SvgPath() { d = "m49.906,14.726,0,3.2519-1.5,0,0-3.2519zm-3,0,0,3.2519-1.5,0,0-3.2519z" }
}
}
}
};
svgFile.SaveToFile(filename);
}
}
}

View File

@ -46,14 +46,16 @@ namespace dezentrale.view
new MenuItem("&Add new member", mnuMain_Members_Add),
new MenuItem("&Cronjob all", lstMembers_CronjobAll),
new MenuItem("-"),
new MenuItem("&Send MV invitation...", mnuMain_Members_MV_intivation),
new MenuItem("Run MV", mnuMain_Members_MV_run),
new MenuItem("-"),
#if DEBUG
new MenuItem("Generate &Testdata", mnuMain_Members_Generate_Testdata),
new MenuItem("-"),
#endif
new MenuItem("Show numeric &info", lstMembers_mnuMain_Members_ShowInfo),
} },
new MenuItem("MV")
{ MenuItems = {
new MenuItem("&Send MV invitation...", mnuMain_Members_MV_intivation),
new MenuItem("Run MV", mnuMain_Members_MV_run),
} },
new MenuItem("Payments")
{ MenuItems = {