servuo/Scripts/Accounting/AccountComment.cs

74 lines
2.4 KiB
C#
Raw Permalink Normal View History

2013-10-28 07:09:42 +00:00
using System;
using System.Xml;
namespace Server.Accounting
{
public class AccountComment
{
private readonly string m_AddedBy;
private string m_Content;
private DateTime m_LastModified;
/// <summary>
/// Constructs a new AccountComment instance.
/// </summary>
/// <param name="addedBy">Initial AddedBy value.</param>
/// <param name="content">Initial Content value.</param>
public AccountComment(string addedBy, string content)
{
2020-04-16 21:29:55 -04:00
m_AddedBy = addedBy;
m_Content = content;
m_LastModified = DateTime.UtcNow;
2013-10-28 07:09:42 +00:00
}
/// <summary>
/// Deserializes an AccountComment instance from an xml element.
/// </summary>
/// <param name="node">The XmlElement instance from which to deserialize.</param>
public AccountComment(XmlElement node)
{
2020-04-16 21:29:55 -04:00
m_AddedBy = Utility.GetAttribute(node, "addedBy", "empty");
m_LastModified = Utility.GetXMLDateTime(Utility.GetAttribute(node, "lastModified"), DateTime.UtcNow);
m_Content = Utility.GetText(node, "");
2013-10-28 07:09:42 +00:00
}
/// <summary>
/// A string representing who added this comment.
/// </summary>
2020-04-16 21:29:55 -04:00
public string AddedBy => m_AddedBy;
2013-10-28 07:09:42 +00:00
/// <summary>
/// Gets or sets the body of this comment. Setting this value will reset LastModified.
/// </summary>
public string Content
{
get
{
2020-04-16 21:29:55 -04:00
return m_Content;
2013-10-28 07:09:42 +00:00
}
set
{
2020-04-16 21:29:55 -04:00
m_Content = value;
m_LastModified = DateTime.UtcNow;
2013-10-28 07:09:42 +00:00
}
}
/// <summary>
/// The date and time when this account was last modified -or- the comment creation time, if never modified.
/// </summary>
2020-04-16 21:29:55 -04:00
public DateTime LastModified => m_LastModified;
2013-10-28 07:09:42 +00:00
/// <summary>
/// Serializes this AccountComment instance to an XmlTextWriter.
/// </summary>
/// <param name="xml">The XmlTextWriter instance from which to serialize.</param>
public void Save(XmlTextWriter xml)
{
xml.WriteStartElement("comment");
2020-04-16 21:29:55 -04:00
xml.WriteAttributeString("addedBy", m_AddedBy);
2013-10-28 07:09:42 +00:00
2020-04-16 21:29:55 -04:00
xml.WriteAttributeString("lastModified", XmlConvert.ToString(m_LastModified, XmlDateTimeSerializationMode.Utc));
2013-10-28 07:09:42 +00:00
2020-04-16 21:29:55 -04:00
xml.WriteString(m_Content);
2013-10-28 07:09:42 +00:00
xml.WriteEndElement();
}
}
}