public async Task GetTagsNoCacheTest() { //Arrange var mockCache = new Mock <ICacheAccessor>(); var mockDb = new Mock <IBlogAccessor>(); mockDb.Setup(m => m.GetTagList()) .ReturnsAsync(() => new[] { new MetaTag { Count = 3, Tag = TestConstants.GuidString }, new MetaTag { Count = 1, Tag = TestConstants.GuidString }, new MetaTag { Count = 2, Tag = TestConstants.GuidString } }); var engine = new BlogEngine(mockDb.Object, mockCache.Object); //Act var results = await engine.GetTagList(); //Assert Assert.IsNotNull(results, "Should never be null"); Assert.IsInstanceOfType(results, typeof(IEnumerable <MetaTag>)); Assert.AreEqual(3, results.Count(), "Should be three tags"); mockCache.Verify(m => m.CacheEnt <IEnumerable <MetaTag> >(It.IsAny <string>(), It.IsAny <IEnumerable <MetaTag> >(), It.IsAny <TimeSpan?>()), Times.Once, "Should be called once to cache results"); }
/// <summary> /// Deletes custom field /// </summary> /// <param name="field">Object field</param> public override void DeleteCustomField(BlogEngine.Core.Data.Models.CustomField field) { var fileName = Path.Combine(this.Folder, _customFieldsFile); var xmlDoc = new XmlDocument(); xmlDoc.Load(fileName); var items = xmlDoc.SelectNodes("CustomFields/item"); if (items != null && items.Count > 0) { for (int i = 0; i < items.Count; i++) { if (items[i].Attributes != null && items[i].Attributes["customtype"] != null && items[i].Attributes["blogid"] != null && items[i].Attributes["objectid"] != null && items[i].Attributes["key"] != null) { if (field.CustomType == items[i].Attributes["customtype"].InnerText && field.BlogId.ToString() == items[i].Attributes["blogid"].InnerText && field.ObjectId == items[i].Attributes["objectid"].InnerText && field.Key == items[i].Attributes["key"].InnerText) { if (items[i].ParentNode != null) items[i].ParentNode.RemoveChild(items[i]); } } } } xmlDoc.Save(fileName); }
public override void SaveToDataStore(BlogEngine.Core.DataStore.ExtensionType exType, string exId, object settings) { XmlSerializer xs = new XmlSerializer(settings.GetType()); string objectXML = string.Empty; using (StringWriter sw = new StringWriter()) { xs.Serialize(sw, settings); objectXML = sw.ToString(); } using (var mongo = new MongoDbWr()) { var coll = mongo.BlogDB.GetCollection("DataStoreSettings"); Document spec = new Document(); spec["ExtensionType"] = exType; spec["ExtensionId"] = exId; var res = new Document(); res["Settings"] = objectXML; res["ExtensionType"] = exType; res["ExtensionId"] = exId; coll.Update(res, spec, UpdateFlags.Upsert); } }
public override void InsertPage(BlogEngine.Core.Page page) { using (var mongo = new MongoDbWr()) { var coll = mongo.BlogDB.GetCollection(COLLECTION_PAGES); var record = PageToDocument(page); coll.Insert(record); } }
public override void RemoveFromDataStore(BlogEngine.Core.DataStore.ExtensionType exType, string exId) { using (var mongo = new MongoDbWr()) { var coll = mongo.BlogDB.GetCollection("DataStoreSettings"); Document spec = new Document(); spec["ExtensionType"] = exType; spec["ExtensionId"] = exId; coll.Delete(spec); } }
public override object LoadFromDataStore(BlogEngine.Core.DataStore.ExtensionType exType, string exId) { using (var mongo = new MongoDbWr()) { var coll = mongo.BlogDB.GetCollection("DataStoreSettings"); Document spec = new Document(); spec["ExtensionType"] = exType; spec["ExtensionId"] = exId; var res = coll.FindOne(spec); if (res == null) return null; return res["Settings"]; } }
/// <summary> /// Saves custom field /// </summary> /// <param name="field">Object custom field</param> public override void SaveCustomField(BlogEngine.Core.Data.Models.CustomField field) { var fileName = Path.Combine(this.Folder, _customFieldsFile); var x = FillCustomFields(); var items = FillCustomFields() ?? new List<BlogEngine.Core.Data.Models.CustomField>(); int idx = -1; for (int index = 0; index < items.Count; index++) { var n = items[index]; if (n.CustomType == field.CustomType && n.BlogId == field.BlogId && field.ObjectId == n.ObjectId && n.Key == field.Key) { idx = index; break; } } if (idx >= 0) items.RemoveAt(idx); items.Add(field); using (var writer = new XmlTextWriter(fileName, Encoding.UTF8)) { writer.Formatting = Formatting.Indented; writer.Indentation = 4; writer.WriteStartDocument(true); writer.WriteStartElement("CustomFields"); foreach (var n in items) { writer.WriteStartElement("item"); writer.WriteAttributeString("customtype", n.CustomType); writer.WriteAttributeString("objectid", n.ObjectId); writer.WriteAttributeString("blogid", Blog.CurrentInstance.Id.ToString()); writer.WriteAttributeString("key", n.Key); writer.WriteAttributeString("value", n.Value); writer.WriteAttributeString("attribute", n.Attribute); writer.WriteEndElement(); } writer.WriteEndElement(); } }
public async Task GetHeadersPageNullDataTest() { //Arrange var mockCache = new Mock <ICacheAccessor>(); var mockDb = new Mock <IBlogAccessor>(); mockDb.Setup(m => m.GetPostHeadersByPage(It.IsAny <int>(), It.IsAny <int>())) .ReturnsAsync(() => null); var engine = new BlogEngine(mockDb.Object, mockCache.Object); //Act var results = await engine.GetPageOfHeaders(0, 2); //Assert Assert.IsNull(results, "Should be null"); mockCache.Verify(m => m.CacheEnt(It.IsAny <string>(), It.IsAny <IEnumerable <PostHeader> >(), It.IsAny <TimeSpan?>()), Times.Never, "Should be skipped because of null"); }
/// <summary> /// Adds a blog to the item collection and start retrieving the blogs. /// </summary> private static void AddBlog(BlogEngine.Core.BlogRollItem br) { blogRequest affected = null; foreach (blogRequest req in _Items) { if (req.RollItem.Equals(br)) { affected = req; break; } } if (affected == null) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(br.FeedUrl); req.Credentials = CredentialCache.DefaultNetworkCredentials; blogRequest bReq = new blogRequest(br, req); _Items.Add(bReq); req.BeginGetResponse(ProcessRespose, bReq); } }
public async Task GetHeadersPageTaggedNoDataTest() { //Arrange var mockCache = new Mock <ICacheAccessor>(); var mockDb = new Mock <IBlogAccessor>(); mockDb.Setup(m => m.GetPostHeaderPageByTag(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())) .ReturnsAsync(() => new PostHeader[0]); var engine = new BlogEngine(mockDb.Object, mockCache.Object); //Act var results = await engine.GetPageOfHeadersByTag(0, 2, TestConstants.GuidString); //Assert Assert.IsNotNull(results, "Should never be null"); Assert.IsInstanceOfType(results, typeof(IEnumerable <PostHeader>)); Assert.IsFalse(results.Any(), "Should be no headers on this page"); mockCache.Verify(m => m.CacheEnt(It.IsAny <string>(), It.IsAny <IEnumerable <PostHeader> >(), It.IsAny <TimeSpan?>()), Times.Never, "Should be skipped because of null"); }
public async Task GetTagsNoDataTest() { //Arrange var mockCache = new Mock <ICacheAccessor>(); var mockDb = new Mock <IBlogAccessor>(); mockDb.Setup(m => m.GetTagList()) .ReturnsAsync(() => new MetaTag[0]); var engine = new BlogEngine(mockDb.Object, mockCache.Object); //Act var results = await engine.GetTagList(); //Assert Assert.IsNotNull(results, "Should never be null"); Assert.IsInstanceOfType(results, typeof(IEnumerable <MetaTag>)); Assert.IsFalse(results.Any(), "Should be no tags"); mockCache.Verify(m => m.CacheEnt(It.IsAny <string>(), It.IsAny <IEnumerable <MetaTag> >(), It.IsAny <TimeSpan?>()), Times.Never, "Should be skipped because of null"); }
private HtmlGenericControl BuildChildPageList(BlogEngine.Core.Page page) { HtmlGenericControl ul = new HtmlGenericControl("ul"); foreach (Page cPage in BlogEngine.Core.Page.Pages.FindAll(delegate(BlogEngine.Core.Page p) { //p => (p.Parent == page.Id))) return p.Parent == page.Id; })) { HtmlGenericControl cLi = new HtmlGenericControl("li"); cLi.Attributes.CssStyle.Add("font-weight", "normal"); HtmlAnchor cA = new HtmlAnchor(); cA.HRef = "?id=" + cPage.Id.ToString(); cA.InnerHtml = cPage.Title; System.Web.UI.LiteralControl cText = new System.Web.UI.LiteralControl (" (" + cPage.DateCreated.ToString("yyyy-dd-MM HH:mm") + ")"); cLi.Controls.Add(cA); cLi.Controls.Add(cText); if (cPage.HasChildPages) { cLi.Attributes.CssStyle.Remove("font-weight"); cLi.Attributes.CssStyle.Add("font-weight", "bold"); cLi.Controls.Add(BuildChildPageList(cPage)); } ul.Controls.Add(cLi); } return ul; }
/// <summary> /// Resets the parent page. /// </summary> /// <param name="page">The page to reset.</param> private void ResetParentPage(BlogEngine.Core.Page page) { foreach (var child in BlogEngine.Core.Page.Pages.Where(child => page.Id == child.Parent)) { child.Parent = Guid.Empty; child.Save(); this.ResetParentPage(child); } }
/// <summary> /// Builds the child page list. /// </summary> /// <param name="page">The page to make a child list for.</param> /// <returns>The page list.</returns> private HtmlGenericControl BuildChildPageList(BlogEngine.Core.Page page) { var ul = new HtmlGenericControl("ul"); foreach (var childPage in BlogEngine.Core.Page.Pages.FindAll(p => p.Parent == page.Id)) { var cLi = new HtmlGenericControl("li"); cLi.Attributes.CssStyle.Add("font-weight", "normal"); var cA = new HtmlAnchor { HRef = string.Format("?id={0}", childPage.Id), InnerHtml = childPage.Title }; var childText = new LiteralControl(string.Format(" ({0}) ", childPage.DateCreated.ToString("yyyy-dd-MM HH:mm"))); const string DeleteText = "Are you sure you want to delete the page?"; var delete = new HtmlAnchor { InnerText = labels.delete }; delete.Attributes["onclick"] = string.Format("if (confirm('{0}')){{location.href='?delete={1}'}}", DeleteText, childPage.Id); delete.HRef = "javascript:void(0);"; delete.Style.Add(HtmlTextWriterStyle.FontWeight, "normal"); cLi.Controls.Add(cA); cLi.Controls.Add(childText); cLi.Controls.Add(delete); if (childPage.HasChildPages) { cLi.Attributes.CssStyle.Remove("font-weight"); cLi.Attributes.CssStyle.Add("font-weight", "bold"); cLi.Controls.Add(this.BuildChildPageList(childPage)); } ul.Controls.Add(cLi); } return ul; }
/// <summary> /// Deletes custom field /// </summary> /// <param name="field">Object field</param> public abstract void DeleteCustomField(BlogEngine.Core.Data.Models.CustomField field);
/// <summary> /// Deletes custom field /// </summary> /// <param name="field">Object field</param> public static void DeleteCustomField(BlogEngine.Core.Data.Models.CustomField field) { Provider.DeleteCustomField(field); }
public void WhosYourDaddy() { BlogEngine = CozyPressAdapter.CreateBlogEngine(); BlogEngine.Init(); OperateBlog = BlogEngine.Blog(); }
private Comment GetCoreFromJson(BlogEngine.Core.Data.Models.CommentItem c) { Comment item = (from p in Post.Posts from cmn in p.AllComments where cmn.Id == c.Id select cmn).FirstOrDefault(); if (c.IsPending) { item.IsApproved = false; item.IsSpam = false; } if (c.IsApproved) { item.IsApproved = true; item.IsSpam = false; } if (c.IsSpam) { item.IsApproved = false; item.IsSpam = true; } item.Email = c.Email; item.Author = c.Author; item.Website = string.IsNullOrEmpty(c.Website) ? null : new Uri(c.Website); item.IP = c.Ip; return item; }
public FoafPerson(string id, BlogEngine.Core.AuthorProfile ap) { ID = "#me"; Name = ap.FullName; Email = ap.EmailAddress; // no homepage // this website = blog Blog = Utils.AbsoluteWebRoot.ToString(); Rdf = Utils.AbsoluteWebRoot.ToString() + "foaf_" + ap.UserName + ".axd"; Firstname = ap.FirstName; Lastname = ap.LastName; Image = ap.PhotoURL; Birthday = ap.Birthday.ToString("yyyy-MM-dd"); Phone = ap.PhoneMain; PhotoUrl = ap.PhotoURL; }
internal blogRequest(BlogEngine.Core.BlogRollItem rollItem, HttpWebRequest request) { this.RollItem = rollItem; this.Request = request; }
/// <summary> /// Update blog /// </summary> /// <param name="blog">Blog to update</param> /// <returns>True on success</returns> public bool Update(BlogEngine.Core.Data.Models.Blog blog) { // sub-blogs not allowed to see other blogs if (!(Blog.CurrentInstance.IsPrimary && Security.IsAdministrator)) throw new System.UnauthorizedAccessException(); try { var coreBlog = Blog.Blogs.Where(b => b.Id == blog.Id).FirstOrDefault(); return Save(coreBlog, blog); } catch (Exception) { return false; } }
public override void UpdatePage(BlogEngine.Core.Page page) { throw new NotImplementedException(); }
public async Task GetHeadersPageNoCacheTest() { //Arrange var mockCache = new Mock <ICacheAccessor>(); var mockDb = new Mock <IBlogAccessor>(); mockDb.Setup(m => m.GetPostHeadersByPage(It.IsAny <int>(), It.IsAny <int>())) .ReturnsAsync(() => new[] { new PostHeader { BodyId = 1, Id = 1, Title = TestConstants.GuidString, Tags = new [] { new Tag { Id = 1, Text = TestConstants.GuidString }, new Tag { Id = 2, Text = TestConstants.GuidString } } }, new PostHeader { BodyId = 2, Id = 2, Title = TestConstants.GuidString, Tags = new [] { new Tag { Id = 3, Text = TestConstants.GuidString }, new Tag { Id = 4, Text = TestConstants.GuidString } } }, }); var engine = new BlogEngine(mockDb.Object, mockCache.Object); //Act var results = await engine.GetPageOfHeaders(0, 2); //Assert Assert.IsNotNull(results, "Should never be null"); Assert.IsInstanceOfType(results, typeof(IEnumerable <PostHeader>)); Assert.AreEqual(2, results.Count(), "Should be two headers on this page"); mockCache.Verify(m => m.CacheEnt <IEnumerable <PostHeader> >(It.IsAny <string>(), It.IsAny <IEnumerable <PostHeader> >(), It.IsAny <TimeSpan?>()), Times.Once, "Should be called once to cache results"); }
public override void UpdateBlogRollItem(BlogEngine.Core.BlogRollItem blogRollItem) { throw new NotImplementedException(); }
public override void UpdateReferrer(BlogEngine.Core.Referrer referrer) { throw new NotImplementedException(); }
static bool Save(Blog coreBlog, BlogEngine.Core.Data.Models.Blog jsonBlog) { coreBlog.Id = jsonBlog.Id; coreBlog.Name = jsonBlog.Name; coreBlog.StorageContainerName = jsonBlog.StorageContainerName; coreBlog.Hostname = jsonBlog.Hostname; coreBlog.IsAnyTextBeforeHostnameAccepted = jsonBlog.IsAnyTextBeforeHostnameAccepted; coreBlog.VirtualPath = jsonBlog.VirtualPath; coreBlog.IsActive = jsonBlog.IsActive; coreBlog.IsSiteAggregation = jsonBlog.IsSiteAggregation; coreBlog.IsPrimary = jsonBlog.IsPrimary; //coreBlog.StorageLocation = PhysicalStorageLocation = HostingEnvironment.MapPath(blog.StorageLocation); coreBlog.Save(); return true; }
private HtmlGenericControl BuildChildPageList(BlogEngine.Core.Page page) { HtmlGenericControl ul = new HtmlGenericControl("ul"); foreach (Page cPage in BlogEngine.Core.Page.Pages.FindAll(delegate(BlogEngine.Core.Page p) { //p => (p.Parent == page.Id))) return p.Parent == page.Id; })) { HtmlGenericControl cLi = new HtmlGenericControl("li"); cLi.Attributes.CssStyle.Add("font-weight", "normal"); HtmlAnchor cA = new HtmlAnchor(); cA.HRef = "?id=" + cPage.Id.ToString(); cA.InnerHtml = cPage.Title; System.Web.UI.LiteralControl cText = new System.Web.UI.LiteralControl (" (" + cPage.DateCreated.ToString("yyyy-dd-MM HH:mm") + ") "); string deleteText = "Are you sure you want to delete the page?"; HtmlAnchor delete = new HtmlAnchor(); delete.InnerText = Resources.labels.delete; delete.Attributes["onclick"] = "if (confirm('" + deleteText + "')){location.href='?delete=" + cPage.Id + "'}"; delete.HRef = "javascript:void(0);"; delete.Style.Add(System.Web.UI.HtmlTextWriterStyle.FontWeight, "normal"); cLi.Controls.Add(cA); cLi.Controls.Add(cText); cLi.Controls.Add(delete); if (cPage.HasChildPages) { cLi.Attributes.CssStyle.Remove("font-weight"); cLi.Attributes.CssStyle.Add("font-weight", "bold"); cLi.Controls.Add(BuildChildPageList(cPage)); } ul.Controls.Add(cLi); } return ul; }