public void CreateWithIdTest() { DateTime updatedDate = DateTime.Now; AtomFeed atomFeed = new AtomFeed() { Id = new Uri("tag:[email protected],2008:collection") }; Assert.IsNotNull(atomFeed); Assert.IsNotNull(atomFeed.Id); }
public void CreateWithSubtitleTest() { DateTime updatedDate = DateTime.Now; AtomFeed atomFeed = new AtomFeed() { Subtitle = new AtomSubtitle() { Text = "aSubtitle" } }; Assert.IsNotNull(atomFeed); Assert.IsNotNull(atomFeed.Subtitle); Assert.AreEqual("aSubtitle", atomFeed.Subtitle.Text); }
public void CreateWithRightsTest() { DateTime updatedDate = DateTime.Now; AtomFeed atomFeed = new AtomFeed() { Rights = new AtomRights() { Text = "aText" } }; Assert.IsNotNull(atomFeed); Assert.IsNotNull(atomFeed.Rights); Assert.AreEqual("aText", atomFeed.Rights.Text); }
protected void SetLinks(AtomFeed f) { if (f.Id != null && f.Id.Scheme == "tag") { if (!new BlogAppCollection(AppService.GetCollection(f.Id)).BloggingOn) return; LogService.Debug("BlogService.SetLinks feedId={0}", f.Id); var links = f.Links.ToList(); var url = new UrlHelper(Container.GetInstance<RequestContext>()); links.Merge(new AtomLink() { Rel = "alternate", Type = "text/html", Href = url.RouteIdUri("BlogListing", f.Id, AbsoluteMode.Force) }); f.Links = links; } }
protected void SetLinks(AtomFeed f) { LogService.Debug("AnnotateService.SetLinks feedId={0}", f.Id); var links = f.Links.ToList(); var url = new UrlHelper(Container.GetInstance<RequestContext>()); //atom threading extension if (f.Id != null && f.Id.Scheme == "tag") { links.Merge(new AtomLink { Href = url.RouteIdUri("AnnotateAnnotationsFeed", f.Id, AbsoluteMode.Force), Rel = "replies", Type = Atom.ContentType, Updated = DateTimeOffset.UtcNow }); } f.Links = links; }
protected virtual AtomFeed GetAnnotations(EntryCriteria criteria, int pageIndex, int pageSize) { AtomFeed feed = new AtomFeed(); feed.Subtitle = new AtomText(Atom.AtomNs + "subtitle") { Text = "Annotations" }; if (criteria.EntryId != null) //get annotations for an entry { AtomEntry parent = AtomEntryRepository.GetEntry(criteria.EntryId); feed.Title = parent.Title; feed.Id = parent.Id; //feed.Authors = parent.Authors; //feed.Contributors = parent.Contributors; } else if (criteria.CollectionName != null) //get annotations for a collection { AppCollection coll = AppService.GetCollection(criteria.WorkspaceName, criteria.CollectionName); feed.Id = coll.Id; feed.Title = coll.Title; //TODO: feed.Authors = coll.Authors; //TODO: feed.Contributors = coll.Contributors; } else if (criteria.WorkspaceName != null) //get annotations for an entire workspace { AppWorkspace ws = AppService.GetWorkspace(criteria.WorkspaceName); feed.Title = ws.Title; //TODO: feed.Authors = ws.Authors; //TODO: feed.Contributors = ws.Contributors; } else { feed.Title = new AtomTitle { Text = "Annotations" }; } int total; feed.Entries = AtomEntryRepository.GetEntries(criteria, pageIndex, pageSize, out total); feed.TotalResults = total; //foreach (AtomEntry e in feed.Entries) //{ // e.UpdateLinks(this.UrlHelper.RouteIdUri); //} return feed; }
/// <summary> /// Gets a feed of the given type (rss or atom) and remove's emails /// to prevent spam /// </summary> /// <param name="feed"></param> /// <param name="type"></param> /// <returns></returns> protected ActionResult GetFeedResult(AtomFeed feed, string type) { //remove email's to prevent spam foreach (AtomPerson person in feed.People.Concat(feed.Entries.SelectMany(e => e.People))) { person.Email = null; //string.Empty; } if (type == "atom") { return new XmlWriterResult((w) => feed.Xml.WriteTo(w)) { ContentType = Atom.ContentTypeFeed }; } else if (type == "rss") { return new XmlWriterResult((w) => feed.WriteRssTo(w)) { ContentType = "text/xml" }; } else { throw new ResourceNotFoundException(type + " feed", "requested"); } }
public AtomFeed GetFeedBySearch(string workspace, string term, int pageIndex, int pageSize) { LogService.Info("AtomPubService.GetFeedBySearch workspace={0} term={1} pageIndex={2}", workspace, term, pageIndex); AuthorizeService.Auth(new Scope() { Workspace = workspace }, AuthAction.GetFeed); EntryCriteria criteria = new EntryCriteria() { WorkspaceName = workspace, SearchTerm = term, Authorized = AuthorizeService.IsAuthorized(GetUser(), new Scope() { Workspace = workspace }, AuthAction.GetEntryOrMedia) }; int total; //search annotations? AtomFeed feed = new AtomFeed(); feed.Generator = new AtomGenerator { Text = "atomsite.net" }; AppWorkspace w = AppServiceRepository.GetService().GetWorkspace(workspace); feed.Title = w.Title; feed.Updated = DateTimeOffset.UtcNow; feed.Entries = AtomEntryRepository.GetEntries(criteria, pageIndex, pageSize, out total); feed.TotalResults = total; //use newest updated date as feed updated date if (feed.Entries.Count() > 0) feed.Updated = feed.Entries.Max().Updated; feed.Subtitle = new AtomSubtitle { Text = "Search for '" + term + "'" }; SetLinks(feed); return feed; }
protected void SetLinks(AtomFeed feed) { LogService.Debug("AtomPubService.SetLinks collectionId={0}", feed.Id); if (feed.Links == null) feed.Links = new List<AtomLink>(); var links = feed.Links.ToList(); var url = new UrlHelper(Container.GetInstance<RequestContext>()); links.Merge(new AtomLink() { Rel = "service", Type = Atom.ContentTypeService, Href = url.RouteUriEx("AtomPubService", AbsoluteMode.Force) }); if (feed.Id != null && feed.Id.Scheme == "tag") { links.Merge(new AtomLink() { Rel = "self", Type = Atom.ContentTypeFeed, Href = url.RouteIdUri("AtomPubFeed", feed.Id, AbsoluteMode.Force) }); links.Merge(new AtomLink() { Rel = "alternate", Type = "text/html", Href = url.RouteIdUri("AtomPubCollectionIndex", feed.Id, AbsoluteMode.Force) }); } feed.Links = links; foreach (AtomEntry entry in feed.Entries) SetLinks(entry); if (SettingFeedLinks != null) SettingFeedLinks(feed); }
public void FullCreateTest() { DateTime updatedDate = DateTime.Now; AtomFeed atomFeed = new AtomFeed() { Authors = new List<AtomPerson>(), Contributors = new List<AtomPerson>(), Base = new Uri("http://base.com"), Categories = new List<AtomCategory>(), Entries = new List<AtomEntry>(), Generator = new AtomGenerator(), Updated = updatedDate, Icon = new Uri("http://icon.com"), Lang = "EN", Links = new List<AtomLink>(), Logo = new Uri("http://logo.com") }; Assert.IsNotNull(atomFeed); Assert.IsNotNull(atomFeed.Authors); Assert.IsNotNull(atomFeed.Contributors); Assert.IsNotNull(atomFeed.Base); Assert.AreEqual(new Uri("http://base.com"), atomFeed.Base); Assert.IsNotNull(atomFeed.Categories); Assert.IsNotNull(atomFeed.Entries); Assert.IsNotNull(atomFeed.Generator); Assert.AreEqual(updatedDate, atomFeed.Updated); Assert.AreEqual(new Uri("http://icon.com"), atomFeed.Icon); Assert.AreEqual("EN", atomFeed.Lang); Assert.IsNotNull(atomFeed.Links); Assert.AreEqual(new Uri("http://logo.com"), atomFeed.Logo); }
/// <summary> /// Gets a consolidated feed of all collections in a workspace. /// </summary> /// <param name="workspaceName"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public virtual AtomFeed GetFeed(string workspaceName, int pageIndex, int pageSize) { LogService.Info("AtomPubService.GetFeed: workspace={0}", workspaceName); AuthorizeService.Auth(new Scope() { Workspace = workspaceName }, AuthAction.GetFeed); AppService svc = AppServiceRepository.GetService(); AtomFeed feed = new AtomFeed(); feed.Generator = new AtomGenerator { Text = "atomsite.net" }; feed.Id = new Uri("urn:" + Guid.NewGuid().ToString()); feed.Title = new AtomText() { Text = svc.Base.Authority }; int grandTotal = 0; if (!string.IsNullOrEmpty(workspaceName) || svc.Workspaces.Count() == 1) { //fill info from workspace feed.Title = svc.Workspaces.First().Title; feed.Subtitle = svc.Workspaces.First().Subtitle; //TODO: other props } //build feed for entire service or a single workspace var collections = svc.Workspaces.Where(w => w.Name == workspaceName || workspaceName == null) .SelectMany(w => w.Collections) .Where(c => c.SyndicationOn && c.Visible); List<AtomEntry> entries = new List<AtomEntry>(); foreach (AppCollection coll in collections) { if (AuthorizeService.IsAuthorized(GetUser(), coll.Id.ToScope(), AuthAction.GetFeed)) { int total; EntryCriteria criteria = new EntryCriteria() { WorkspaceName = coll.Id.Workspace, CollectionName = coll.Id.Collection, Authorized = AuthorizeService.IsAuthorized(GetUser(), coll.Id.ToScope(), AuthAction.GetEntryOrMedia), }; entries.AddRange(AtomEntryRepository.GetEntries(criteria, pageIndex, pageSize, out total)); grandTotal += total; } } feed.TotalResults = grandTotal; entries.OrderByDescending(e => e.Date); entries.Take(pageSize); feed.Entries = entries; SetLinks(feed); return feed; }
private IEnumerable<AtomCategory> GetCategories(AtomFeed Feed) { if (Feed.Entries.Count() == 0 || Feed.Entries.SelectMany(e => e.Categories).Count() == 0) return Enumerable.Empty<AtomCategory>(); return Feed.Entries.SelectMany(e => e.Categories).Distinct() .OrderBy(c => c.ToString()); }
public static AtomFeed Load(SyndicationFeed feed, int maxEntries) { feed.Items = feed.Items.Take(maxEntries); using (MemoryStream ms = new MemoryStream()) { XmlWriter w = new XmlTextWriter(ms, Encoding.UTF8); feed.GetAtom10Formatter().WriteTo(w); w.Flush(); AtomFeed atomFeed = new AtomFeed(); ms.Position = 0; XmlReader r = new XmlTextReader(ms); atomFeed.ReadXml(r); return atomFeed; } }
public static AtomFeed BuildFeed(AppCollection coll, IEnumerable<AtomEntry> entries, int total)//, int pageIndex, int pageSize), Func<string, Id, RouteValueDictionary, Uri> routeUri, //string atomRouteName, string webRouteName, bool addPaging) { AtomFeed feed = new AtomFeed(); feed.Generator = new AtomGenerator { Text = "atomsite.net" }; feed.Title = coll.Title; feed.Subtitle = coll.Subtitle; feed.Id = coll.Id; feed.Logo = coll.Logo; feed.Icon = coll.Icon; feed.Rights = coll.Rights; feed.Updated = DateTimeOffset.UtcNow; feed.TotalResults = total; feed.Entries = entries; //refresh links in case they change //foreach (AtomEntry e in feed.Entries) e.UpdateLinks(routeUri); //use newest updated date as feed updated date if (feed.Entries.Count() > 0) feed.Updated = feed.Entries.Max().Updated; //feed.GenerateLinks(routeUri, atomRouteName, webRouteName, pageIndex, pageSize, addPaging); //TODO: ensure all entries have author //NOTE: the below two statements would break any Views built on a FeedModel //TODO: save bandwidth, add author at feed level if all authors are the same, remove from entries //TODO: save bandwidth, add contrib at feed level if all contrib are the same, remove from entries return feed; }
public void CreateWithLinksTest() { AtomFeed atomFeed = new AtomFeed() { Links = TestHelper.MakeLinks(5) }; Assert.IsNotNull(atomFeed); Assert.IsNotNull(atomFeed.Links); Assert.AreEqual(5, atomFeed.Links.Count()); }
public void CreateWithCategoriesTest() { AtomFeed atomFeed = new AtomFeed() { Categories = TestHelper.MakeAtomCategoryList(5) }; Assert.IsNotNull(atomFeed); Assert.IsNotNull(atomFeed.Categories); Assert.AreEqual(5, atomFeed.Categories.Count()); }
public void CreateWithContributorsTest() { AtomFeed atomFeed = new AtomFeed() { Contributors = TestHelper.MakePersonList(5, Atom.AtomNs + "contributor") }; Assert.IsNotNull(atomFeed); Assert.IsNotNull(atomFeed.Contributors); Assert.AreEqual(5, atomFeed.Contributors.Count()); }
public void SimpleCreateTest() { AtomFeed atomFeed = new AtomFeed(); Assert.IsNotNull(atomFeed); }