示例#1
0
文件: ViewModels.cs 项目: csells/sb5
 public AtompubViewModel(HttpRequest request, string category = null, int page = 0)
 {
     // TODO: this is from the site description
       About = "About";
       CategoryScheme = "http://sellsbrothers.com/todo/categoryscheme";
       ContactEmail = "*****@*****.**";
       ContactName = "TodO Mally";
       ContactUrl = "http://example.com/TODO";
       CopyrightNotice = "Copyright (c) now-forever TODO Corp.";
       FeedId = "feedid";
       FeedTitle = "feedtitle";
       ImageUrl = new Uri(request.Scheme + "://" + request.Host + "/sellsbrothers_feed_logo.jpg");
       PostCategories = new PostCategory[] { new PostCategory { Name = "postcat-name-1", DisplayName = "postcat-display-1" }, new PostCategory { Name = "postcat-name-2", DisplayName = "postcat-display-2" }, };
       Posts = new Post[] {
     new Post { Author = "Chris Sells", Content = "<h1>testing</h1><p>123...</p>", CreationDate = new DateTime(1995, 1, 1, 12, 0, 0), Id = "1", Title = "Test 1" },
     new Post { Author = "Chris Sells", Content = "<h1>testing</h1><p>321...</p>", CreationDate = new DateTime(1995, 1, 1, 12, 0, 1), Id = "2", Title = "Test 2" },
     new Post { Author = "Chris Sells", Content = "<h1>testing</h1><p>abc...</p>", CreationDate = new DateTime(1995, 1, 1, 12, 0, 2), Id = "3", Title = "Test 3" },
       };
 }
示例#2
0
        IActionResult CreateAtomPost(XmlElement body)
        {
            // TODO
              //if (!BasicAuthSingleAdminUserModule.ForceSslAndBasicAuthAsAdmin()) { return null; }

            #if false
              // Get post data
              SyndicationItem entry = null;
              using (var reader = XmlReader.Create(Request.InputStream)) {
            entry = SyndicationItem.Load(reader);
              }

              // Create post
              var post = new Post() {
            Categories = entry.Categories.Aggregate("", (cats, cat) => cats.Length == 0 ? cat.Name : cats + "," + cat.Name),
            Content = ((TextSyndicationContent)entry.Content).Text,
            CreationDate = entry.PublishDate < minDate ? DateTime.Now : entry.PublishDate.DateTime,
            Author = entry.Authors.Count > 0 ? entry.Authors[0].Name : null,
            Email = entry.Authors.Count > 0 ? entry.Authors[0].Email : null,
            IsActive = true,
            Title = entry.Title.Text,
            UuidString = Guid.NewGuid().ToString(),
              };

              db.Add(post);
              db.SaveChanges();

              // Return the updated post
              var postLink = GetAtomPostLink(post.Id);
              entry.Id = postLink;
              entry.Authors.Add(new SyndicationPerson() { Name = db.Site.ContactName, Email = db.Site.ContactEmail });

              var sb = new StringBuilder();
              // OMG! WLW crashes if it gets back an XML declaration!
              using (var writer = XmlWriter.Create(sb, new XmlWriterSettings() { OmitXmlDeclaration = true })) { entry.SaveAsAtom10(writer); }
              var result = new SimpleActionResult() { ResponseOut = sb.ToString(), StatusCode = 201, StatusDescription = "Created" };
              result.Headers.Add("Location", postLink);
              return result;
            #endif
              return null;
        }
示例#3
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;
        }