From 050be28f6b40dbad90489626c19721cf9cefd545 Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Wed, 1 Sep 2010 16:25:18 +0000 Subject: [PATCH] Timespans processing implemented; PunishmentType.timeSpan implemented; Punishment.Expires implemented --- Builder/IISMainHandler/build.txt | 2 +- Common/UserContext.cs | 10 ++++++++++ Common/dataobjects/Post.cs | 1 + Common/dataobjects/Punishment.cs | 13 ++++++++++++- Common/dataobjects/PunishmentType.cs | 13 ++++++++++++- Core/Util.cs | 13 +++++++++++++ MySQLConnector/Connection.cs | 2 ++ templates/Full/PostPunish.xslt | 3 ++- templates/Full/elems/Main.xslt | 21 +++++++++++++++++++++ templates/Lite/PostPunish.xslt | 3 ++- templates/Lite/elems/Main.xslt | 21 +++++++++++++++++++++ 11 files changed, 97 insertions(+), 5 deletions(-) diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index 7cebf7d..f3d2a11 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -1001 \ No newline at end of file +1004 \ No newline at end of file diff --git a/Common/UserContext.cs b/Common/UserContext.cs index 8264973..5534a8f 100644 --- a/Common/UserContext.cs +++ b/Common/UserContext.cs @@ -50,6 +50,16 @@ namespace FLocal.Common { ); } + public static XElement ToXml(this TimeSpan timeSpan) { + return new XElement("timeSpan", + new XElement("days", (long)timeSpan.TotalDays), + new XElement("hours", timeSpan.Hours), + new XElement("minutes", timeSpan.Minutes), + new XElement("seconds", timeSpan.Seconds), + new XElement("ticks", timeSpan.Ticks) + ); + } + } } diff --git a/Common/dataobjects/Post.cs b/Common/dataobjects/Post.cs index 0789586..10ed61b 100644 --- a/Common/dataobjects/Post.cs +++ b/Common/dataobjects/Post.cs @@ -377,6 +377,7 @@ namespace FLocal.Common.dataobjects { { Punishment.TableSpec.FIELD_PUNISHMENTTYPE, new ScalarFieldValue(type.id.ToString()) }, { Punishment.TableSpec.FIELD_ISWITHDRAWED, new ScalarFieldValue("0") }, { Punishment.TableSpec.FIELD_COMMENT, new ScalarFieldValue(comment) }, + { Punishment.TableSpec.FIELD_EXPIRES, new ScalarFieldValue(DateTime.Now.Add(type.timeSpan).ToUTCString()) }, } ) ); diff --git a/Common/dataobjects/Punishment.cs b/Common/dataobjects/Punishment.cs index 776b377..28c06a0 100644 --- a/Common/dataobjects/Punishment.cs +++ b/Common/dataobjects/Punishment.cs @@ -21,6 +21,7 @@ namespace FLocal.Common.dataobjects { public const string FIELD_PUNISHMENTTYPE = "PunishmentType"; public const string FIELD_ISWITHDRAWED = "IsWithdrawed"; public const string FIELD_COMMENT = "Comment"; + public const string FIELD_EXPIRES = "Expires"; public static readonly TableSpec instance = new TableSpec(); public string name { get { return TABLE; } } public string idName { get { return FIELD_ID; } } @@ -118,6 +119,14 @@ namespace FLocal.Common.dataobjects { } } + private DateTime _expires; + public DateTime expires { + get { + this.LoadIfNotLoaded(); + return this._expires; + } + } + protected override void doFromHash(Dictionary data) { this._postId = int.Parse(data[TableSpec.FIELD_POSTID]); this._ownerId = int.Parse(data[TableSpec.FIELD_OWNERID]); @@ -127,6 +136,7 @@ namespace FLocal.Common.dataobjects { this._punishmentTypeId = int.Parse(data[TableSpec.FIELD_PUNISHMENTTYPE]); this._isWithdrawed = Util.string2bool(data[TableSpec.FIELD_ISWITHDRAWED]); this._comment = data[TableSpec.FIELD_COMMENT]; + this._expires = Util.ParseDateTimeFromTimestamp(data[TableSpec.FIELD_EXPIRES]).Value; } public XElement exportToXml(UserContext context) { @@ -138,7 +148,8 @@ namespace FLocal.Common.dataobjects { new XElement("punishmentDate", this.punishmentDate.ToXml()), this.punishmentType.exportToXml(context), new XElement("isWithdrawed", this.isWithdrawed.ToPlainString()), - new XElement("comment", this.comment) + new XElement("comment", this.comment), + new XElement("expires", this.expires) ); } diff --git a/Common/dataobjects/PunishmentType.cs b/Common/dataobjects/PunishmentType.cs index 419cfbb..06f3bdb 100644 --- a/Common/dataobjects/PunishmentType.cs +++ b/Common/dataobjects/PunishmentType.cs @@ -16,6 +16,7 @@ namespace FLocal.Common.dataobjects { public const string FIELD_DESCRIPTION = "Description"; public const string FIELD_WEIGHT = "Weight"; public const string FIELD_WEIGHTDESCRIPTION = "WeightDescription"; + public const string FIELD_TIMESPAN = "TimeSpan"; public static readonly TableSpec instance = new TableSpec(); public string name { get { return TABLE; } } public string idName { get { return FIELD_ID; } } @@ -48,10 +49,19 @@ namespace FLocal.Common.dataobjects { } } + private TimeSpan _timeSpan; + public TimeSpan timeSpan { + get { + this.LoadIfNotLoaded(); + return this._timeSpan; + } + } + protected override void doFromHash(Dictionary data) { this._description = data[TableSpec.FIELD_DESCRIPTION]; this._weight = int.Parse(data[TableSpec.FIELD_WEIGHT]); this._weightDescription = data[TableSpec.FIELD_WEIGHTDESCRIPTION]; + this._timeSpan = Util.ParseTimeSpanFromTimestamp(data[TableSpec.FIELD_TIMESPAN]).Value; } public XElement exportToXml(UserContext context) { @@ -59,7 +69,8 @@ namespace FLocal.Common.dataobjects { new XElement("id", this.id), new XElement("description", this.description), new XElement("weight", this.weight), - new XElement("weightDescription", this.weightDescription) + new XElement("weightDescription", this.weightDescription), + this.timeSpan.ToXml() ); } diff --git a/Core/Util.cs b/Core/Util.cs index 17e27e5..b553344 100644 --- a/Core/Util.cs +++ b/Core/Util.cs @@ -134,6 +134,19 @@ namespace FLocal.Core { } } + public static TimeSpan? ParseTimeSpanFromTimestamp(string raw) { + if(raw == "") { + return null; + } else { + long ticks = long.Parse(raw); + if(ticks < 1) { + return null; + } else { + return new TimeSpan(ticks); + } + } + } + public static string EOL { get { return new string(new char[] { (char)0x0d, (char)0x0a }); diff --git a/MySQLConnector/Connection.cs b/MySQLConnector/Connection.cs index d3985de..58c2684 100644 --- a/MySQLConnector/Connection.cs +++ b/MySQLConnector/Connection.cs @@ -57,6 +57,8 @@ namespace FLocal.MySQLConnector { string sValue; if(value is DateTime) { sValue = ((DateTime)value).Ticks.ToString(); + } else if(value is TimeSpan) { + sValue = ((TimeSpan)value).Ticks.ToString(); } else { sValue = value.ToString(); } diff --git a/templates/Full/PostPunish.xslt b/templates/Full/PostPunish.xslt index 524c5f1..d04a3e7 100644 --- a/templates/Full/PostPunish.xslt +++ b/templates/Full/PostPunish.xslt @@ -90,7 +90,8 @@ ( - ) + ), срок действия +
diff --git a/templates/Full/elems/Main.xslt b/templates/Full/elems/Main.xslt index b2ea4e3..8d03d2d 100644 --- a/templates/Full/elems/Main.xslt +++ b/templates/Full/elems/Main.xslt @@ -104,6 +104,27 @@ + + + + + дней + + + + часов + + + + минут + + + + секунд + + + + -1 diff --git a/templates/Lite/PostPunish.xslt b/templates/Lite/PostPunish.xslt index ba5a512..e6faf25 100644 --- a/templates/Lite/PostPunish.xslt +++ b/templates/Lite/PostPunish.xslt @@ -86,7 +86,8 @@ ( - ) + ), срок действия +
diff --git a/templates/Lite/elems/Main.xslt b/templates/Lite/elems/Main.xslt index 21eff77..f6af314 100644 --- a/templates/Lite/elems/Main.xslt +++ b/templates/Lite/elems/Main.xslt @@ -98,6 +98,27 @@ + + + + + дней + + + + часов + + + + минут + + + + секунд + + + + -1