当前位置: 首页>>代码示例>>C#>>正文


C# SyndicationFeed.GetAtom10Formatter方法代码示例

本文整理汇总了C#中System.ServiceModel.Syndication.SyndicationFeed.GetAtom10Formatter方法的典型用法代码示例。如果您正苦于以下问题:C# SyndicationFeed.GetAtom10Formatter方法的具体用法?C# SyndicationFeed.GetAtom10Formatter怎么用?C# SyndicationFeed.GetAtom10Formatter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ServiceModel.Syndication.SyndicationFeed的用法示例。


在下文中一共展示了SyndicationFeed.GetAtom10Formatter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetService

        public async Task<IHttpActionResult> GetService(string id)
        {
            Service service = await db.Services.FindAsync(id);
            if (service == null)
            {
                return NotFound();
            }

            var ServiceFeed = new SyndicationFeed();
            ServiceFeed.Id = service.Id;
            ServiceFeed.LastUpdatedTime = service.Updated;
            ServiceFeed.Title = new TextSyndicationContent(service.Title);
            ServiceFeed.Description = new TextSyndicationContent(service.Summary);

            ServiceFeed.Categories.Add(new SyndicationCategory(service.ServiceCategoryId.ToString(), null, service.Category.Name));

            var SelfLink = new SyndicationLink();
            SelfLink.RelationshipType = "self";
            SelfLink.Uri = new Uri(Url.Content("~/Service/" + service.Id));
            SelfLink.MediaType = "application/atom+xml";
            ServiceFeed.Links.Add(SelfLink);

            var HtmlLink = new SyndicationLink();
            HtmlLink.RelationshipType = "self";
            HtmlLink.Uri = new Uri("http://surreyhillsdc.azurewebsites.net/");
            HtmlLink.MediaType = "text/html";
            ServiceFeed.Links.Add(HtmlLink);

            return Ok(ServiceFeed.GetAtom10Formatter());
        }
开发者ID:BforBen,项目名称:OpenGovApi,代码行数:30,代码来源:ServiceController.cs

示例2: GetFeedContent

        private string GetFeedContent(SyndicationFeed feed)
        {
            using (var sw = new StringWriter())
            using (var xw = XmlWriter.Create(sw))
            {
                feed.GetAtom10Formatter().WriteTo(xw);
                xw.Flush();

                return sw.ToString();
            }
        }
开发者ID:elbandit,项目名称:PPPDDD,代码行数:11,代码来源:BeganFollowingController.cs

示例3: StreamedFeed

        public Atom10FeedFormatter StreamedFeed()
        {
            SyndicationFeed feed = new SyndicationFeed("Streamed feed", "Feed to test streaming", null);

            //Generate an infinite stream of items. Both the client and the service share
            //a reference to the ItemCounter, which allows the sample to terminate
            //execution after the client has read 10 items from the stream
            ItemGenerator itemGenerator = new ItemGenerator(this.counter, 10);

            feed.Items = itemGenerator.GenerateItems();
            return feed.GetAtom10Formatter();
        }
开发者ID:spzenk,项目名称:sfdocsamples,代码行数:12,代码来源:StreamingFeedService.cs

示例4: GetProcessesFeed

        public Atom10FeedFormatter GetProcessesFeed( int topItems )
        {
            // Create the list of syndication items. These correspond to Atom entries
            List<SyndicationItem> items = new List<SyndicationItem>();
            int currentItem = 0;
            foreach (Process currentProces in Process.GetProcesses())
            {
                currentItem += 1;
                if ( topItems > 0 && currentItem > topItems )
                {
                    continue;
                }
                items.Add( new SyndicationItem
                {
                    // Every entry must have a stable unique URI id
                    Id = String.Format( "http://tempuri.org/Processes?max={0}", currentProces.Id ),
                    Title = new TextSyndicationContent( String.Format( "Process '{0}'", currentProces.ProcessName ) ),
                    // Every entry should include the last time it was updated
                    LastUpdatedTime = DateTime.Now,
                    // The Atom spec requires an author for every entry. If the entry has no author, use the empty string
                    Authors =
                    {
                        new SyndicationPerson()
                        {
                            Name = currentProces.StartInfo.UserName
                        }
                    },
                    // The content of an Atom entry can be text, xml, a link or arbitrary content. In this sample text content is used.
                    Content = new TextSyndicationContent( String.Format( "FileName: {0}\nArguments: {1}", currentProces.StartInfo.FileName, currentProces.StartInfo.Arguments) ),
                } );

            }
            // create the feed containing the syndication items.
            SyndicationFeed feed =
                new SyndicationFeed
                {
                    // The feed must have a unique stable URI id
                    Id = "http://tempuri.org/FeedId",
                    Title = new TextSyndicationContent( "Processor List" ),
                    Items = items
                };
            #region Sets response content-type for Atom feeds
            WebOperationContext.Current.OutgoingResponse.ContentType = "application/atom+xml";
            #endregion
            return feed.GetAtom10Formatter();
        }
开发者ID:RolfEleveld,项目名称:TryoutCSharp,代码行数:46,代码来源:Service.svc.cs

示例5: SerializeFeed

        public string SerializeFeed(SyndicationFeed feed, SyndicationFormat format)
        {
            using (var stream = new MemoryStream())
            {
                var writer = XmlWriter.Create(stream);

                if (format == SyndicationFormat.Atom)
                {
                    feed.GetAtom10Formatter().WriteTo(writer);
                }
                else
                {
                    feed.GetRss20Formatter().WriteTo(writer);
                }

                writer.Flush();

                stream.Position = 0;

                var reader = new StreamReader(stream, Encoding.UTF8);
                return reader.ReadToEnd();
            }
        }
开发者ID:dstarosta,项目名称:GitProjects,代码行数:23,代码来源:FeedResultTests.cs

示例6: GetContacts

    public Atom10FeedFormatter GetContacts()
    {
      var items = new List<SyndicationItem>();

      var repository = new ContactsRepository();

      foreach (Contact contact in repository.GetContactsForUser(Thread.CurrentPrincipal.Identity.Name))
      {
        items.Add(new SyndicationItem
          {
            Id = String.Format(CultureInfo.InvariantCulture, "http://contacts.org/{0}", Guid.NewGuid()),
            Title = new TextSyndicationContent(contact.FullName),
            LastUpdatedTime = DateTime.UtcNow,
            Authors =
              {
                new SyndicationPerson
                  {
                    Name = "Sample Author"
                  }
              },
            Content = new TextSyndicationContent(contact.Email),
          });
      }

      // create the feed containing the syndication items.

      var feed = new SyndicationFeed
        {
          // The feed must have a unique stable URI id

          Id = "http://contacts/Feed",
          Title = new TextSyndicationContent("Contacts feed"),
          Items = items
        };

      feed.AddSelfLink(WebOperationContext.Current.IncomingRequest.GetRequestUri());

      WebOperationContext.Current.OutgoingResponse.ContentType = ContentTypes.Atom;

      return feed.GetAtom10Formatter();
    }
开发者ID:tiwariritesh7,项目名称:devdefined-tools,代码行数:41,代码来源:ContactsService.svc.cs

示例7: Load

 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;
   }
 }
开发者ID:erikzaadi,项目名称:atomsitethemes.erikzaadi.com,代码行数:15,代码来源:AtomFeed.cs

示例8: GetFeed

        //[WebGet(UriTemplate="help")]
        public Atom10FeedFormatter GetFeed()
        {
            List<SyndicationItem> items = new List<SyndicationItem>();
            foreach (OperationDescription od in this.Description.Operations)
            {
                WebGetAttribute get;
                WebInvokeAttribute invoke;
                GetWebGetAndInvoke(od, out get, out invoke);    
                string method = GetMethod(get, invoke);
                string requestFormat = null;
                if (invoke != null)
                {
                    requestFormat = GetRequestFormat(invoke, od);
                }
                string responseFormat = GetResponseFormat(get, invoke, od);
                string uriTemplate = GetUriTemplate(get, invoke, od);
                WebMessageBodyStyle bodyStyle = GetBodyStyle(get, invoke);

                string requestSchemaLink = null;
                string responseSchemaLink = null;
                string requestExampleLink = null;
                string responseExampleLink = null;

                if (bodyStyle == WebMessageBodyStyle.Bare)
                {
                    UriTemplate responseSchemaTemplate = new UriTemplate(OperationResponseSchemaTemplate);
                    responseSchemaLink = responseSchemaTemplate.BindByPosition(this.BaseUri, od.Name).AbsoluteUri;

                    UriTemplate responseExampleTemplate = new UriTemplate(OperationResponseExampleTemplate);
                    responseExampleLink = responseExampleTemplate.BindByPosition(this.BaseUri, od.Name).AbsoluteUri;
                    if (invoke != null)
                    {
                        UriTemplate requestSchemaTemplate = new UriTemplate(OperationRequestSchemaTemplate);
                        requestSchemaLink = requestSchemaTemplate.BindByPosition(this.BaseUri, od.Name).AbsoluteUri;

                        UriTemplate requestExampleTemplate = new UriTemplate(OperationRequestExampleTemplate);
                        requestExampleLink = requestExampleTemplate.BindByPosition(this.BaseUri, od.Name).AbsoluteUri;
                    }
                }

                uriTemplate = String.Format("{0}/{1}", this.BaseUri.AbsoluteUri, uriTemplate);
                uriTemplate = HttpUtility.HtmlEncode(uriTemplate);

                string xhtmlDescription = String.Format("<div xmlns=\"http://www.w3.org/1999/xhtml\"><table border=\"5\"><tr><td>UriTemplate</td><td>{0}</td></tr><tr><td>Method</td><td>{1}</td></tr>", uriTemplate, method);
                if (!string.IsNullOrEmpty(requestFormat))
                {
                    xhtmlDescription += String.Format("<tr><td>Request Format</td><td>{0}</td></tr>", requestFormat);
                }
                if (requestSchemaLink != null)
                {
                    xhtmlDescription += String.Format("<tr><td>Request Schema</td><td><a href=\"{0}\">{0}</a></td></tr>", HttpUtility.HtmlEncode(requestSchemaLink));
                }
                if (requestExampleLink != null)
                {
                    xhtmlDescription += String.Format("<tr><td>Request Example</td><td><a href=\"{0}\">{0}</a></td></tr>", HttpUtility.HtmlEncode(requestExampleLink));
                }
                xhtmlDescription += String.Format("<tr><td>Response Format</td><td>{0}</td></tr>", responseFormat);
                if (responseSchemaLink != null)
                {
                    xhtmlDescription += String.Format("<tr><td>Response Schema</td><td><a href=\"{0}\">{0}</a></td></tr>", HttpUtility.HtmlEncode(responseSchemaLink));
                }
                if (responseExampleLink != null)
                {
                    xhtmlDescription += String.Format("<tr><td>Response Example</td><td><a href=\"{0}\">{0}</a></td></tr>", HttpUtility.HtmlEncode(responseExampleLink));
                }
                WebHelpAttribute help = od.Behaviors.Find<WebHelpAttribute>();
                if (help != null && !string.IsNullOrEmpty(help.Comment))
                {
                    xhtmlDescription += String.Format("<tr><td>Description</td><td>{0}</td></tr>", help.Comment);
                }
                xhtmlDescription += "</table></div>";
                SyndicationItem item = new SyndicationItem()
                {
                    Id = "http://tmpuri.org/" + od.Name,
                    Content = new TextSyndicationContent(xhtmlDescription, TextSyndicationContentKind.XHtml),
                    LastUpdatedTime = DateTime.UtcNow,
                    Title = new TextSyndicationContent(String.Format("{0}: {1}", Description.Name, od.Name)),
                };
                items.Add(item);
            }

            SyndicationFeed feed = new SyndicationFeed()
            {
                Title = new TextSyndicationContent("Service help page"),
                Id = feedId,
                LastUpdatedTime = DateTime.UtcNow,
                Items = items
            };
            WebOperationContext.Current.OutgoingResponse.ContentType = "application/atom+xml";
            return feed.GetAtom10Formatter();
        }
开发者ID:pusp,项目名称:o2platform,代码行数:92,代码来源:HelpPageInvoker.cs

示例9: GetCategoriesDocument

        /// <summary>
        /// Gets the categories document.
        /// </summary>
        /// <returns></returns>
        /// <remarks>Documented by Dev05, 2012-02-07</remarks>
        private XmlDocument GetCategoriesDocument()
        {
            SyndicationFeed feed = new SyndicationFeed();
            feed.Id = Settings.Default.CategoriesFeedId.ToString();
            feed.Title = new TextSyndicationContent("MemoryLifter Module Categories", TextSyndicationContentKind.Plaintext);
            feed.Description = new TextSyndicationContent("Lists all categories with modules available.", TextSyndicationContentKind.Plaintext);
            feed.LastUpdatedTime = new DateTimeOffset(DateTime.Now);

            feed.Authors.Add(new SyndicationPerson("[email protected]", "OMICRON", "http://www.memorylifter.com"));
            List<SyndicationItem> items = new List<SyndicationItem>();
            feed.Items = items;

            string filename = Server.MapPath(Path.Combine(Settings.Default.InfoFolder, "categories.xml"));
            if (File.Exists(filename))
            {
                Stream file = File.OpenRead(filename);
                categories = categoriesSerializer.Deserialize(file) as SerializableList<ModuleCategory>;
                file.Close();

                foreach (ModuleCategory category in categories)
                {
                    SyndicationItem item = new SyndicationItem();
                    item.Id = category.Id.ToString();
                    item.Title = new TextSyndicationContent(category.Title, TextSyndicationContentKind.Plaintext);
                    item.Links.Add(new SyndicationLink() { RelationshipType = AtomLinkRelationshipType.Parent.ToString(), Title = category.ParentCategory.ToString() });
                    items.Add(item);
                }
            }

            StringBuilder result = new StringBuilder();
            XmlWriter writer = XmlWriter.Create(result);
            feed.GetAtom10Formatter().WriteTo(writer);
            writer.Flush();

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(result.ToString());
            return doc;
        }
开发者ID:Stoner19,项目名称:Memory-Lifter,代码行数:43,代码来源:ModuleService.asmx.cs

示例10: GetModulesDocument

        /// <summary>
        /// Gets the modules document.
        /// </summary>
        /// <returns></returns>
        /// <remarks>Documented by Dev05, 2012-02-07</remarks>
        private XmlDocument GetModulesDocument()
        {
            SyndicationFeed feed = new SyndicationFeed();
            feed.Id = Settings.Default.ModuleFeedId.ToString();
            feed.Title = new TextSyndicationContent("MemoryLifter Modules", TextSyndicationContentKind.Plaintext);
            feed.Description = new TextSyndicationContent("Lists all modules available.", TextSyndicationContentKind.Plaintext);
            feed.LastUpdatedTime = new DateTimeOffset(DateTime.Now);

            feed.Authors.Add(new SyndicationPerson("[email protected]", "OMICRON", "http://www.memorylifter.com"));
            List<SyndicationItem> items = new List<SyndicationItem>();
            feed.Items = items;

            foreach (string file in Directory.GetFiles(Server.MapPath(Settings.Default.ModulesFolder), "*.mlm", SearchOption.AllDirectories))
            {
                SyndicationItem item = new SyndicationItem();
                items.Add(item);

                string filename = Path.GetFileNameWithoutExtension(file);
                string xmlFile = Path.Combine(Server.MapPath(Settings.Default.InfoFolder), filename + ".xml");

                long size = 0;
                if (File.Exists(xmlFile)) //if there is a xml-info-file use the information from it
                {
                    Stream fStream = File.OpenRead(xmlFile);
                    ModuleInfo info = (ModuleInfo)infoSerializer.Deserialize(fStream);
                    fStream.Close();

                    item.Id = info.Id;
                    item.Title = new TextSyndicationContent(info.Title, TextSyndicationContentKind.Plaintext);
                    item.Content = new TextSyndicationContent(info.Description, TextSyndicationContentKind.Plaintext); //This is also shown in feed readers as text
                    //As the summary we use a struct which can be deserialized to a ModuleInfo-struct
                    item.Summary = new TextSyndicationContent("<ModuleInfo><Cards>" + info.Cards + "</Cards></ModuleInfo>", TextSyndicationContentKind.XHtml);
                    foreach (string category in info.Categories)
                    {
                        ModuleCategory cat = (from c in categories
                                              where c.Id.ToString() == category
                                              select c).FirstOrDefault();
                        if(cat.Id > 0) //if the stored category is actually an Id to a category
                            item.Categories.Add(new SyndicationCategory(cat.Title) { Label = category });
                        else
                            item.Categories.Add(new SyndicationCategory(category));
                    }
                    item.Contributors.Add(new SyndicationPerson(info.AuthorMail, info.Author, info.AuthorUrl));
                    DateTime time;
                    if (DateTime.TryParse(info.EditDate, out time))
                        item.LastUpdatedTime = new DateTimeOffset(time);
                    else
                        item.LastUpdatedTime = new DateTimeOffset((new FileInfo(file)).LastWriteTime);
                    size = info.Size;
                }
                else // use the information you can get from the file - no SQL CE access on Mono --> if running on IIS/.net you could read it form the file
                {
                    item.Id = file.GetHashCode().ToString();
                    item.Title = new TextSyndicationContent(filename, TextSyndicationContentKind.Plaintext);
                    item.LastUpdatedTime = new DateTimeOffset((new FileInfo(file)).LastWriteTime);
                }
                if (size <= 0)
                    size = (new FileInfo(file)).Length;

                item.Links.Add(new SyndicationLink(new Uri(BaseAddress + Settings.Default.ModulesFolder + '/' + Uri.EscapeDataString(Path.GetFileName(file))))
                {
                    MediaType = "application/x-mlm",
                    RelationshipType = AtomLinkRelationshipType.Module.ToString(),
                    Length = size
                });
                item.Links.Add(new SyndicationLink(new Uri(BaseAddress + "GetImage.ashx?size=150&module=" + HttpUtility.UrlEncode(filename)))
                {
                    MediaType = "image/png",
                    RelationshipType = AtomLinkRelationshipType.Preview.ToString()
                });
                item.Links.Add(new SyndicationLink(new Uri(BaseAddress + "GetImage.ashx?size=32&module=" + HttpUtility.UrlEncode(filename)))
                {
                    MediaType = "image/png",
                    RelationshipType = AtomLinkRelationshipType.IconBig.ToString()
                });
                item.Links.Add(new SyndicationLink(new Uri(BaseAddress + "GetImage.ashx?size=16&module=" + HttpUtility.UrlEncode(filename)))
                {
                    MediaType = "image/png",
                    RelationshipType = AtomLinkRelationshipType.IconSmall.ToString()
                });
            }

            StringBuilder result = new StringBuilder();
            XmlWriter writer = XmlWriter.Create(result);
            feed.GetAtom10Formatter().WriteTo(writer);
            writer.Flush();

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(result.ToString());
            return doc;
        }
开发者ID:Stoner19,项目名称:Memory-Lifter,代码行数:96,代码来源:ModuleService.asmx.cs

示例11: GetPosts

        public HttpResponseMessage GetPosts(HttpRequestMessage request)
        {
            string baseUrl = request.BaseUrl("posts");

            List<Post> posts = _postManager.GetAllPosts();
            if (posts == null || posts.Count == 0)
            {
                return new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.NotFound
                };
            }
            else
            {
                if (request.AcceptsHtml())
                {
                    return new HttpResponseMessage()
                    {
                        StatusCode = HttpStatusCode.OK,
                        Content = new ObjectContent(typeof(List<Post>), posts, new List<MediaTypeFormatter>() { new PostListHtmlMediaTypeFormatter() })
                    };
                }
                else
                {
                    var postsFeed = new SyndicationFeed()
                    {
                        Id = baseUrl,
                        Title = new TextSyndicationContent("List of posts"),
                        LastUpdatedTime = new DateTimeOffset(DateTime.Now)
                    };
                    postsFeed.Links.Add(new SyndicationLink() 
                    {
                        Uri = request.RequestUri,
                        RelationshipType = "self"
                    });
                    postsFeed.Items = posts.Select(p => new SyndicationItem()
                    {
                        Id = p.Id,
                        Title = new TextSyndicationContent(p.Title),
                        LastUpdatedTime = p.LastUpdatedTime,
                        Content =  new TextSyndicationContent(p.Content)
                    });

                    if (request.AcceptsAtom() || request.AcceptsAll())
                    {
                        return new HttpResponseMessage()
                        {
                            StatusCode = HttpStatusCode.OK,
                            Content = new ObjectContent(typeof(Atom10FeedFormatter), postsFeed.GetAtom10Formatter())
                        };
                    }

                    return new HttpResponseMessage()
                    {
                        StatusCode = HttpStatusCode.InternalServerError
                    };
                }
            }
        }
开发者ID:sandrapatfer,项目名称:PROMPT11-06-Services.sandrapatfer,代码行数:59,代码来源:BlogEngineService.cs

示例12: Main

        static void Main(string[] args)
        {
            //Create an extensible object (in this case, SyndicationFeed). Other extensible types (SyndicationItem,
            //SyndicationCategory, SyndicationPerson, SyndicationLink) follow the same pattern.
            SyndicationFeed feed = new SyndicationFeed();

            //Attribute extensions are stored in a dictionary indexed by XmlQualifiedName
            feed.AttributeExtensions.Add(new XmlQualifiedName("myAttribute", ""), "someValue");

            //Add several different types of element extensions.
            feed.ElementExtensions.Add("simpleString", "", "hello, world!");
            feed.ElementExtensions.Add("simpleString", "", "another simple string");

            feed.ElementExtensions.Add( new DataContractExtension() { Key = "X", Value = 4 } );
            feed.ElementExtensions.Add( new XmlSerializerExtension { Key = "Y", Value = 8 }, new XmlSerializer( typeof( XmlSerializerExtension ) ) );

            feed.ElementExtensions.Add(new XElement("xElementExtension",
                                           new XElement("Key", new XAttribute("attr1", "someValue"), "Z"),
                                           new XElement("Value", new XAttribute("attr1", "someValue"), "15")).CreateReader());

            //Dump the raw feed XML to the console to show how extensions elements appear in the final XML
            Console.WriteLine("Raw XML");
            Console.WriteLine( "-------" );
            DumpToConsole( feed.GetAtom10Formatter() );
            Console.WriteLine(Environment.NewLine);

            //Read in the XML into a new SyndicationFeed to show the "read" path
            Stream inputStream = WriteToMemoryStream(feed.GetAtom10Formatter());
            SyndicationFeed feed2 = SyndicationFeed.Load(new XmlTextReader(inputStream));

            Console.WriteLine("Attribute Extensions");
            Console.WriteLine("--------------------");

            Console.WriteLine( feed.AttributeExtensions[ new XmlQualifiedName( "myAttribute", "" )]);
            Console.WriteLine("");

            Console.WriteLine("Primitive Extensions");
            Console.WriteLine("--------------------");
            foreach( string s in feed2.ElementExtensions.ReadElementExtensions<string>("simpleString", ""))
            {
                Console.WriteLine(s);
            }

            Console.WriteLine("");

            Console.WriteLine("SerializableExtensions");
            Console.WriteLine("----------------------");

            foreach (DataContractExtension dce in feed2.ElementExtensions.ReadElementExtensions<DataContractExtension>("DataContractExtension",
                                                                                                                        "http://schemas.datacontract.org/2004/07/SyndicationExtensions"))
            {
                Console.WriteLine(dce.ToString());
            }

            Console.WriteLine("");

            foreach (XmlSerializerExtension xse in feed2.ElementExtensions.ReadElementExtensions<XmlSerializerExtension>("XmlSerializerExtension", "", new XmlSerializer(typeof(XmlSerializerExtension))))
            {
                Console.WriteLine(xse.ToString());
            }

            Console.WriteLine("");

            Console.WriteLine("XElement Extensions");
            Console.WriteLine("-------------------");

            foreach (SyndicationElementExtension extension in feed2.ElementExtensions.Where<SyndicationElementExtension>(x => x.OuterName == "xElementExtension"))
            {
                XNode xelement = XElement.ReadFrom(extension.GetReader());
                Console.WriteLine(xelement.ToString());
            }

            Console.WriteLine("");

            Console.WriteLine("Reader over all extensions");
            Console.WriteLine("--------------------------");

            XmlReader extensionsReader = feed2.ElementExtensions.GetReaderAtElementExtensions();

            while (extensionsReader.IsStartElement())
            {
                XNode extension = XElement.ReadFrom(extensionsReader);
                Console.WriteLine(extension.ToString());
            }

            Console.ReadLine();
        }
开发者ID:tian1ll1,项目名称:WPF_Examples,代码行数:87,代码来源:Program.cs

示例13: Save

        public static void Save()
        {
            var values = Items.Values;
            foreach (var item in values)
                item.WriteExtensions();

            var items = new Item[Items.Count];
            values.CopyTo(items, 0);

            XmlWriter writer = XmlWriter.Create(itemfile_tmp);
            SyndicationFeed sf = new SyndicationFeed(items);
            Atom10FeedFormatter fmtr = sf.GetAtom10Formatter();
            fmtr.WriteTo(writer);
            writer.Close();
            File.Delete(itemfile);
            File.Move(itemfile_tmp, itemfile);
        }
开发者ID:GNOME,项目名称:blam,代码行数:17,代码来源:ItemStore.cs

示例14: GetPosts

        public HttpResponseMessage GetPosts(string id, HttpRequestMessage request, int pageIndex = 1, int pageSize = 10)
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

            try
            {
                IPostsService postsService = ObjectFactory.GetInstance<IPostsService>();
                var posts = postsService.GetAllFromBlog(String.Format("blogs/{0}", id), pageIndex, pageSize);

                if (posts != null)
                {
                    if (this.ClientAcceptsMediaType("text/html", request))
                    {
                        var postsHtml = posts.GeneratePostsHtml();
                        response.Content = new ObjectContent<string>(postsHtml, "text/html");
                    }
                    else
                    {
                        SyndicationFeed blogPostsFeed = new SyndicationFeed
                                                            {
                                                                Title =
                                                                    new TextSyndicationContent(
                                                                    String.Format("Blog {0} posts", id)),
                                                                LastUpdatedTime = new DateTimeOffset(DateTime.Now)
                                                            };

                        blogPostsFeed.Links.Add(SyndicationLink.CreateSelfLink(request.RequestUri));

                        List<SyndicationItem> itemList = new List<SyndicationItem>();
                        blogPostsFeed.Items = itemList;

                        foreach (var post in posts)
                        {
                            SyndicationItem item = new SyndicationItem
                                                       {
                                                           Id = post.Id,
                                                           LastUpdatedTime = post.updated,
                                                           PublishDate = post.published,
                                                           Title = new TextSyndicationContent(post.title)
                                                       };

                            item.Links.Add(SyndicationLink.CreateSelfLink(new Uri(String.Format("{0}/{1}/{2}", this.serviceURI, post.blogId, post.Id))));
                            item.Links.Add(SyndicationLink.CreateAlternateLink(request.RequestUri, "text/html"));

                            item.Links.Add(new SyndicationLink(new Uri(String.Format("{0}/{1}", this.serviceURI, post.blogId)), "service.blog", "Parent blog", "application/atom+xml;type=feed", 0));
                            item.Links.Add(new SyndicationLink(new Uri(String.Format("{0}/{1}/{2}", this.serviceURI, post.blogId, post.Id)), "service.edit", "Edit post", "application/atom+xml;type=feed", 0));
                            item.Links.Add(new SyndicationLink(new Uri(String.Format("{0}/{1}/{2}/{3}", this.serviceURI, post.blogId, post.Id, "service.comments")), "comments", "Post comments", "application/atom+xml;type=feed", 0));

                            var pagingLinks = this.BuildPagingLinks(postsService.Count(), pageIndex, pageSize, request.RequestUri);

                            foreach (var link in pagingLinks)
                            {
                                item.Links.Add(link);
                            }

                            item.Authors.Add(new SyndicationPerson(string.Empty, post.author, string.Empty));
                            item.Content = SyndicationContent.CreatePlaintextContent(post.content);

                            itemList.Add(item);
                        }

                        SyndicationFeedFormatter formatter = null;

                        if (this.ClientAcceptsMediaType("application/atom+xml", request))
                        {
                            formatter = blogPostsFeed.GetAtom10Formatter();
                        }
                        else
                        {
                            if (this.ClientAcceptsMediaType("application/rss+xml", request))
                            {
                                formatter = blogPostsFeed.GetRss20Formatter();
                            }
                        }

                        response.Content = new ObjectContent(typeof(SyndicationFeedFormatter), formatter);
                    }
                }
                else
                {
                    response.StatusCode = HttpStatusCode.NoContent;
                }
            }
            catch (Exception)
            {
                response.StatusCode = HttpStatusCode.InternalServerError;
            }

            return response;
        }
开发者ID:luismdcp,项目名称:PROMPT-06-Services,代码行数:90,代码来源:RESTBlogsService.cs

示例15: GetPost

        public HttpResponseMessage GetPost(string blogId, string id, HttpRequestMessage request)
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

            try
            {
                IPostsService postsService = ObjectFactory.GetInstance<IPostsService>();
                var post = postsService.Get(String.Format("posts/{0}", id));

                var etag = request.Headers.IfNoneMatch.FirstOrDefault();

                if (etag != null && etag.Tag == post.etag)
                {
                    response.StatusCode = HttpStatusCode.NotModified;
                }
                else
                {
                    if (post != null)
                    {
                        if (this.ClientAcceptsMediaType("text/html", request))
                        {
                            response.Content = new ObjectContent<string>(post.ToHtml(), "text/html");
                        }
                        else
                        {
                            SyndicationFeed postFeed = new SyndicationFeed
                                                           {
                                                               Title = new TextSyndicationContent("Single Post"),
                                                               LastUpdatedTime = new DateTimeOffset(DateTime.Now)
                                                           };

                            postFeed.Links.Add(SyndicationLink.CreateSelfLink(request.RequestUri));

                            SyndicationItem item = new SyndicationItem();
                            List<SyndicationItem> itemList = new List<SyndicationItem> {item};
                            postFeed.Items = itemList;

                            item.Id = post.Id;
                            item.LastUpdatedTime = post.updated;
                            item.PublishDate = post.published;
                            item.Title = new TextSyndicationContent(post.title);
                            item.Content = new TextSyndicationContent(post.content);

                            item.Links.Add(SyndicationLink.CreateSelfLink(request.RequestUri));
                            item.Links.Add(SyndicationLink.CreateAlternateLink(request.RequestUri, "text/html"));

                            item.Links.Add(new SyndicationLink(request.RequestUri, "service.edit", "Edit Post", "application/atom+xml;type=feed", 0));
                            item.Links.Add(new SyndicationLink(new Uri(String.Format("{0}/blogs/{1}/{2}/{3}", this.serviceURI, blogId, post.Id, "service.comments")), "comments", "Post comments", "application/atom+xml;type=feed", 0));
                            item.Links.Add(new SyndicationLink(new Uri(String.Format("{0}/blogs/{1}", this.serviceURI, blogId)), "service.blog", "Parent blog", "application/atom+xml;type=feed", 0));

                            item.Authors.Add(new SyndicationPerson(string.Empty, post.author, string.Empty));

                            SyndicationFeedFormatter formatter = null;

                            if (this.ClientAcceptsMediaType("application/atom+xml", request))
                            {
                                formatter = postFeed.GetAtom10Formatter();
                            }
                            else
                            {
                                if (this.ClientAcceptsMediaType("application/rss+xml", request))
                                {
                                    formatter = postFeed.GetRss20Formatter();
                                }
                            }

                            response.Content = new ObjectContent(typeof(SyndicationFeedFormatter), formatter);
                        }
                    }
                    else
                    {
                        response.StatusCode = HttpStatusCode.NotFound;
                    }
                }
            }
            catch (Exception)
            {
                response.StatusCode = HttpStatusCode.InternalServerError;
            }

            return response;
        }
开发者ID:luismdcp,项目名称:PROMPT-06-Services,代码行数:82,代码来源:RESTBlogsService.cs


注:本文中的System.ServiceModel.Syndication.SyndicationFeed.GetAtom10Formatter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。