2018-11-10 01:19:54 +00:00
|
|
|
|
using System;
|
2018-12-27 12:29:41 +00:00
|
|
|
|
using System.Collections.Generic;
|
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
|
|
|
|
|
{
|
|
|
|
|
|
2018-12-27 12:29:41 +00:00
|
|
|
|
public class Reminder : IEquatable<Reminder>
|
2018-11-10 01:19:54 +00:00
|
|
|
|
{
|
|
|
|
|
public int Id { get; }
|
2018-12-27 12:29:41 +00:00
|
|
|
|
public string Jid => JidObj.ToString();
|
|
|
|
|
public Jid JidObj { get; }
|
|
|
|
|
public DateTime Time { get; private set; }
|
2018-11-10 01:19:54 +00:00
|
|
|
|
public string Message { get; }
|
|
|
|
|
|
2018-12-27 12:29:41 +00:00
|
|
|
|
public Reminder(int inId, Jid inJid, DateTime inTime, string inMessage)
|
2018-11-10 01:19:54 +00:00
|
|
|
|
{
|
|
|
|
|
Id = inId;
|
2018-12-27 12:29:41 +00:00
|
|
|
|
JidObj = inJid.GetBareJid();
|
2018-11-10 01:19:54 +00:00
|
|
|
|
Time = inTime;
|
|
|
|
|
Message = inMessage;
|
|
|
|
|
}
|
2018-11-10 18:15:30 +00:00
|
|
|
|
|
2018-12-27 12:29:41 +00:00
|
|
|
|
public void TweakTime() {
|
|
|
|
|
Time = Time.AddMilliseconds(1);
|
2018-11-10 18:15:30 +00:00
|
|
|
|
}
|
2018-11-10 19:58:45 +00:00
|
|
|
|
|
|
|
|
|
|
2018-12-27 12:29:41 +00:00
|
|
|
|
#region Overrides
|
|
|
|
|
|
|
|
|
|
public override bool Equals(object obj) {
|
|
|
|
|
if (!(obj is Reminder)) return false;
|
|
|
|
|
Reminder otherReminder = obj as Reminder;
|
|
|
|
|
return otherReminder.Id == Id &&
|
|
|
|
|
otherReminder.JidObj == JidObj && // Will *always* be a bare Jid
|
|
|
|
|
otherReminder.Time == Time &&
|
|
|
|
|
otherReminder.Message == Message;
|
|
|
|
|
}
|
|
|
|
|
// For IEquatable<Reminder> implementation
|
|
|
|
|
public bool Equals(Reminder otherReminder) => Equals((object)otherReminder);
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode() {
|
|
|
|
|
int hashCode = -81903051;
|
|
|
|
|
hashCode = (hashCode * -1521134295) + Id.GetHashCode();
|
|
|
|
|
hashCode = (hashCode * -1521134295) + EqualityComparer<Jid>.Default.GetHashCode(JidObj);
|
|
|
|
|
hashCode = (hashCode * -1521134295) + Time.GetHashCode();
|
|
|
|
|
hashCode = (hashCode * -1521134295) + EqualityComparer<string>.Default.GetHashCode(Message);
|
|
|
|
|
return hashCode;
|
|
|
|
|
}
|
|
|
|
|
public static bool operator ==(Reminder reminder1, Reminder reminder2) => EqualityComparer<Reminder>.Default.Equals(reminder1, reminder2);
|
|
|
|
|
public static bool operator !=(Reminder reminder1, Reminder reminder2) => !(reminder1 == reminder2);
|
|
|
|
|
|
|
|
|
|
public override string ToString() {
|
|
|
|
|
return $"[Reminder Id={Id}, Jid={Jid}, Time={Time}, Message=\"{Message}\"]";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region XML
|
2018-11-10 19:58:45 +00:00
|
|
|
|
|
|
|
|
|
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-12-27 12:29:41 +00:00
|
|
|
|
|
|
|
|
|
|
2018-11-10 01:19:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|