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 SwingDto { public Dictionary> swing { get; set; } = new Dictionary>(); public string secure { get; set; } = "UP"; public string material { get; set; } = "wood"; /// /// Recupera oggetto serializzato YAML oppure "semplificato" /// /// /// public string GetSerialized(bool removeDoorOps) { string answ = ""; StringBuilder sb = new StringBuilder(); List outLines = new List(); 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; //} /// /// Restituisce conf serializzata in formato YAML /// /// public string GetObjYaml() { var serializer = new SerializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance) .WithIndentedSequences() .Build(); var rawdata = serializer.Serialize(this); return rawdata; } } }