310f304b7e
- testing gestione file conf YAML/JSON - bozza acquisizione e salvataggio dati conf da IOB sul campo
102 lines
3.0 KiB
C#
102 lines
3.0 KiB
C#
using Newtonsoft.Json;
|
|
using YamlDotNet.Serialization.NamingConventions;
|
|
using YamlDotNet.Serialization;
|
|
using static IobConf.Core.Enum;
|
|
|
|
// <Auto-Generated>
|
|
// This is here so CodeMaid doesn't reorganize this document
|
|
// </Auto-Generated>
|
|
namespace IobConf.Core
|
|
{
|
|
/// <summary>
|
|
/// Albero configurazione globale IOB
|
|
/// </summary>
|
|
[Serializable]
|
|
public class IobConfTree
|
|
{
|
|
/// <summary>
|
|
/// Init classe configurazione
|
|
/// </summary>
|
|
public IobConfTree()
|
|
{ }
|
|
/// <summary>
|
|
/// Codice univoco IOB
|
|
/// </summary>
|
|
public string codIOB { get; set; } = "ND";
|
|
|
|
/// <summary>
|
|
/// TIpologia generale dell'adapter
|
|
/// </summary>
|
|
public ComLayer GeneralCom { get; set; } = ComLayer.ND;
|
|
|
|
/// <summary>
|
|
/// Tipo Adapter specifico (implementazione)
|
|
/// </summary>
|
|
public AdapterType IobType { get; set; }= AdapterType.ND;
|
|
|
|
/// <summary>
|
|
/// Dati configurazione CNC
|
|
/// </summary>
|
|
public CncConf CncData { get; set; } = new CncConf();
|
|
|
|
#region Metodi Serializzazione
|
|
|
|
/// <summary>
|
|
/// Restituisce conf serializzata in formato JSON
|
|
/// </summary>
|
|
/// <param name="filePath"></param>
|
|
/// <returns></returns>
|
|
public string getJson()
|
|
{
|
|
string rawdata = JsonConvert.SerializeObject(this, Formatting.Indented);
|
|
return rawdata;
|
|
}
|
|
/// <summary>
|
|
/// Restituisce conf serializzata in formato YAML
|
|
/// </summary>
|
|
/// <param name="filePath"></param>
|
|
/// <returns></returns>
|
|
public string getYaml()
|
|
{
|
|
var serializer = new SerializerBuilder()
|
|
.WithNamingConvention(CamelCaseNamingConvention.Instance)
|
|
.Build();
|
|
var rawdata = serializer.Serialize(this);
|
|
return rawdata;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Metodi Load/Save
|
|
|
|
/// <summary>
|
|
/// Scrive conf serializzata in formato JSON
|
|
/// </summary>
|
|
/// <param name="filePath"></param>
|
|
/// <returns></returns>
|
|
public bool SaveJson(string filePath)
|
|
{
|
|
bool answ = false;
|
|
string rawdata = JsonConvert.SerializeObject(this, Formatting.Indented);
|
|
File.WriteAllText(filePath, rawdata);
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Scrive conf serializzata in formato YAML
|
|
/// </summary>
|
|
/// <param name="filePath"></param>
|
|
/// <returns></returns>
|
|
public bool SaveYaml(string filePath)
|
|
{
|
|
bool answ = false;
|
|
var serializer = new SerializerBuilder()
|
|
.WithNamingConvention(CamelCaseNamingConvention.Instance)
|
|
.Build();
|
|
var rawdata = serializer.Serialize(this);
|
|
File.WriteAllText(filePath, rawdata);
|
|
return answ;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |