// Copyright (c) 2017- schick Informatik // Description: Helper class for customs data serialization // using bsmd.database.EasyPeasy; using System; using System.IO; using System.Xml.Serialization; namespace ENI2.Util { public static class EasyPeasyState { private static readonly string Root = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "EasyPeasy"); private static readonly string StatePath = Path.Combine(Root, "state.xml"); public static ProofRequest LoadOrCreate() { try { if (File.Exists(StatePath)) { using (var fs = File.OpenRead(StatePath)) { var ser = new XmlSerializer(typeof(ProofRequest)); return (ProofRequest)ser.Deserialize(fs); } } } catch { /* swallow & create new */ } return CreateDefault(); } public static void Save(ProofRequest data) { Directory.CreateDirectory(Root); using (var fs = File.Create(StatePath)) { var ser = new XmlSerializer(typeof(ProofRequest)); ser.Serialize(fs, data); } } public static ProofRequest CreateDefault() { return new ProofRequest { ProofInformationT2LT2LF = new ProofInformationT2LT2LF { RequestedValidityOfTheProof = new RequestedValidityOfTheProof(), GoodsShipmentForT2LT2LF = new GoodsShipmentForT2LT2LF { LocationOfGoods = new LocationOfGoods(), TransportDocuments = new TransportDocuments() } } }; } } }