public void Rebuild() { // get the lock fileLock.AcquireWriterLock(100); try { XmlSerializer x = new XmlSerializer(typeof(DayExtra)); CommentCollection rebuiltCollection = new CommentCollection(); DirectoryInfo di = new DirectoryInfo(this.contentBaseDirectory); foreach (FileInfo file in di.GetFiles("*dayfeedback.xml")) { using(FileStream fs = file.OpenRead()) { DayExtra de = (DayExtra)x.Deserialize(fs); rebuiltCollection.AddRange(de.Comments); } } _commentCache = rebuiltCollection; } catch(Exception e) { // report error ErrorTrace.Trace(TraceLevel.Error,e); } finally { // release the lock fileLock.ReleaseWriterLock(); } }
private void BuildPage() { if (Request.QueryString["id"] == null) { //CommentCollection cc = new CommentCollection(); Query q = Comment.CreateQuery(); if (!(Request.QueryString["a"] == "d")) { q.AndWhere(Comment.Columns.IsPublished, !(Request.QueryString["a"] == "f")); } q.AndWhere(Comment.Columns.IsDeleted, (Request.QueryString["a"] == "d")); if (!String.IsNullOrEmpty(Request.QueryString["pid"])) { q.AndWhere(Comment.Columns.PostId, Request.QueryString["pid"]); } q.OrderByDesc(Comment.Columns.Id); CommentCollection tempCC = CommentCollection.FetchByQuery(q); CommentCollection permissionsFilteredCount = new CommentCollection(); permissionsFilteredCount.AddRange(tempCC); foreach (Comment c in tempCC) { if (!RolePermissionManager.GetPermissions(c.Post.CategoryId, GraffitiUsers.Current).Read) { permissionsFilteredCount.Remove(c); } } q.PageIndex = Int32.Parse(Request.QueryString["p"] ?? "1"); q.PageSize = 25; CommentCollection cc = CommentCollection.FetchByQuery(q); CommentCollection permissionsFiltered = new CommentCollection(); permissionsFiltered.AddRange(cc); foreach (Comment c in cc) { if (!RolePermissionManager.GetPermissions(c.Post.CategoryId, GraffitiUsers.Current).Read) { permissionsFiltered.Remove(c); } } CommentList.DataSource = permissionsFiltered; CommentList.DataBind(); string qs = Request.QueryString["a"] != null ? "?a=" + Request.QueryString["a"] : "?a=t"; Pager.Text = Util.Pager(q.PageIndex, q.PageSize, permissionsFilteredCount.Count, "navigation", qs); if (Request.QueryString["a"] == "f") { CommentLinks.SetActiveView(PendingComments); } else if (Request.QueryString["a"] == "d") { CommentLinks.SetActiveView(DeletedComments); } } else { the_Views.SetActiveView(Comment_Form); Comment comment = new Comment(Request.QueryString["id"]); if (comment.IsNew) { throw new Exception("Invalid Comment Id"); } txtName.Text = Server.HtmlDecode(comment.Name); txtSite.Text = comment.WebSite; txtEmail.Text = comment.Email; CommentEditor.Text = comment.Body; } #region build the page title StringBuilder sb = new StringBuilder(); string page = Request.QueryString["a"] ?? "t"; switch (page) { case "t": sb.Append("Published "); break; case "f": sb.Append("Pending "); break; case "d": sb.Append("Deleted "); break; } sb.Append(" Comments"); lblPageTitle.Text = sb.ToString(); string post = Request.QueryString["pid"]; if (!String.IsNullOrEmpty(post)) { Post p = new Post(Convert.ToInt32(post)); lblPageTitle.Text += " for \"" + p.Name + "\""; } #endregion }
private void BuildPage() { if (Request.QueryString["id"] == null) { //CommentCollection cc = new CommentCollection(); Query q = Comment.CreateQuery(); if (!(Request.QueryString["a"] == "d")) q.AndWhere(Comment.Columns.IsPublished, !(Request.QueryString["a"] == "f")); q.AndWhere(Comment.Columns.IsDeleted, (Request.QueryString["a"] == "d")); if (!String.IsNullOrEmpty(Request.QueryString["pid"])) { q.AndWhere(Comment.Columns.PostId, Request.QueryString["pid"]); } q.OrderByDesc(Comment.Columns.Id); CommentCollection tempCC = CommentCollection.FetchByQuery(q); CommentCollection permissionsFilteredCount = new CommentCollection(); permissionsFilteredCount.AddRange(tempCC); foreach (Comment c in tempCC) { if (!RolePermissionManager.GetPermissions(c.Post.CategoryId, GraffitiUsers.Current).Read) permissionsFilteredCount.Remove(c); } q.PageIndex = Int32.Parse(Request.QueryString["p"] ?? "1"); q.PageSize = 25; CommentCollection cc = CommentCollection.FetchByQuery(q); CommentCollection permissionsFiltered = new CommentCollection(); permissionsFiltered.AddRange(cc); foreach (Comment c in cc) { if (!RolePermissionManager.GetPermissions(c.Post.CategoryId, GraffitiUsers.Current).Read) permissionsFiltered.Remove(c); } CommentList.DataSource = permissionsFiltered; CommentList.DataBind(); string qs = Request.QueryString["a"] != null ? "?a=" + Request.QueryString["a"] : "?a=t"; Pager.Text = Util.Pager(q.PageIndex, q.PageSize, permissionsFilteredCount.Count, "navigation", qs); if (Request.QueryString["a"] == "f") CommentLinks.SetActiveView(PendingComments); else if (Request.QueryString["a"] == "d") CommentLinks.SetActiveView(DeletedComments); } else { the_Views.SetActiveView(Comment_Form); Comment comment = new Comment(Request.QueryString["id"]); if (comment.IsNew) throw new Exception("Invalid Comment Id"); txtName.Text = Server.HtmlDecode(comment.Name); txtSite.Text = comment.WebSite; txtEmail.Text = comment.Email; CommentEditor.Text = comment.Body; } #region build the page title StringBuilder sb = new StringBuilder(); string page = Request.QueryString["a"] ?? "t"; switch (page) { case "t": sb.Append("Published "); break; case "f": sb.Append("Pending "); break; case "d": sb.Append("Deleted "); break; } sb.Append(" Comments"); lblPageTitle.Text = sb.ToString(); string post = Request.QueryString["pid"]; if (!String.IsNullOrEmpty(post)) { Post p = new Post(Convert.ToInt32(post)); lblPageTitle.Text += " for \"" + p.Name + "\""; } #endregion }