Beispiel #1
0
 public SyndicationItem AddEntry(Uri feedUri, SyndicationItem newEntry)
 {
     if (feedUri == null)
     {
         throw new ArgumentNullException("feedUri");
     }
     if (newEntry == null)
     {
         throw new ArgumentNullException("newEntry");
     }
     return this.Post(feedUri, AtomEntryContentType, HttpContentExtensions.CreateDataContract(newEntry.GetAtom10Formatter())).EnsureStatusIs(HttpStatusCode.Created).Content.ReadAsDataContract<Atom10ItemFormatter>().Item;
 }
    public AtomEntry GetEntry(Id entryId)
    {
      ItemDataContext dc = new ItemDataContext();
      Item item = dc.Items.Where(i => i.Id == entryId.ToString()).SingleOrDefault();
      SyndicationItem si = new SyndicationItem()
      {
        Id = item.Id,
        LastUpdatedTime = item.LastUpdatedTime,
        PublishDate = item.PublishDate.Value
      };
      if (!string.IsNullOrEmpty(item.BaseUri)) si.BaseUri = new Uri(item.BaseUri);

      LoadAttributes(si.AttributeExtensions, item.Attributes);
      LoadElements(si.ElementExtensions, item.Elements);
      LoadPersons(si.Authors, item.Persons, PersonTypeAuthor);
      LoadPersons(si.Contributors, item.Persons, PersonTypeContributor);
      si.Content = GetContent(item.Content);
      si.Title = GetTextContent(item.Title);
      si.Summary = GetTextContent(item.Summary);
      si.Copyright = GetTextContent(item.Copyright);
      LoadLinks(si.Links, item.Links);
      LoadCategories(si.Categories, item.Categories);

      using (Stream s = new MemoryStream())
      {
        XmlWriter w = new XmlTextWriter(s, Encoding.UTF8);
        si.GetAtom10Formatter().WriteTo(w);
        w.Flush();
        AtomEntry entry = new AtomEntry();
        s.Position = 0;
        XmlReader r = new XmlTextReader(s);
        entry.Xml = XElement.Load(r);
        //entry.ReadXml(r);
        return entry;
      }
    }
        public HttpResponseMessage GetPost(string id, HttpRequestMessage request)
        {
            var post = _postManager.Get(id);
            if (post == null)
            {
                return new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.NotFound
                };
            }

            if (request.AcceptsHtml())
            {
                return new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.OK,
                    Content = new ObjectContent(typeof(Post), post, new List<MediaTypeFormatter>() { new PostHtmlMediaTypeFormatter() })
                };
            }
            else if (request.AcceptsAtom())
            {
                var item = new SyndicationItem()
                {
                    Id = post.Id,
                    Title = new TextSyndicationContent(post.Title),
                    LastUpdatedTime = post.LastUpdatedTime,
                    Content = new TextSyndicationContent(post.Content)
                };
                return new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.OK,
                    Content = new ObjectContent(typeof(Atom10ItemFormatter), item.GetAtom10Formatter())
                };
            }
            else
            {
                return new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.InternalServerError
                };
            }
        }
Beispiel #4
0
 public SyndicationItem UpdateEntry(Uri editUri, SyndicationItem newValue)
 {
     if (editUri == null)
     {
         throw new ArgumentNullException("editUri");
     }
     if (newValue == null)
     {
         throw new ArgumentNullException("newValue");
     }
     return this.Put(editUri, AtomEntryContentType, HttpContentExtensions.CreateDataContract(newValue.GetAtom10Formatter())).EnsureStatusIs(HttpStatusCode.OK).Content.ReadAsDataContract<Atom10ItemFormatter>().Item;
 }