v1.3.0 Restructure Saxonite workspace and upgrade to .NET 10 (#1)
Move Saxonite’s projects into a dedicated `Workspace` folder and align the solution with .NET 10 and the current Common workspace. Update encryption integration, test project structure and coverage, and repository guidance and upgrade notes. - Relocate application and library projects while retaining Git rename history. - Split tests into Admin, Online, and Shared projects; add representative behavioral and serialization tests. - Update Common integration, application version, and repository documentation. Application version: 1.3.0 Reviewed-on: #1 Co-authored-by: andy <andy@sarand.com>
This commit was merged in pull request #1.
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Saxonite.Net.Standard.Base.App;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Saxonite.Net.Standard.Base.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
// Contact data - associated with Organisations, Users etc.
|
||||
//=======================================================================
|
||||
public class SaxContactData
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
private static readonly String ElementName_ContactMethods = "contactMethods";
|
||||
private static readonly String ElementName_ContactMethod = "contactMethod";
|
||||
private static readonly String AttributeName_Method = "method";
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private class ContactMethodData
|
||||
{
|
||||
public Sax.ContactMethod Method { get; set; }
|
||||
public String Value { get; set; }
|
||||
}
|
||||
private Dictionary<Sax.ContactMethod, ContactMethodData> contactMethods { get; } = new Dictionary<Sax.ContactMethod, ContactMethodData>();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction - from serialised data.
|
||||
public SaxContactData(String contactData = "")
|
||||
{
|
||||
ExtractContactData(contactData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
public List<Sax.ContactMethod> Methods { get { return contactMethods.Keys.ToList(); } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Contact Methods.
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>Extract the value associated with the specified method.</summary>
|
||||
public String GetContactMethodValue(Sax.ContactMethod method)
|
||||
{
|
||||
return contactMethods.GetValueOrDefault(method, new ContactMethodData()).Value;
|
||||
}
|
||||
|
||||
/// <summary>Set the value associated with the specified method.</summary>
|
||||
public bool SetContactMethodValue(Sax.ContactMethod method, String value)
|
||||
{
|
||||
if ((int)method < 1 || value.IsEmpty()) return false;
|
||||
ContactMethodData contactMethod = contactMethods.GetValueOrDefault(method, null);
|
||||
if (contactMethod == null)
|
||||
contactMethods.Add(method, contactMethod = new ContactMethodData() { Method = method });
|
||||
contactMethod.Value = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>Clear the value associated with the specified method.</summary>
|
||||
public bool ClearContactMethod(Sax.ContactMethod method)
|
||||
{
|
||||
return contactMethods.Remove(method);
|
||||
}
|
||||
|
||||
/// <summary>Clear all contact methods.</summary>
|
||||
public void ClearContactMethods()
|
||||
{
|
||||
contactMethods.Clear();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Serialisation.
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Extract contact methods from serialised data.
|
||||
/// </summary>
|
||||
private void ExtractContactData(String contactData)
|
||||
{
|
||||
contactMethods.Clear();
|
||||
if (StringUtil.IsEmpty(contactData)) return;
|
||||
|
||||
try
|
||||
{
|
||||
// Load XML data.
|
||||
XDocument doc = XDocument.Parse(contactData);
|
||||
XElement rootElement = doc.Root;
|
||||
foreach (XElement rootChildElement in rootElement.GetChildElements())
|
||||
{
|
||||
String rootChildElementName = rootChildElement.GetLocalName();
|
||||
if (rootChildElementName.EqualsCI(ElementName_ContactMethod))
|
||||
{
|
||||
// Contact Method.
|
||||
String methodValue = rootChildElement.GetAttributeValue(AttributeName_Method);
|
||||
Sax.ContactMethod method = EnumUtil.ParseEnum(methodValue, Sax.ContactMethod.Unknown);
|
||||
if (method != Sax.ContactMethod.Unknown)
|
||||
{
|
||||
ContactMethodData contactMethod = new ContactMethodData()
|
||||
{
|
||||
Method = method,
|
||||
Value = rootChildElement.Value
|
||||
};
|
||||
contactMethods.Add(method, contactMethod);
|
||||
}
|
||||
else SaLogger.Warn($"{SysUtil.Fn} Unrecognised contact method: " + methodValue);
|
||||
}
|
||||
else SaLogger.Warn($"{SysUtil.Fn} Unexpected 'Root' child element: " + rootChildElementName);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} " + ExceptionUtil.GetLogMessage(exc));
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Convert to serialised data.
|
||||
/// </summary>
|
||||
public String GetContactData()
|
||||
{
|
||||
try
|
||||
{
|
||||
XDocument doc = new XDocument();
|
||||
XElement contactMethodsElement = doc.AppendElement(ElementName_ContactMethods);
|
||||
foreach (ContactMethodData contactMethod in contactMethods.Values)
|
||||
{
|
||||
if ((int)contactMethod.Method < 1 || contactMethod.Value.IsEmpty()) continue;
|
||||
XElement contactMethodElement = contactMethodsElement.AppendElement(ElementName_ContactMethod, contactMethod.Value);
|
||||
contactMethodElement.SetAttribute(AttributeName_Method, contactMethod.Method.ToString());
|
||||
}
|
||||
return doc.GetXml();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} " + ExceptionUtil.GetLogMessage(exc));
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
Reference in New Issue
Block a user