public void CreatePostWithANewTopicTest() { // topic that doesn't exist TransitTopic t_topic1 = new TransitTopic(); t_topic1.Name = Guid.NewGuid().ToString(); // topic that exists TransitTopic t_topic2 = new TransitTopic(); t_topic2.Name = Guid.NewGuid().ToString(); t_topic2.Id = Blog.CreateOrUpdateTopic(Ticket, t_topic2); // post TransitPost t_post = new TransitPost(); t_post.Body = Guid.NewGuid().ToString(); t_post.Title = Guid.NewGuid().ToString(); List <TransitTopic> topics = new List <TransitTopic>(); topics.Add(t_topic1); topics.Add(t_topic2); t_post.Topics = topics.ToArray(); t_post.Publish = true; t_post.Id = Blog.CreateOrUpdatePost(Ticket, t_post); Assert.Greater(t_post.Id, 0); TransitPost t_post_retrieved = Blog.GetPostById(Ticket, t_post.Id); Assert.AreEqual(t_post_retrieved.Topics.Length, t_post.Topics.Length); Blog.DeletePost(Ticket, t_post.Id); t_topic1.Id = Blog.GetTopicByName(Ticket, t_topic1.Name).Id; Blog.DeleteTopic(Ticket, t_topic2.Id); }
public string GetCategories(TransitTopic[] topics) { StringBuilder sb = new StringBuilder(); foreach (TransitTopic topic in topics) { sb.AppendFormat("<category>{0}</category>", Renderer.Render(topic.Name)); } return sb.ToString(); }
public void TestGetTopicByName() { TransitTopic t_topic = new TransitTopic(); t_topic.Name = Guid.NewGuid().ToString(); t_topic.Type = Guid.NewGuid().ToString(); Assert.IsNull(Blog.GetTopicByName(Ticket, t_topic.Name)); t_topic.Id = Blog.CreateOrUpdateTopic(Ticket, t_topic); TransitTopic t_topic_2 = Blog.GetTopicByName(Ticket, t_topic.Name); Assert.IsNotNull(t_topic_2); Assert.AreEqual(t_topic.Name, t_topic_2.Name); Blog.DeleteTopic(Ticket, t_topic.Id); }
void grid_OnGetDataSource(object sender, EventArgs e) { List <TransitTopic> topics = SessionManager.GetCachedCollection <TransitTopic>( "GetTopics", SessionManager.Ticket, null); if (topics.Count > 0 && topics[0].Id != 0) { TransitTopic t_all = new TransitTopic(); t_all.Name = "all posts"; topics.Insert(0, t_all); } grid.DataSource = topics; }
public string GetRssTitle() { int topic_id = GetId("topicid"); string title = SessionManager.GetSetting("title", "Untitled"); if (topic_id > 0) { TransitTopic topic = SessionManager.GetCachedObject <TransitTopic>( "GetTopicById", SessionManager.Ticket, topic_id); title = string.Format("{0}: {1}", title, Renderer.Render(topic.Name)); } return(title); }
protected void Page_Load(object sender, EventArgs e) { try { if (Header != null) { Header.Controls.Add(HtmlMetaDescription); } DBlogMaster master = (DBlogMaster)this.Master; master.TopicChanged += new ViewTopicsControl.TopicChangedHandler(topics_TopicChanged); master.Search += new SearchControl.SearchHandler(search_Search); master.DateRangeChanged += new DateRangeControl.DateRangeHandler(master_DateRangeChanged); grid.OnGetDataSource += new EventHandler(grid_OnGetDataSource); if (!IsPostBack) { String topicName = Request.Params["t"]; if (!string.IsNullOrEmpty(topicName)) { TransitTopic topic = SessionManager.GetCachedObject <TransitTopic>("GetTopicByName", SessionManager.Ticket, topicName); if (topic == null) { throw new Exception("Invalid topic: " + topicName); } TopicId = topic.Id; } else { TopicId = RequestId; } Query = Request.Params["q"]; GetData(sender, e); } } catch (Exception ex) { ReportException(ex); } }
public void save_Click(object sender, EventArgs e) { try { Post.Title = CheckInput("Title", inputTitle.Text); List<TransitTopic> topics = new List<TransitTopic>(); foreach (ListItem topic in inputTopic.Items) { if (topic.Selected) { TransitTopic t_topic = new TransitTopic(); t_topic.Name = topic.Text; t_topic.Id = int.Parse(topic.Value); topics.Add(t_topic); } } Post.Topics = topics.ToArray(); Post.Body = inputBody.Content; Post.Publish = inputPublish.Checked; Post.Display = inputDisplay.Checked; Post.Sticky = inputSticky.Checked; Post.Export = inputExport.Checked; Post.Created = SessionManager.ToUTC(inputCreatedDate.SelectedDate.Add( inputCreatedTime.SelectedTime)); Post.Id = PostId = SessionManager.BlogService.CreateOrUpdatePost( SessionManager.Ticket, Post); if (!string.IsNullOrEmpty(inputServerPath.Text)) { string fullpath = Path.Combine( SessionManager.GetSetting("Images", string.Empty), inputServerPath.Text); ArrayList filenames = new ArrayList(); filenames.AddRange(Directory.GetFiles(fullpath, "*.jpg")); filenames.AddRange(Directory.GetFiles(fullpath, "*.gif")); List<TransitPostImage> deleted = SessionManager.GetCachedCollection<TransitPostImage>( "GetPostImages", SessionManager.Ticket, new TransitPostImageQueryOptions(Post.Id)); List<TransitPostImage> updated = new List<TransitPostImage>(); foreach (string filename in filenames) { TransitImage image = new TransitImage(); image.Name = Path.GetFileName(filename); image.Path = inputServerPath.Text; for (int i = 0; i < deleted.Count; i++) { if (deleted[i].Image.Name == image.Name) { image = deleted[i].Image; deleted.RemoveAt(i); break; } } ThumbnailBitmap bitmap = new ThumbnailBitmap(filename); image.Thumbnail = bitmap.Thumbnail; SessionManager.BlogService.CreateOrUpdatePostImage( SessionManager.Ticket, PostId, image); } foreach (TransitPostImage dimage in deleted) { SessionManager.BlogService.DeletePostImage( SessionManager.Ticket, dimage.Id); } SessionManager.Invalidate<TransitPostImage>(); images.Visible = true; GetDataImages(sender, e); } if (! string.IsNullOrEmpty(inputLogin.Text)) { loginAdd_Click(sender, e); } SessionManager.Invalidate<TransitPost>(); ReportInfo("Post Saved"); } catch (Exception ex) { ReportException(ex); } }
public void save_Click(object sender, EventArgs e) { try { Post.Title = CheckInput("Title", inputTitle.Text); List <TransitTopic> topics = new List <TransitTopic>(); foreach (ListItem topic in inputTopic.Items) { if (topic.Selected) { TransitTopic t_topic = new TransitTopic(); t_topic.Name = topic.Text; t_topic.Id = int.Parse(topic.Value); topics.Add(t_topic); } } Post.Topics = topics.ToArray(); Post.Body = inputBody.Content; Post.Publish = inputPublish.Checked; Post.Display = inputDisplay.Checked; Post.Sticky = inputSticky.Checked; Post.Export = inputExport.Checked; Post.Created = SessionManager.ToUTC(inputCreatedDate.SelectedDate.Add( inputCreatedTime.SelectedTime)); Post.Id = PostId = SessionManager.BlogService.CreateOrUpdatePost( SessionManager.Ticket, Post); if (!string.IsNullOrEmpty(inputServerPath.Text)) { string fullpath = Path.Combine( SessionManager.GetSetting("Images", string.Empty), inputServerPath.Text); ArrayList filenames = new ArrayList(); filenames.AddRange(Directory.GetFiles(fullpath, "*.jpg")); filenames.AddRange(Directory.GetFiles(fullpath, "*.gif")); List <TransitPostImage> deleted = SessionManager.GetCachedCollection <TransitPostImage>( "GetPostImages", SessionManager.Ticket, new TransitPostImageQueryOptions(Post.Id)); List <TransitPostImage> updated = new List <TransitPostImage>(); foreach (string filename in filenames) { TransitImage image = new TransitImage(); image.Name = Path.GetFileName(filename); image.Path = inputServerPath.Text; for (int i = 0; i < deleted.Count; i++) { if (deleted[i].Image.Name == image.Name) { image = deleted[i].Image; deleted.RemoveAt(i); break; } } ThumbnailBitmap bitmap = new ThumbnailBitmap(filename); image.Thumbnail = bitmap.Thumbnail; SessionManager.BlogService.CreateOrUpdatePostImage( SessionManager.Ticket, PostId, image); } foreach (TransitPostImage dimage in deleted) { SessionManager.BlogService.DeletePostImage( SessionManager.Ticket, dimage.Id); } SessionManager.Invalidate <TransitPostImage>(); images.Visible = true; GetDataImages(sender, e); } if (!string.IsNullOrEmpty(inputLogin.Text)) { loginAdd_Click(sender, e); } SessionManager.Invalidate <TransitPost>(); ReportInfo("Post Saved"); } catch (Exception ex) { ReportException(ex); } }
private void CreateOrUpdatePost(object sender, EventArgs e) { SessionManager.BasicAuth(); if (!SessionManager.IsAdministrator) { throw new ManagedLogin.AccessDeniedException(); } AtomEntry atomEntry = new AtomEntry(); atomEntry.Load(Request.InputStream); TransitPost post = (RequestId > 0) ? SessionManager.BlogService.GetPostById(SessionManager.Ticket, RequestId) : new TransitPost(); post.Title = atomEntry.Title.Content; List<TransitTopic> topics = new List<TransitTopic>(); foreach (AtomCategory category in atomEntry.Categories) { TransitTopic topic = SessionManager.BlogService.GetTopicByName(SessionManager.Ticket, category.Term); if (topic == null) { topic = new TransitTopic(); topic.Name = category.Term; } topics.Add(topic); } post.Topics = topics.ToArray(); post.Body = atomEntry.Content.Content; post.Publish = true; post.Display = true; post.Sticky = false; post.Export = false; if (atomEntry.PublishedOn != DateTime.MinValue) post.Created = atomEntry.PublishedOn; if (atomEntry.UpdatedOn != DateTime.MinValue) post.Modified = atomEntry.UpdatedOn; post.Id = SessionManager.BlogService.CreateOrUpdatePost(SessionManager.Ticket, post); Response.ContentType = "application/atom+xml;type=entry;charset=\"utf-8\""; Response.StatusCode = 201; Response.StatusDescription = "Created"; string location = string.Format("{0}AtomPost.aspx?id={1}", SessionManager.WebsiteUrl, post.Id); Response.Headers.Add("Location", location); Response.Headers.Add("Content-Location", location); Response.Headers.Add("ETag", string.Format("\"{0}\"", Guid.NewGuid().ToString())); atomEntry.Id = new AtomId(new Uri(string.Format("{0}Post/{1}", SessionManager.WebsiteUrl, post.Id))); atomEntry.Links.Add(new AtomLink(new Uri(string.Format("{0}AtomPost.aspx?id={1}", SessionManager.WebsiteUrl, post.Id)))); atomEntry.Links.Add(new AtomLink(new Uri(string.Format("{0}AtomPost.aspx?id={1}", SessionManager.WebsiteUrl, post.Id)), "edit")); AtomLink atomEntryUri = new AtomLink(new Uri(string.Format("{0}{1}", SessionManager.WebsiteUrl, post.LinkUri)), "alternate"); atomEntryUri.ContentType = "text/html"; atomEntry.Links.Add(atomEntryUri); atomEntry.Save(Response.OutputStream); Response.End(); }
public string GetTopics(TransitTopic[] topics) { StringBuilder sb = new StringBuilder(); foreach (TransitTopic topic in topics) { if (sb.Length != 0) sb.Append(", "); sb.Append(Renderer.Render(topic.Name)); } return sb.ToString(); }
public BlogTopicTest() { mTopic = new TransitTopic(); mTopic.Name = Guid.NewGuid().ToString(); mTopic.Type = Guid.NewGuid().ToString(); }
public TransitPostTopic(ISession session, DBlog.Data.PostTopic o) : base(o.Id) { Post = new TransitPost(session, o.Post, false); Topic = new TransitTopic(o.Topic); }
void grid_OnGetDataSource(object sender, EventArgs e) { List<TransitTopic> topics = SessionManager.GetCachedCollection<TransitTopic>( "GetTopics", SessionManager.Ticket, null); if (topics.Count > 0 && topics[0].Id != 0) { TransitTopic t_all = new TransitTopic(); t_all.Name = "all posts"; topics.Insert(0, t_all); } grid.DataSource = topics; }
private void CreateOrUpdatePost(object sender, EventArgs e) { SessionManager.BasicAuth(); if (!SessionManager.IsAdministrator) { throw new ManagedLogin.AccessDeniedException(); } AtomEntry atomEntry = new AtomEntry(); atomEntry.Load(Request.InputStream); TransitPost post = (RequestId > 0) ? SessionManager.BlogService.GetPostById(SessionManager.Ticket, RequestId) : new TransitPost(); post.Title = atomEntry.Title.Content; List <TransitTopic> topics = new List <TransitTopic>(); foreach (AtomCategory category in atomEntry.Categories) { TransitTopic topic = SessionManager.BlogService.GetTopicByName(SessionManager.Ticket, category.Term); if (topic == null) { topic = new TransitTopic(); topic.Name = category.Term; } topics.Add(topic); } post.Topics = topics.ToArray(); post.Body = atomEntry.Content.Content; post.Publish = true; post.Display = true; post.Sticky = false; post.Export = false; if (atomEntry.PublishedOn != DateTime.MinValue) { post.Created = atomEntry.PublishedOn; } if (atomEntry.UpdatedOn != DateTime.MinValue) { post.Modified = atomEntry.UpdatedOn; } post.Id = SessionManager.BlogService.CreateOrUpdatePost(SessionManager.Ticket, post); Response.ContentType = "application/atom+xml;type=entry;charset=\"utf-8\""; Response.StatusCode = 201; Response.StatusDescription = "Created"; string location = string.Format("{0}AtomPost.aspx?id={1}", SessionManager.WebsiteUrl, post.Id); Response.Headers.Add("Location", location); Response.Headers.Add("Content-Location", location); Response.Headers.Add("ETag", string.Format("\"{0}\"", Guid.NewGuid().ToString())); atomEntry.Id = new AtomId(new Uri(string.Format("{0}Post/{1}", SessionManager.WebsiteUrl, post.Id))); atomEntry.Links.Add(new AtomLink(new Uri(string.Format("{0}AtomPost.aspx?id={1}", SessionManager.WebsiteUrl, post.Id)))); atomEntry.Links.Add(new AtomLink(new Uri(string.Format("{0}AtomPost.aspx?id={1}", SessionManager.WebsiteUrl, post.Id)), "edit")); AtomLink atomEntryUri = new AtomLink(new Uri(string.Format("{0}{1}", SessionManager.WebsiteUrl, post.LinkUri)), "alternate"); atomEntryUri.ContentType = "text/html"; atomEntry.Links.Add(atomEntryUri); atomEntry.Save(Response.OutputStream); Response.End(); }
public int CreateOrUpdateTopic(string ticket, TransitTopic t_topic) { using (DBlog.Data.Hibernate.Session.OpenConnection(GetNewConnection())) { ISession session = DBlog.Data.Hibernate.Session.Current; CheckAdministrator(session, ticket); Topic topic = t_topic.GetTopic(session); session.SaveOrUpdate(topic); session.Flush(); return topic.Id; } }