110 lines
3.9 KiB
C#
110 lines
3.9 KiB
C#
|
|
using Sarand.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using static Saxonite.Net.Standard.Base.Bus.SaxUserConfig;
|
|
using System.Xml.Linq;
|
|
|
|
namespace Saxonite.Net.Standard.Base.Data
|
|
{
|
|
//==========================================================================
|
|
public class SaxConfigData
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Definitions.
|
|
private static readonly String ElementName_Config = "Config";
|
|
private static readonly String ElementName_Profile = "Profile";
|
|
private static readonly String ElementName_Eligibility = "Eligibility";
|
|
private static readonly String ElementName_HideInfo = "HideInfo";
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Profile settings.</summary>
|
|
public class ProfileData
|
|
{
|
|
//---------------------------------------------------------------
|
|
/// <summary>Eligibility settings.</summary>
|
|
public class EligibilityData
|
|
{
|
|
/// <summary>Hide the eligbiility information tip.</summary>
|
|
public bool HideInfo { get; set; }
|
|
}
|
|
public EligibilityData Eligibility { get; set; } = new EligibilityData();
|
|
|
|
//---------------------------------------------------------------
|
|
/// <summary>Serialise to XML.</summary>
|
|
public static String ToXml(ProfileData profile)
|
|
{
|
|
String fn = typeof(ProfileData).FullName + ".GetConfigData";
|
|
try
|
|
{
|
|
XDocument doc = new XDocument();
|
|
XElement configElement = doc.AppendElement(ElementName_Config);
|
|
// Profile.
|
|
XElement profileElement = configElement.AppendElement(ElementName_Profile);
|
|
// Profile - Eligibility.
|
|
XElement eligibilityElement = profileElement.AppendElement(ElementName_Eligibility);
|
|
if (profile.Eligibility.HideInfo)
|
|
eligibilityElement.AppendElement(ElementName_HideInfo, "1");
|
|
return doc.GetXml();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
SaLogger.Warn(fn + " " + ExceptionUtil.GetLogMessage(exc));
|
|
}
|
|
return "";
|
|
}
|
|
|
|
//---------------------------------------------------------------
|
|
/// <summary>Deserialise from XML.</summary>
|
|
public static ProfileData FromXml(String configData)
|
|
{
|
|
String fn = typeof(ProfileData).FullName + ".ExtractConfig";
|
|
ProfileData profile = new ProfileData();
|
|
if (StringUtil.IsEmpty(configData)) return profile;
|
|
try
|
|
{
|
|
// Load XML data.
|
|
// NB Serialised data has 'Config' as root element
|
|
XDocument doc = XDocument.Parse(configData);
|
|
XElement rootElement = doc.Root;
|
|
foreach (XElement rootChildElement in rootElement.GetChildElements())
|
|
{
|
|
String rootChildElementName = rootChildElement.GetLocalName();
|
|
if (rootChildElementName.EqualsCI(ElementName_Profile))
|
|
{
|
|
// Profile.
|
|
XElement profileElement = rootChildElement;
|
|
foreach (XElement profileChildElement in profileElement.GetChildElements())
|
|
{
|
|
String profileChildElementName = profileChildElement.GetLocalName();
|
|
if (profileChildElementName.EqualsCI(ElementName_Eligibility))
|
|
{
|
|
// Profile - Eligibility.
|
|
XElement eligibilityElement = profileChildElement;
|
|
String hideInfo = eligibilityElement.GetChildText(ElementName_HideInfo);
|
|
profile.Eligibility.HideInfo = StringUtil.ToBool(hideInfo);
|
|
}
|
|
else SaLogger.Warn(fn + " Unexpected 'Profile' child element: " + profileChildElementName);
|
|
}
|
|
}
|
|
else SaLogger.Warn(fn + " Unexpected 'Root' child element: " + rootChildElementName);
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
SaLogger.Warn(fn + " " + ExceptionUtil.GetLogMessage(exc));
|
|
}
|
|
return profile;
|
|
}
|
|
|
|
//---------------------------------------------------------------
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
|
|
//==========================================================================
|
|
}
|