80 lines
2.6 KiB
C#
80 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using YamlDotNet.Serialization.NamingConventions;
|
|
using YamlDotNet.Serialization;
|
|
using System.Diagnostics;
|
|
|
|
namespace WebDoorCreator.Data.DTO
|
|
{
|
|
[Serializable]
|
|
public class FinishingDto
|
|
{
|
|
public Dictionary<string, Dictionary<string, string>> finishing { get; set; } = new Dictionary<string, Dictionary<string, string>>();
|
|
|
|
/// <summary>
|
|
/// Recupera oggetto serializzato YAML oppure "semplificato"
|
|
/// </summary>
|
|
/// <param name="removeDoorOps"></param>
|
|
/// <returns></returns>
|
|
public string GetSerialized(bool removeDoorOps)
|
|
{
|
|
string answ = "";
|
|
StringBuilder sb = new StringBuilder();
|
|
List<string> outLines = new List<string>();
|
|
string rawData = GetObjYaml();
|
|
if (removeDoorOps)
|
|
{
|
|
var lines = rawData.Split(Environment.NewLine);
|
|
foreach (var item in lines)
|
|
{
|
|
if (item != "")
|
|
{
|
|
if (item.Split(":")[1] != "")
|
|
{
|
|
if (item.StartsWith(" "))
|
|
{
|
|
sb.AppendLine($"{char.ToLower(item.Substring(4)[0])}{item.Substring(5)}");
|
|
}
|
|
else
|
|
{
|
|
sb.AppendLine(item);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
answ = sb.ToString();
|
|
}
|
|
else
|
|
{
|
|
answ = rawData;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
//public static string? FirstCharToLowerCase(this string? str)
|
|
//{
|
|
// if (!string.IsNullOrEmpty(str) && char.IsUpper(str[0]))
|
|
// return str.Length == 1 ? char.ToLower(str[0]).ToString() : char.ToLower(str[0]) + str[1..];
|
|
|
|
// return str;
|
|
//}
|
|
|
|
/// <summary>
|
|
/// Restituisce conf serializzata in formato YAML
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string GetObjYaml()
|
|
{
|
|
var serializer = new SerializerBuilder()
|
|
.WithNamingConvention(CamelCaseNamingConvention.Instance)
|
|
.WithIndentedSequences()
|
|
.Build();
|
|
var rawdata = serializer.Serialize(this);
|
|
return rawdata;
|
|
}
|
|
}
|
|
}
|