201207PX Continued on MV data structures, moved MV attachment to more generic Blob

This commit is contained in:
phantomix 2020-12-07 14:15:48 +01:00
parent fca076b39d
commit 39fabe4ee5
4 changed files with 60 additions and 6 deletions

View File

@ -201,6 +201,8 @@
<Compile Include="model\Mv.cs" />
<Compile Include="model\svg\SvgFile.cs" />
<Compile Include="model\svg\SvgPath.cs" />
<Compile Include="model\MvList.cs" />
<Compile Include="model\Blob.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />

14
model/Blob.cs Normal file
View File

@ -0,0 +1,14 @@
using System;
using System.Xml.Serialization;
namespace dezentrale.model
{
public class Blob
{
[XmlIgnore] public string Guid { get; set; }
public string FileName { get; set; }
public byte[] Data { get; set; }
public DateTime Added { get; set; } = DateTime.Now;
public DateTime LastChanged { get; set; }
}
}

View File

@ -10,11 +10,7 @@ namespace dezentrale.model
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; }
@ -26,7 +22,7 @@ namespace dezentrale.model
public string AdditionalInfo { get; set; }
public List<MvInvitedMember> Invited { get; set; } = new List<MvInvitedMember>();
public List<MvAttachment> Attachments { get; set; } = new List<MvAttachment>();
public List<Blob> Attachments { get; set; } = new List<Blob>();
public FormMail BuildInvitation()
{

42
model/MvList.cs Normal file
View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
namespace dezentrale.model
{
public class MvList : XmlData
{
[XmlElement("Mv")] public List<Mv> Entries = new List<Mv>();
[XmlIgnore] public static string FileName { get; } = "mv.xml";
public MvList()
{
}
public static MvList LoadFromFile()
{
try
{
string mtlFile = System.IO.Path.Combine(Program.config.DbDirectory, FileName);
return (MvList)XmlData.LoadFromFile(mtlFile, typeof(MvList));
}
catch (Exception ex)
{
Console.WriteLine($"Error while loading MoneyTransferList: {ex.Message}");
return new MvList();
}
}
public static bool SaveToFile(MvList list)
{
string mvFile = System.IO.Path.Combine(Program.config.DbDirectory, FileName);
Program.config.DbChangedSinceExport = true;
Program.config.LastDbLocalChange = DateTime.Now;
XmlData.SaveToFile(Program.ConfigFile, Program.config);
return XmlData.SaveToFile(mvFile, list);
}
public bool SaveToFile()
{
return SaveToFile(this);
}
}
}