Exemplo n.º 1
0
        SyndicationItem GetAtomItem(AtompubViewModel vm, Post post)
        {
            string authorEmail = post.Email;
              string authorName = post.Author;
              if (string.IsNullOrWhiteSpace(authorEmail) && string.IsNullOrWhiteSpace(authorName)) {
            authorEmail = vm.ContactEmail;
            authorName = vm.ContactName;
              }

              var entry = new SyndicationItem() {
            Content = new TextSyndicationContent(post.Content, TextSyndicationContentKind.Html),
            Id = GetPostLink(post.Id),
            LastUpdatedTime = post.CreationDate,
            Links = {
              new SyndicationLink(new Uri(GetAtomPostLink(post.Id)), "edit", null, null, 0),
              new SyndicationLink(new Uri(GetPostLink(post.Id)), "alternate", null, "text/html", 0),
            },
            PublishDate = post.CreationDate,
            Title = new TextSyndicationContent(post.Title),
            Authors = { new SyndicationPerson(authorEmail, authorName, null) },
              };

              // Split each item category with embedded commas
              if (post.Categories != null && post.Categories.Contains(',')) {
            foreach (var category in post.Categories.Split(',')) {
              entry.Categories.Add(new SyndicationCategory(category));
            }
              }

              return entry;
        }
Exemplo n.º 2
0
        ServiceDocument GetServiceDocument(AtompubViewModel vm)
        {
            var workspaces = new Workspace[] {
            new Workspace("Default", new ResourceCollectionInfo[] {
              new ResourceCollectionInfo("Posts",                              new Uri(Url.Action("posts"), UriKind.Relative)) { Categories = { new InlineCategoriesDocument() { IsFixed = false, Scheme = vm.CategoryScheme } } },
              new ResourceCollectionInfo(new TextSyndicationContent("Images"), new Uri(Url.Action("images"), UriKind.Relative), null, new string[] { "image/*" } ),
            }),
              };
              var doc = new ServiceDocument(workspaces);

              var categories = ((InlineCategoriesDocument)doc.Workspaces[0].Collections[0].Categories[0]).Categories;
              foreach (var cat in vm.PostCategories) {
            categories.Add(new SyndicationCategory(cat.Name, null, cat.DisplayName));
              }

              return doc;
        }
Exemplo n.º 3
0
        SyndicationFeed GetAtomFeed(AtompubViewModel vm)
        {
            var posts = vm.Posts.ToArray();
              var feed = new SyndicationFeed() {
            Authors = { new SyndicationPerson(vm.ContactEmail, vm.ContactName, vm.ContactUrl) },
            ImageUrl = vm.ImageUrl,
            Copyright = new TextSyndicationContent(vm.CopyrightNotice),
            Description = new TextSyndicationContent(vm.About),
            Id = vm.FeedId,
            //Language = "en-us", // TODO: make this work
            LastUpdatedTime = posts.Length == 0 ? DateTime.Now : posts[0].CreationDate,
            Title = new TextSyndicationContent(vm.FeedTitle),
            Items = posts.Select(p => GetAtomItem(vm, p)),
              };

              foreach (var cat in vm.PostCategories) {
            feed.Categories.Add(new SyndicationCategory(cat.Name, vm.CategoryScheme, cat.DisplayName));
              }

              return feed;
        }