Files
webdoorcreator/WebDoorCreator.Data/DTO/DDFDto.cs
T
2023-04-21 17:25:09 +02:00

134 lines
4.2 KiB
C#

using System.Text;
using WebDoorCreator.Data.DbModels;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
namespace WebDoorCreator.Data.DTO
{
[Serializable]
public class DDFDto
{
#region Public Constructors
public DDFDto()
{ }
#endregion Public Constructors
#region Public Properties
public string version { get; set; } = "0";
public bool produce { get; set; } = true;
public string measures { get; set; } = "mm";
public string code { get; set; } = "0015943";
public OrderDto order { get; set; } = new OrderDto();
public DateTime date { get; set; } = DateTime.Now;
public string piece { get; set; } = "DO_1";
public Sizing size { get; set; } = new Sizing();
public string swing { get; set; } = "RH";
public string secure { get; set; } = "UP";
public string material { get; set; } = "wood";
public Edges profiles { get; set; } = new Edges();
#endregion Public Properties
#region Public Methods
/// <summary>
/// Restituisce conf serializzata in formato YAML
/// </summary>
/// <returns></returns>
public string GetObjYaml()
{
var serializer = new SerializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build();
var rawdata = serializer.Serialize(this);
return rawdata;
}
/// <summary>
/// Scrive conf serializzata in formato YAML
/// </summary>
/// <param name="filePath"></param>
/// <param name="headRows"></param>
/// <param name="footRows"></param>
/// <param name="serialDoorOps"></param>
/// <returns></returns>
public string GetSerialized(List<string> headRows, List<string> footRows, string serialDoorOps)
{
string fullData = "";
StringBuilder sb = new StringBuilder();
try
{
// header!
if (headRows != null && headRows.Count > 0)
{
sb = new StringBuilder();
foreach (var row in headRows)
{
sb.AppendLine(row);
}
fullData = sb.ToString();
}
// obj principale
var currYaml = GetObjYaml();
fullData += currYaml;
// aggiungo la parte doorOp come yaml reale/striped...
if (!string.IsNullOrEmpty(serialDoorOps))
{
fullData += serialDoorOps;
}
// footer!
if (footRows != null && footRows.Count > 0)
{
sb = new StringBuilder();
foreach (var row in footRows)
{
sb.AppendLine(row);
}
fullData += sb.ToString();
}
}
catch
{ }
return fullData;
}
#if false
/// <summary>
/// Scrive conf serializzata in formato YAML
/// </summary>
/// <param name="filePath"></param>
/// <param name="headRows"></param>
/// <param name="footRows"></param>
/// <param name="serialDoorOps"></param>
/// <returns></returns>
public bool SaveYaml(string filePath, List<string> headRows, List<string> footRows, string serialDoorOps)
{
bool answ = false;
try
{
string fullData = GetSerialized(headRows, footRows, serialDoorOps);
// FixMe / todo: spostare alla classe che lo chiama... elimino eventuale vecchio file...
if (File.Exists(filePath))
{
File.Delete(filePath);
}
// scrivo!
File.WriteAllText(filePath, fullData);
answ = true;
}
catch
{ }
return answ;
}
#endif
#endregion Public Methods
}
}