2018-11-10 01:19:54 +00:00
|
|
|
|
using System;
|
2018-11-10 19:58:45 +00:00
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Xml;
|
2018-11-10 18:15:30 +00:00
|
|
|
|
using S22.Xmpp;
|
|
|
|
|
|
2018-11-10 01:19:54 +00:00
|
|
|
|
namespace RhinoReminds
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public class Reminder
|
|
|
|
|
{
|
|
|
|
|
public int Id { get; }
|
2018-11-10 18:15:30 +00:00
|
|
|
|
public string Jid { get; }
|
|
|
|
|
public Jid JidObj => new Jid(Jid);
|
2018-11-10 01:19:54 +00:00
|
|
|
|
public DateTime Time { get; }
|
|
|
|
|
public string Message { get; }
|
|
|
|
|
|
2018-11-10 18:15:30 +00:00
|
|
|
|
public Reminder(int inId, string inJid, DateTime inTime, string inMessage)
|
2018-11-10 01:19:54 +00:00
|
|
|
|
{
|
|
|
|
|
Id = inId;
|
2018-11-10 18:15:30 +00:00
|
|
|
|
Jid = inJid;
|
2018-11-10 01:19:54 +00:00
|
|
|
|
Time = inTime;
|
|
|
|
|
Message = inMessage;
|
|
|
|
|
}
|
2018-11-10 18:15:30 +00:00
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return $"[Reminder Id={Id}, Jid={Jid}, Time={Time}, Message={Message}";
|
|
|
|
|
}
|
2018-11-10 19:58:45 +00:00
|
|
|
|
|
|
|
|
|
#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
|
2018-11-10 01:19:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|