diff --git a/DatabaseDumpReader/DumpReader.cs b/DatabaseDumpReader/DumpReader.cs index 62d903f..b60c24f 100644 --- a/DatabaseDumpReader/DumpReader.cs +++ b/DatabaseDumpReader/DumpReader.cs @@ -204,7 +204,9 @@ private void ResolveUserVnForVn(ListedVN vn, SQLiteTransaction transaction) ULNote = dumpUserVn.Notes, Added = dumpUserVn.Added, LastModified = dumpUserVn.LastModified, - Labels = labels + Labels = labels, + Started = dumpUserVn.Started, + Finished = dumpUserVn.Finished }; if (Votes.ContainsKey(vn.VNID)) { diff --git a/DatabaseDumpReader/UserVn.cs b/DatabaseDumpReader/UserVn.cs index 3a3d2eb..ad723c1 100644 --- a/DatabaseDumpReader/UserVn.cs +++ b/DatabaseDumpReader/UserVn.cs @@ -9,6 +9,8 @@ public class UserVn : DumpItem public int VnId { get; set; } public DateTime Added { get; set; } public DateTime LastModified { get; set; } + public DateTime? Started { get; set; } + public DateTime? Finished { get; set; } public string Notes { get; set; } public string LabelsString { get; set; } @@ -19,6 +21,8 @@ public override void LoadFromStringParts(string[] parts) Added = Convert.ToDateTime(GetPart(parts, "added")); // ReSharper disable once StringLiteralTypo LastModified = Convert.ToDateTime(GetPart(parts, "lastmod")); + Started = GetNullableDateTime(parts, "started"); + Finished = GetNullableDateTime(parts, "finished"); Notes = GetPartOrNull(parts, "notes"); LabelsString = GetPart(parts, "labels"); } diff --git a/HappySearchObjectClasses/Database/DatabaseTableBuilder.cs b/HappySearchObjectClasses/Database/DatabaseTableBuilder.cs index 236fe05..aba724d 100644 --- a/HappySearchObjectClasses/Database/DatabaseTableBuilder.cs +++ b/HappySearchObjectClasses/Database/DatabaseTableBuilder.cs @@ -35,6 +35,8 @@ PRIMARY KEY(`Id`) ""Added"" DATETIME, ""Labels"" TEXT, ""LastModified"" DATETIME, + ""Started"" DATETIME, + ""Finished"" DATETIME, PRIMARY KEY(""UserID"",""VNID"") )"); diff --git a/HappySearchObjectClasses/Database/DumpItem.cs b/HappySearchObjectClasses/Database/DumpItem.cs index 38d3a9d..a8dcd26 100644 --- a/HappySearchObjectClasses/Database/DumpItem.cs +++ b/HappySearchObjectClasses/Database/DumpItem.cs @@ -30,6 +30,12 @@ protected string GetPartOrNull(string[] parts, string columnName) protected int GetInteger(string[] parts, string columnName, int skipCharacters = 0) => Convert.ToInt32(parts[Headers[columnName]].Substring(skipCharacters)); + protected DateTime? GetNullableDateTime(string[] parts, string columnName) + { + var part = GetPart(parts, columnName); + return part == NullValue ? null : Convert.ToDateTime(part); + } + /// /// If data is null, returns zero. /// diff --git a/HappySearchObjectClasses/Database/Updates/Update5.sql b/HappySearchObjectClasses/Database/Updates/Update5.sql new file mode 100644 index 0000000..a3b675d --- /dev/null +++ b/HappySearchObjectClasses/Database/Updates/Update5.sql @@ -0,0 +1,6 @@ +ALTER TABLE UserVNs +ADD COLUMN Started DATETIME DEFAULT NULL; +ALTER TABLE UserVNs +ADD COLUMN Finished DATETIME DEFAULT NULL; + +INSERT OR REPLACE INTO TableDetails (Key,Value) VALUES ('updates',5); \ No newline at end of file diff --git a/HappySearchObjectClasses/Database/UserVN.cs b/HappySearchObjectClasses/Database/UserVN.cs index c967891..14e4b8f 100644 --- a/HappySearchObjectClasses/Database/UserVN.cs +++ b/HappySearchObjectClasses/Database/UserVN.cs @@ -30,8 +30,12 @@ public sealed class UserVN : IDataItem<(int, int)> public DateTime? VoteAdded { get; set; } public HashSet Labels { get; set; } - - [NotMapped] + + public DateTime? Started { get; set; } + + public DateTime? Finished { get; set; } + + [NotMapped] public LabelKind PriorityLabel => Labels.FirstOrDefault(i => !_labelsToExcludeFromPriority.Contains(i)); public enum LabelKind @@ -60,8 +64,8 @@ public enum LabelKind DbCommand IDataItem<(int, int)>.UpsertCommand(DbConnection connection, bool insertOnly) { - string sql = $"INSERT {(insertOnly ? string.Empty : "OR REPLACE ")}INTO UserVNs (VNID,UserId,ULNote,Vote,VoteAdded, Added, Labels, LastModified) " + - "VALUES (@vnid,@userid,@ulnote,@vote,@voteadded, @added, @labels, @LastModified)"; + string sql = $"INSERT {(insertOnly ? string.Empty : "OR REPLACE ")}INTO UserVNs (VNID,UserId,ULNote,Vote,VoteAdded, Added, Labels, LastModified, Started, Finished) " + + "VALUES (@vnid,@userid,@ulnote,@vote,@voteadded, @added, @labels, @LastModified, @Started, @Finished)"; var command = connection.CreateCommand(); command.CommandText = sql; command.AddParameter("@vnid", VNID); @@ -72,7 +76,9 @@ public enum LabelKind command.AddParameter("@added", Added); command.AddParameter("@LastModified", LastModified); command.AddParameter("@labels", string.Join(",", Labels.Cast())); - return command; + command.AddParameter("@Started", Started); + command.AddParameter("@Finished", Finished); + return command; } void IDataItem<(int, int)>.LoadFromReader(System.Data.IDataRecord reader) @@ -88,7 +94,9 @@ public enum LabelKind Added = StaticHelpers.GetNullableDate(reader["Added"]); LastModified = StaticHelpers.GetNullableDate(reader["LastModified"]); Labels = Convert.ToString(reader["Labels"]).Split(',').Select(i => (LabelKind)int.Parse(i)).ToHashSet(); - } + Started = StaticHelpers.GetNullableDate(reader["Started"]); + Finished = StaticHelpers.GetNullableDate(reader["Finished"]); + } catch (Exception ex) { StaticHelpers.Logger.ToFile(ex); diff --git a/HappySearchObjectClasses/Happy_Apps_Core.csproj b/HappySearchObjectClasses/Happy_Apps_Core.csproj index 88314a0..8e130fb 100644 --- a/HappySearchObjectClasses/Happy_Apps_Core.csproj +++ b/HappySearchObjectClasses/Happy_Apps_Core.csproj @@ -204,6 +204,7 @@ + PreserveNewest