public History UpdateHistory(History history) { using (SQLiteConnection conn = new SQLiteConnection(UrlBuilder.ToString())) { conn.Open(); if (history == null) throw new NoNullAllowedException("History cannot be null"); StringBuilder sb = new StringBuilder(); sb.Append(Update); sb.Append(HistoryTable); sb.Append(Set); sb.Append("WebId=@webId, ComputerId=@computerId, Title=@title, Url=@url, VisitCount=@visitcount, UpdatedAt=@updatedAt"); sb.Append(Where); sb.Append("Id= " + history.Id); sb.Append(End); var command = new SQLiteCommand(sb.ToString(), conn); command.Parameters.Add(new SQLiteParameter("@webId", history.WebId)); command.Parameters.Add(new SQLiteParameter("@computerId", history.ComputerId)); command.Parameters.Add(new SQLiteParameter("@title", history.Title)); command.Parameters.Add(new SQLiteParameter("@url", history.Url)); command.Parameters.Add(new SQLiteParameter("@visitcount", history.VisitCount)); command.Parameters.Add(new SQLiteParameter("@updatedAt", DateTime.Now)); Console.WriteLine(sb.ToString()); command.ExecuteNonQuery(); } return GetHistoryById(history.Id); }
private History ParseHistory(STATURL url) { var history = new History(); history.Title = url.Title; var match = Regex.Match(url.URL, @"(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?"); if (match.Captures.Count >= 1) { history.Url = match.Captures[0].ToString(); history.CreatedAt = DateTime.Now; history.UpdatedAt = DateTime.Now; return history; } else { return null; } }
public History SaveHistory(History history) { using (SQLiteConnection conn = new SQLiteConnection(UrlBuilder.ToString())) { conn.Open(); if (history == null) throw new NoNullAllowedException("History Object can't be null"); StringBuilder sb = new StringBuilder(); Console.WriteLine("Saving History"); sb.Append(InsertInto); sb.Append(HistoryTable); sb.Append("(ComputerId, Title, Url, VisitCount, CreatedAt, UpdatedAt)"); sb.Append(Values); sb.Append("(@computerid, @title, @url, @visitcount, @createdAt, @updatedAt)"); sb.Append(End); var command = new SQLiteCommand(sb.ToString(), conn); command.Parameters.Add(new SQLiteParameter("@computerid", history.ComputerId)); command.Parameters.Add(new SQLiteParameter("@title", history.Title)); command.Parameters.Add(new SQLiteParameter("@url", history.Url)); command.Parameters.Add(new SQLiteParameter("@visitcount", history.VisitCount)); command.Parameters.Add(new SQLiteParameter("@createdAt", DateTime.Now)); command.Parameters.Add(new SQLiteParameter("@updatedAt", DateTime.Now)); Console.WriteLine(sb.ToString()); command.ExecuteNonQuery(); } Console.WriteLine("Done writing history"); var savedHistory = GetHistories().First(h => h.ComputerId == history.ComputerId && h.Url == history.Url); return savedHistory; }