本文整理匯總了C#中System.ServiceModel.Syndication.Atom10FeedFormatter.WriteTo方法的典型用法代碼示例。如果您正苦於以下問題:C# Atom10FeedFormatter.WriteTo方法的具體用法?C# Atom10FeedFormatter.WriteTo怎麽用?C# Atom10FeedFormatter.WriteTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.ServiceModel.Syndication.Atom10FeedFormatter
的用法示例。
在下文中一共展示了Atom10FeedFormatter.WriteTo方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ContentType = "application/atom+xml";
var formatter = new Atom10FeedFormatter(Feed);
using (XmlWriter writer = XmlWriter.Create(context.HttpContext.Response.Output))
formatter.WriteTo(writer);
}
示例2: fload
public void fload(string namefile)
{
var lines = System.IO.File.ReadAllLines(namefile);
feed.Title = new TextSyndicationContent(lines[1]);
feed.Copyright = new TextSyndicationContent(lines[2]);
feed.Description = new TextSyndicationContent(lines[3]);
feed.Generator = lines[4];
SyndicationLink link = new SyndicationLink();
link.Uri = new Uri(lines[5]);
feed.Links.Add(link);
feed.Items = txtgotolv("feedinfo.txt");
Response.Clear();
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "text/xml";
XmlWriter Writer = XmlWriter.Create
(Response.Output);
if (lines[0] == "rss")
{
Rss20FeedFormatter Formatter = new Rss20FeedFormatter(feed);
Formatter.WriteTo(Writer);
}
else
{
if (lines[0] == "atom")
{
Atom10FeedFormatter Formatter = new Atom10FeedFormatter(feed);
Formatter.WriteTo(Writer);
}
}
Writer.Close();
Response.End();
}
示例3: Build
public string Build(FeedData dataFeed, Uri baseUri)
{
var feed = new SyndicationFeed
{
Id = dataFeed.Id.ToString(),
LastUpdatedTime = dataFeed.DateCreated,
Items = dataFeed.Messages.Select(x => new SyndicationItem
{
Content = new RawSyndicationContent(x.Body),
Id = x.Id.ToString(),
LastUpdatedTime = x.CreatedAt
})
};
if (!string.IsNullOrEmpty(dataFeed.NextUri))
feed.Links.Add(new SyndicationLink(new Uri(baseUri, dataFeed.NextUri), NextInArchiveRelationshipType,
"Next In Archive", ContentType, 0));
if (!string.IsNullOrEmpty(dataFeed.PreviousUri))
feed.Links.Add(new SyndicationLink(new Uri(baseUri, dataFeed.PreviousUri), PrevInArchiveRelationshipType,
"Previous In Archive", ContentType, 0));
var formatter = new Atom10FeedFormatter(feed);
var sw = new StringWriter();
using (var writer = XmlWriter.Create(sw))
{
formatter.WriteTo(writer);
}
return sw.ToString();
}
示例4: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ContentType = "application/atom+xml";
//check request is for Atom or RSS
if (context.HttpContext.Request.QueryString["type"] != null && context.HttpContext.Request.QueryString["type"].ToString().ToLower() == "atom")
{
//Atom Feed
context.HttpContext.Response.ContentType = "application/atom+xml";
var rssFormatter = new Atom10FeedFormatter(FeedData);
using (XmlWriter writer = XmlWriter.Create(context.HttpContext.Response.Output, new XmlWriterSettings { Indent = true }))
{
rssFormatter.WriteTo(writer);
}
}
else
{
//RSS Feed
context.HttpContext.Response.ContentType = "application/rss+xml";
var rssFormatter = new Rss20FeedFormatter(FeedData);
using (XmlWriter writer = XmlWriter.Create(context.HttpContext.Response.Output, new XmlWriterSettings { Indent = true }))
{
rssFormatter.WriteTo(writer);
}
}
}
示例5: WriteFile
//var formatter = new Rss20FeedFormatter(feed);
// Atom10FeedFormatter formatter = new Atom10FeedFormatter(feed);
//using (var writer = XmlWriter.Create(response.Output, new XmlWriterSettings { Indent = true }))
//{
// formatter.WriteTo(writer);
//}
protected override void WriteFile(HttpResponseBase response)
{
Atom10FeedFormatter formatter = new Atom10FeedFormatter(_feed);
using (XmlWriter writer = XmlWriter.Create(response.OutputStream, new XmlWriterSettings { Indent = true }))
{
formatter.WriteTo(writer);
}
}
示例6: GetXmlContents
private static Action<Stream> GetXmlContents(SyndicationFeed feed)
{
return stream =>
{
var writer = new XmlTextWriter(stream, Encoding.UTF8);
var atomFormatter = new Atom10FeedFormatter(feed);
atomFormatter.WriteTo(writer);
};
}
示例7: OnWriteToStream
public override void OnWriteToStream(Type type, object value, Stream stream, HttpContentHeaders contentHeaders, TransportContext context)
{
var formatter = new Atom10FeedFormatter((SyndicationFeed) value);
using (var xmlWriter = XmlWriter.Create(stream))
{
formatter.WriteTo(xmlWriter);
xmlWriter.Close();
}
}
示例8: CreateContentFromAtom10SyndicationFeed
public static StreamContent CreateContentFromAtom10SyndicationFeed(SyndicationFeed feed)
{
SyndicationFeedFormatter formatter = new Atom10FeedFormatter<SyndicationFeed>(feed);
var memoryStream = new MemoryStream();
var settings = new XmlWriterSettings { Encoding = Encoding.UTF8, ConformanceLevel = ConformanceLevel.Document, Indent = true };
using (var xmlWriter = XmlWriter.Create(memoryStream, settings))
{
formatter.WriteTo(xmlWriter);
xmlWriter.Flush();
xmlWriter.Close();
}
memoryStream.Seek(0, SeekOrigin.Begin);
return new StreamContent(memoryStream);
}
示例9: WriteFile
protected override void WriteFile(HttpResponseBase response)
{
_isRssFeed = _feedType == FeedType.Rss;
// Creates Xml file.
string xmlFile = HttpContext.Current.Server.MapPath("~/feed.xml");
using (var fileStream = new FileStream(xmlFile, FileMode.Create))
{
using (var streamWriter = new StreamWriter(fileStream, Encoding.UTF8))
{
var xs = new XmlWriterSettings { Indent = true };
using (var xmlWriter = XmlWriter.Create(streamWriter, xs))
{
xmlWriter.WriteStartDocument();
if (_isCssStyles)
{
const string strPi = "type='text/css' href='/Contents/Styles/feedStyle.css'";
// Write processor information
xmlWriter.WriteProcessingInstruction("xml-stylesheet", strPi);
}
if (_isRssFeed)
{
// RSS 2.0
var rssFormatter = new Rss20FeedFormatter(_feed, true);
rssFormatter.WriteTo(xmlWriter);
}
else
{
// Atom 1.0
var atomFormatter = new Atom10FeedFormatter(_feed);
atomFormatter.WriteTo(xmlWriter);
}
}
}
}
//Display Xml file in browser.
response.Clear();
response.Buffer = true;
response.Charset = "";
response.Cache.SetCacheability(HttpCacheability.NoCache);
response.ContentType = "text/xml";
response.WriteFile(HttpContext.Current.Server.MapPath("~/feed.xml"));
response.Flush();
response.End();
}
示例10: ExecuteResult
/// <summary>
/// Executes the call to the ActionResult method and returns the created feed to the output response.
/// </summary>
/// <param name="context">The context in which the result is executed. The context information includes the
/// controller, HTTP content, request context, and route data.</param>
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ContentType = ContentType.Atom;
var feedFormatter = new Atom10FeedFormatter(this._syndicationFeed);
var xmlWriterSettings = new XmlWriterSettings {Encoding = Encoding.UTF8};
if (HttpContext.Current.IsDebuggingEnabled)
{
// Indent the XML for easier viewing but only in Debug mode. In Release mode, everything is output on
// one line for best performance.
xmlWriterSettings.Indent = true;
}
using (var xmlWriter = XmlWriter.Create(context.HttpContext.Response.Output, xmlWriterSettings))
{
feedFormatter.WriteTo(xmlWriter);
}
}
示例11: WriteFile
protected override void WriteFile(HttpResponseBase response)
{
_isRssFeed = _feedType == FeedType.Rss;
// Creates Xml file.
string xmlFile = HttpContext.Current.Server.MapPath("~/feed.xml");
using (var fileStream = new FileStream(xmlFile, FileMode.Create))
{
using (var streamWriter = new StreamWriter(fileStream, Encoding.UTF8))
{
var xs = new XmlWriterSettings { Indent = true };
using (var xmlWriter = XmlWriter.Create(streamWriter, xs))
{
xmlWriter.WriteStartDocument();
if (_isRssFeed)
{
// RSS 2.0
var rssFormatter = new Rss20FeedFormatter(_feed);
rssFormatter.WriteTo(xmlWriter);
}
else
{
// Atom 1.0
var atomFormatter = new Atom10FeedFormatter(_feed);
atomFormatter.WriteTo(xmlWriter);
}
}
}
}
XslTransform myXslTransform = new XslTransform();
myXslTransform.Load(HttpContext.Current.Server.MapPath("~/feed.xslt"));
myXslTransform.Transform(HttpContext.Current.Server.MapPath("~/feed.xml"), HttpContext.Current.Server.MapPath("~/newFeed.xml"));
//Display Xml file in browser.
response.Clear();
response.Buffer = true;
response.Charset = "";
response.Cache.SetCacheability(HttpCacheability.NoCache);
response.ContentType = "application/xml";
response.WriteFile(HttpContext.Current.Server.MapPath("~/newFeed.xml"));
response.Flush();
response.End();
}
示例12: ExecuteResult
/// <summary>
/// Executes the call to the ActionResult method and returns the created feed to the output response.
/// </summary>
/// <param name="context">The context in which the result is executed. The context information includes the
/// controller, HTTP content, request context, and route data.</param>
public override void ExecuteResult(ActionContext context)
{
context.HttpContext.Response.ContentType = ContentType.Atom;
Atom10FeedFormatter feedFormatter = new Atom10FeedFormatter(this.syndicationFeed);
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
xmlWriterSettings.Encoding = Encoding.UTF8;
if (Context.Environment.IsDevelopment())
{
// Indent the XML for easier viewing but only in Debug mode. In Release mode, everything is output on
// one line for best performance.
xmlWriterSettings.Indent = true;
}
using (XmlWriter xmlWriter = XmlWriter.Create(context.HttpContext.Response.Body, xmlWriterSettings))
{
feedFormatter.WriteTo(xmlWriter);
}
}
示例13: Index
public ActionResult Index()
{
var syndicationItems =
this.DB.Themes.Select(ToSyndicationItem)
.Concat(this.DB.Votes.Include("Theme").Select(ToSyndicationItem))
.OrderByDescending(s => s.LastUpdatedTime);
var feed = new SyndicationFeed(_Localize.SiteTitle, "", this.GetAppUrl(), syndicationItems.ToArray());
var formatter = new Atom10FeedFormatter(feed);
return new LamdaResult(context =>
{
var response = context.HttpContext.Response;
response.ContentType = "application/xml";
var xmlWriter = XmlWriter.Create(response.OutputStream);
formatter.WriteTo(xmlWriter);
xmlWriter.Flush();
});
}
示例14: try_it_out
public void try_it_out()
{
var doc = new XmlDocument().WithRoot("root").WithAtt("a", "1");
var feed = new SyndicationFeed("some feed", "cool feed", new Uri("http://elsewere.com"));
var item = new SyndicationItem("the title", "some content", new Uri("http://somewhere.com"));
item.ElementExtensions.Add(doc);
feed.Items = new SyndicationItem[]{item};
var builder = new StringBuilder();
var writer = XmlWriter.Create(builder);
var formatter = new Atom10FeedFormatter(feed);
formatter.WriteTo(writer);
writer.Close();
Debug.WriteLine(builder);
}
示例15: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
_isRssFeed = _feedType == FeedType.Rss;
context.HttpContext.Response.ContentType = _isRssFeed
? "application/rss+xml"
: "application/atom+xml";
var writerSettings = new XmlWriterSettings { Indent = true };
using (var feedWriter = XmlWriter.Create(context.HttpContext.Response.OutputStream, writerSettings))
{
if (_isRssFeed)
{
// RSS 2.0
var rssFormatter = new Rss20FeedFormatter(_feed);
rssFormatter.WriteTo(feedWriter);
}
else
{
var atomFormatter = new Atom10FeedFormatter(_feed);
atomFormatter.WriteTo(feedWriter);
}
}
}