/// <summary> /// The update log. /// </summary> /// <param name="comment"> /// The comment. /// </param> public void UpdateLog(Comment comment) { if (!this.RecaptchaLoggingEnabled || this.skipRecaptcha) { return; } var log = RecaptchaLogger.ReadLogItems(); var logItem = new RecaptchaLogItem { Response = this.RecaptchaResponseValue, CommentId = comment.Id, Enabled = this.RecaptchaEnabled, Necessary = this.RecaptchaNecessary, NumberOfAttempts = this.RecaptchaAttempts, TimeToComment = DateTime.Now.Subtract(this.PageLoadTime).TotalSeconds, TimeToSolveCapcha = DateTime.Now.Subtract(this.RecaptchaRenderTime).TotalSeconds }; log.Add(logItem); if (log.Count > this.MaxLogEntries) { log.RemoveRange(0, log.Count - this.MaxLogEntries); } RecaptchaLogger.SaveLogItems(log); this.RecaptchaAttempts = 0; this.PageLoadTime = DateTime.Now; Blog.CurrentInstance.Cache.Remove($"{UserUniqueIdentifier}RecaptchaChallengeValue"); Blog.CurrentInstance.Cache.Remove($"{UserUniqueIdentifier}RecaptchaResponseValue"); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { var log = RecaptchaLogger.ReadLogItems(); var comments = Post.Posts.SelectMany(post => post.Comments).ToDictionary(comment => comment.Id); var logView = new DataTable("LogView"); logView.Columns.Add("Email"); logView.Columns.Add("Date", typeof(DateTime)); logView.Columns.Add("Author"); logView.Columns.Add("Website"); logView.Columns.Add("IP"); logView.Columns.Add("RecaptchaAttempts", typeof(ushort)); logView.Columns.Add("CommentTime", typeof(double)); logView.Columns.Add("RecaptchaTime", typeof(double)); var orphanedRecords = new List <RecaptchaLogItem>(); foreach (var item in log) { if (comments.ContainsKey(item.CommentId)) { var comment = comments[item.CommentId]; logView.Rows.Add( comment.Email, comment.DateCreated, comment.Author, comment.Website, comment.IP, item.NumberOfAttempts, item.TimeToComment, item.TimeToSolveCapcha); } else { orphanedRecords.Add(item); } } if (orphanedRecords.Count > 0) { foreach (var orphan in orphanedRecords) { log.Remove(orphan); } RecaptchaLogger.SaveLogItems(log); } using (var view = new DataView(logView)) { view.Sort = "Date DESC"; this.RecaptchaLog.DataSource = view; this.RecaptchaLog.DataBind(); } }