RhinoReminds/RhinoReminds/Reminder.cs

73 lines
1.5 KiB
C#
Raw Normal View History

using System;
using System.Net;
using System.Xml;
using S22.Xmpp;
namespace RhinoReminds
{
public class Reminder
{
public int Id { get; }
public string Jid { get; }
public Jid JidObj => new Jid(Jid);
public DateTime Time { get; }
public string Message { get; }
public Reminder(int inId, string inJid, DateTime inTime, string inMessage)
{
Id = inId;
Jid = inJid;
Time = inTime;
Message = inMessage;
}
public override string ToString()
{
return $"[Reminder Id={Id}, Jid={Jid}, Time={Time}, Message={Message}";
}
#region XML
public void WriteToXml(XmlWriter xml)
{
xml.WriteStartElement("Reminder");
xml.WriteElementString("Id", Id.ToString());
xml.WriteElementString("Jid", Jid);
xml.WriteElementString("Time", Time.ToString());
xml.WriteElementString("Message", WebUtility.HtmlEncode(Message));
xml.WriteEndElement();
}
public static Reminder FromXml(XmlNode xml)
{
int id = -1; string jid = string.Empty, message = string.Empty; DateTime dateTime = DateTime.Now;
foreach (XmlNode subNode in xml.ChildNodes) {
switch (subNode.Name) {
case "Id":
id = int.Parse(subNode.InnerText);
break;
case "Jid":
jid = subNode.InnerText;
break;
case "Time":
dateTime = DateTime.Parse(subNode.InnerText);
break;
case "Message":
message = WebUtility.HtmlDecode(subNode.InnerText);
break;
}
}
return new Reminder(id, jid, dateTime, message);
}
#endregion
}
}