protected override void SendToRecipients(IEnumerable<string> recipients, SyndicationFeedFormatter formatter) { proxy.ConfigureEmailSender(ConfigurationManager.AppSettings["senderEmail"], ConfigurationManager.AppSettings["senderPassword"]); proxy.SendFeedToRecipientsByEmail(recipients.ToArray(), (Rss20FeedFormatter)formatter); }
public FeedResult(SyndicationFeedFormatter feed) { if (feed == null) throw new ArgumentNullException("feed"); this.feed = feed; }
private static void DumpToConsole( SyndicationFeedFormatter formatter ) { XmlWriter writer = XmlTextWriter.Create(Console.Out, new XmlWriterSettings() { Indent = true }); formatter.WriteTo(writer); writer.Flush(); }
public void Publish(SyndicationFeedFormatter feedFormatter) { string targetFilePath = string.Format(_filePublisherSettings.OutputFilePath, DateTime.Now.ToString("yyyyMMddHHmmss")); using (var writer = XmlWriter.Create(targetFilePath)) { feedFormatter.WriteTo(writer); } }
public FeedResult(SyndicationFeedFormatter formatter, string contentType) { Ensure.Argument.NotNull(formatter, "feed"); Ensure.Argument.NotNullOrEmpty(contentType, "contentType"); Formatter = formatter; ContentType = contentType; Encoding = Encoding.UTF8; }
public void Run() { var allArticles = _feedDataClient.GetAllArticles(); _feed = _feedService.GetFeed(allArticles); _feedFormatter = CreateFeedFormatter(); _publishService.Publish(_feedFormatter); }
public FeedResult(SyndicationFeedFormatter formatter, string contentType) { if (formatter == null) { throw new ArgumentNullException("formatter"); } if (contentType == null) { throw new ArgumentNullException("contentType"); } Formatter = formatter; ContentType = contentType; Encoding = Encoding.UTF8; }
protected override void SendToRecipients(IEnumerable<string> recipients, SyndicationFeedFormatter formatter) { MailSender mailSender = new MailSender(); string message = FormMessage(formatter.Feed.Items); string subject = "You rss feeds by " + DateTime.Now; string sender = ConfigurationManager.AppSettings["senderEmail"]; string password = ConfigurationManager.AppSettings["senderPassword"]; foreach (var recipient in recipients) { try { mailSender.Send(sender, password, recipient, message, subject); } catch { } } }
public override void ExecuteResult(ControllerContext context) { if (context == null) throw new ArgumentNullException("context"); if (FeedFormat == null) FeedFormat = new Atom10FeedFormatter(); context.HttpContext.Response.ContentType = (FeedFormat.GetType() == typeof(Rss20FeedFormatter)) ? "application/rss+xml" : "application/atom+xml"; if (ContentEncoding != null) context.HttpContext.Response.ContentEncoding = ContentEncoding; using (var xmlWriter = new XmlTextWriter(context.HttpContext.Response.Output)) { xmlWriter.Formatting = Formatting.Indented; FeedFormat.WriteTo(xmlWriter); } }
public void Publish(SyndicationFeedFormatter feedFormatter) { var config = new AmazonS3Config { Timeout = TimeSpan.FromMinutes(5), ReadWriteTimeout = TimeSpan.FromMinutes(5), RegionEndpoint = RegionEndpoint.GetBySystemName(_s3PublisherSettings.Region) }; IAmazonS3 s3Client = new AmazonS3Client(_s3PublisherSettings.AccessKey, _s3PublisherSettings.SecretKey, config); var memStream = new MemoryStream(); var settings = new XmlWriterSettings(){ Encoding = Encoding.UTF8 }; using (var writer = XmlWriter.Create(memStream, settings)) { feedFormatter.WriteTo(writer); } using (var transferUtility = new TransferUtility(s3Client)) { var uploadRequest = new TransferUtilityUploadRequest() { AutoCloseStream = true, BucketName = _s3PublisherSettings.BucketName, Key = string.Format(_s3PublisherSettings.FileName, DateTime.Now.ToString("yyyyMMddHHmmss")), // Adding datetime for debugging purposess only. // In order for this to take effect change the config file to something like this // <add key="S3Publisher.FileName" value="rareburg.articles.{0}.rss" /> ContentType = string.Format("application/{0}+xml", _feedSettings.FeedFormat), CannedACL = S3CannedACL.PublicRead, InputStream = memStream }; transferUtility.Upload(uploadRequest); } }
private static Stream WriteToMemoryStream(SyndicationFeedFormatter formatter) { MemoryStream stream = new MemoryStream(); XmlWriter writer = XmlTextWriter.Create(stream, new XmlWriterSettings() { Indent = true }); formatter.WriteTo(writer); writer.Flush(); stream.Position = 0; return stream; }
private static void ReadInlineCategories(XmlReader reader, InlineCategoriesDocument inlineCategories, Uri baseUri, string version, int maxExtensionSize) { inlineCategories.BaseUri = baseUri; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs) { inlineCategories.BaseUri = FeedUtils.CombineXmlBase(inlineCategories.BaseUri, reader.Value); } else if (reader.LocalName == "lang" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs) { inlineCategories.Language = reader.Value; } else if (reader.LocalName == App10Constants.Fixed && reader.NamespaceURI == string.Empty) { inlineCategories.IsFixed = (reader.Value == "yes"); } else if (reader.LocalName == Atom10Constants.SchemeTag && reader.NamespaceURI == string.Empty) { inlineCategories.Scheme = reader.Value; } else { string ns = reader.NamespaceURI; string name = reader.LocalName; if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns)) { continue; } string val = reader.Value; if (!TryParseAttribute(name, ns, val, inlineCategories, version)) { inlineCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); } } } } SyndicationFeedFormatter.MoveToStartElement(reader); bool isEmptyElement = reader.IsEmptyElement; reader.ReadStartElement(); if (!isEmptyElement) { XmlBuffer buffer = null; XmlDictionaryWriter extWriter = null; try { while (reader.IsStartElement()) { if (reader.IsStartElement(Atom10Constants.CategoryTag, Atom10Constants.Atom10Namespace)) { SyndicationCategory category = CreateCategory(inlineCategories); Atom10FeedFormatter.ReadCategory(reader, category, version, preserveAttributeExtensions: true, preserveElementExtensions: true, maxExtensionSize); category.Scheme ??= inlineCategories.Scheme; inlineCategories.Categories.Add(category); } else if (!TryParseElement(reader, inlineCategories, version)) { SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, maxExtensionSize); } } LoadElementExtensions(buffer, extWriter, inlineCategories); } finally { extWriter?.Close(); } reader.ReadEndElement(); } }
private static void LogResponse(SyndicationFeedFormatter formatter, string contentType, Encoding contentEncoding) { if (!LogUtility.CanLog) { return; } using (var stream = new MemoryStream()) { XmlWriter writer = XmlWriter.Create(stream, new XmlWriterSettings { Indent = true }); formatter.WriteTo(writer); writer.Flush(); stream.Seek(0, SeekOrigin.Begin); var reader = new StreamReader(stream, contentEncoding); LogUtility.LogResponseBody(reader.ReadToEnd(), contentType); } }
protected static void LoadElementExtensions(XmlReader reader, SyndicationLink link, int maxExtensionSize) { SyndicationFeedFormatter.LoadElementExtensions(reader, link, maxExtensionSize); }
protected FeedResult(SyndicationFeedFormatter feedFormatter, string contentType) : base(contentType) { FeedFormatter = feedFormatter; }
protected static SyndicationCategory CreateCategory(SyndicationItem item) { return(SyndicationFeedFormatter.CreateCategory(item)); }
protected static SyndicationPerson CreatePerson(SyndicationItem item) { return(SyndicationFeedFormatter.CreatePerson(item)); }
public SyndicationActionResult(SyndicationFeedFormatter formatter) { this.formatter = formatter; }
protected static void WriteAttributeExtensions(XmlWriter writer, SyndicationCategory category, string version) { SyndicationFeedFormatter.WriteAttributeExtensions(writer, category, version); }
internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationLink link) { SyndicationFeedFormatter.LoadElementExtensions(buffer, writer, link); }
private ResourceCollectionInfo ReadCollection(XmlReader reader, Workspace workspace) { ResourceCollectionInfo result = CreateCollection(workspace); result.BaseUri = workspace.BaseUri; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs) { result.BaseUri = FeedUtils.CombineXmlBase(result.BaseUri, reader.Value); } else if (reader.LocalName == App10Constants.Href && reader.NamespaceURI == string.Empty) { result.Link = new Uri(reader.Value, UriKind.RelativeOrAbsolute); } else { string ns = reader.NamespaceURI; string name = reader.LocalName; if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns)) { continue; } string val = reader.Value; if (!TryParseAttribute(name, ns, val, result, Version)) { result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); } } } } XmlBuffer buffer = null; XmlDictionaryWriter extWriter = null; reader.ReadStartElement(); try { while (reader.IsStartElement()) { if (reader.IsStartElement(Atom10Constants.TitleTag, Atom10Constants.Atom10Namespace)) { result.Title = Atom10FeedFormatter.ReadTextContentFrom(reader, "//app:service/app:workspace/app:collection/atom:title[@type]", preserveAttributeExtensions: true); } else if (reader.IsStartElement(App10Constants.Categories, App10Constants.Namespace)) { result.Categories.Add(ReadCategories(reader, result.BaseUri, () => CreateInlineCategories(result), () => CreateReferencedCategories(result), Version, _maxExtensionSize)); } else if (reader.IsStartElement(App10Constants.Accept, App10Constants.Namespace)) { result.Accepts.Add(reader.ReadElementString()); } else if (!TryParseElement(reader, result, Version)) { SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, _maxExtensionSize); } } LoadElementExtensions(buffer, extWriter, result); } finally { extWriter?.Close(); } reader.ReadEndElement(); return(result); }
internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationCategory category) { SyndicationFeedFormatter.LoadElementExtensions(buffer, writer, category); }
internal static void CreateBufferIfRequiredAndWriteNode(ref XmlBuffer buffer, ref XmlDictionaryWriter extWriter, XmlDictionaryReader reader, int maxExtensionSize) { SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, maxExtensionSize); }
public FeedBodyWriter(SyndicationFeedFormatter formatter) : base(false) { this.formatter = formatter; }
private Workspace ReadWorkspace(XmlReader reader, ServiceDocument document) { Workspace result = CreateWorkspace(document); result.BaseUri = document.BaseUri; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs) { result.BaseUri = FeedUtils.CombineXmlBase(result.BaseUri, reader.Value); } else { string ns = reader.NamespaceURI; string name = reader.LocalName; if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns)) { continue; } string val = reader.Value; if (!TryParseAttribute(name, ns, val, result, Version)) { result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); } } } } XmlBuffer buffer = null; XmlDictionaryWriter extWriter = null; reader.ReadStartElement(); try { while (reader.IsStartElement()) { if (reader.IsStartElement(Atom10Constants.TitleTag, Atom10Constants.Atom10Namespace)) { result.Title = Atom10FeedFormatter.ReadTextContentFrom(reader, "//app:service/app:workspace/atom:title[@type]", preserveAttributeExtensions: true); } else if (reader.IsStartElement(App10Constants.Collection, App10Constants.Namespace)) { result.Collections.Add(ReadCollection(reader, result)); } else if (!TryParseElement(reader, result, Version)) { SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, _maxExtensionSize); } } LoadElementExtensions(buffer, extWriter, result); } finally { extWriter?.Close(); } reader.ReadEndElement(); return(result); }
protected static void WriteAttributeExtensions(XmlWriter writer, SyndicationLink link, string version) { SyndicationFeedFormatter.WriteAttributeExtensions(writer, link, version); }
internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationPerson person) { SyndicationFeedFormatter.LoadElementExtensions(buffer, writer, person); }
protected static void WriteAttributeExtensions(XmlWriter writer, SyndicationPerson person, string version) { SyndicationFeedFormatter.WriteAttributeExtensions(writer, person, version); }
protected static SyndicationLink CreateLink(SyndicationItem item) { return(SyndicationFeedFormatter.CreateLink(item)); }
public RssFeedResult(SyndicationFeedFormatter feed) { this.feed = feed; }
protected static void LoadElementExtensions(XmlReader reader, SyndicationCategory category, int maxExtensionSize) { SyndicationFeedFormatter.LoadElementExtensions(reader, category, maxExtensionSize); }
public FeedResult(SyndicationFeedFormatter formatter) { Formatter = formatter; ContentEncoding = Encoding.UTF8; }
private static void ReadReferencedCategories(XmlReader reader, ReferencedCategoriesDocument referencedCategories, Uri baseUri, Uri link, string version, int maxExtensionSize) { referencedCategories.BaseUri = baseUri; referencedCategories.Link = link; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs) { referencedCategories.BaseUri = FeedUtils.CombineXmlBase(referencedCategories.BaseUri, reader.Value); } else if (reader.LocalName == "lang" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs) { referencedCategories.Language = reader.Value; } else if (reader.LocalName == App10Constants.Href && reader.NamespaceURI == string.Empty) { continue; } else { string ns = reader.NamespaceURI; string name = reader.LocalName; if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns)) { continue; } string val = reader.Value; if (!TryParseAttribute(name, ns, val, referencedCategories, version)) { referencedCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); } } } } reader.MoveToElement(); bool isEmptyElement = reader.IsEmptyElement; reader.ReadStartElement(); if (!isEmptyElement) { XmlBuffer buffer = null; XmlDictionaryWriter extWriter = null; try { while (reader.IsStartElement()) { if (!TryParseElement(reader, referencedCategories, version)) { SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, maxExtensionSize); } } LoadElementExtensions(buffer, extWriter, referencedCategories); } finally { extWriter?.Close(); } reader.ReadEndElement(); } }
public void Publish(SyndicationFeedFormatter feedFormatter) { }
public FeedResult(SyndicationFeedFormatter feedFormat) { FeedFormat = feedFormat; }
public FeedResult(SyndicationFeedFormatter feed, DateTime lastModified) { this.feed = feed; this.lastModified = lastModified; }
protected abstract void SendToRecipients(IEnumerable<string> recipients, SyndicationFeedFormatter formatter);
public FeedResult(SyndicationFeedFormatter feed, string contentType) : this(feed) { ContentType = contentType; }
private static SyndicationFeed GetFeed(Stream stream, SyndicationFeedFormatter formatter) { Contract.Requires(stream != null); Contract.Requires(formatter != null); Contract.Ensures(Contract.Result<SyndicationFeed>() != null); using (stream) using (var reader = XmlReader.Create(stream)) { formatter.ReadFrom(reader); } var feed = formatter.Feed; Contract.Assume(feed != null); return feed; }
private async Task <Workspace> ReadWorkspaceAsync(XmlReader reader, ServiceDocument document) { Workspace result = CreateWorkspace(document); result.BaseUri = document.BaseUri; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs) { result.BaseUri = FeedUtils.CombineXmlBase(result.BaseUri, await reader.GetValueAsync()); } else { string ns = reader.NamespaceURI; string name = reader.LocalName; if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns)) { continue; } string val = await reader.GetValueAsync(); if (!TryParseAttribute(name, ns, val, result, Version)) { if (_preserveAttributeExtensions) { result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), val); } } } } } XmlBuffer buffer = null; XmlDictionaryWriter extWriter = null; await reader.ReadStartElementAsync(); try { while (await reader.IsStartElementAsync()) { if (await reader.IsStartElementAsync(Atom10Constants.TitleTag, Atom10Constants.Atom10Namespace)) { result.Title = await new Atom10FeedFormatter().ReadTextContentFromAsync(reader, "//app:service/app:workspace/atom:title[@type]", _preserveAttributeExtensions); } else if (await reader.IsStartElementAsync(App10Constants.Collection, App10Constants.Namespace)) { result.Collections.Add(await ReadCollectionAsync(reader, result)); } else if (!TryParseElement(reader, result, Version)) { if (_preserveElementExtensions) { var tuple = await SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNodeAsync(buffer, extWriter, reader, _maxExtensionSize); buffer = tuple.Item1; extWriter = tuple.Item2; } else { await reader.SkipAsync(); } } } LoadElementExtensions(buffer, extWriter, result); } finally { if (extWriter != null) { extWriter.Close(); } } await reader.ReadEndElementAsync(); return(result); }
protected static void WriteElementExtensions(XmlWriter writer, SyndicationItem item, string version) { SyndicationFeedFormatter.WriteElementExtensions(writer, item, version); }
private void ReadDocument(XmlReader reader) { ServiceDocument result = CreateDocumentInstance(); try { SyndicationFeedFormatter.MoveToStartElement(reader); bool elementIsEmpty = reader.IsEmptyElement; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.LocalName == "lang" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs) { result.Language = reader.Value; } else if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs) { result.BaseUri = new Uri(reader.Value, UriKind.RelativeOrAbsolute); } else { string ns = reader.NamespaceURI; string name = reader.LocalName; if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns)) { continue; } string val = reader.Value; if (!TryParseAttribute(name, ns, val, result, Version)) { result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); } } } } XmlBuffer buffer = null; XmlDictionaryWriter extWriter = null; reader.ReadStartElement(); if (!elementIsEmpty) { try { while (reader.IsStartElement()) { if (reader.IsStartElement(App10Constants.Workspace, App10Constants.Namespace)) { result.Workspaces.Add(ReadWorkspace(reader, result)); } else if (!TryParseElement(reader, result, Version)) { SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, _maxExtensionSize); } } LoadElementExtensions(buffer, extWriter, result); } finally { extWriter?.Close(); } } reader.ReadEndElement(); } catch (FormatException e) { throw new XmlException(FeedUtils.AddLineInfo(reader, SR.ErrorParsingDocument), e); } catch (ArgumentException e) { throw new XmlException(FeedUtils.AddLineInfo(reader, SR.ErrorParsingDocument), e); } SetDocument(result); }
/// <summary>Reads a SyndicationFeed object from the specified XmlReader.</summary> /// <param name='formatter'>Formatter to use when reading content.</param> /// <param name='reader'>Read to read feed from.</param> /// <returns>A new SyndicationFeed instance.</returns> private static SyndicationFeed ReadSyndicationFeed(SyndicationFeedFormatter formatter, XmlReader reader) { Debug.Assert(formatter != null, "formatter != null"); Debug.Assert(reader != null, "reader != null"); try { formatter.ReadFrom(reader); } catch (XmlException exception) { throw DataServiceException.CreateBadRequestError(Strings.Syndication_ErrorReadingFeed(exception.Message), exception); } Debug.Assert(formatter.Feed != null, "formatter.Feed != null"); return formatter.Feed; }
protected void WriteElementExtensions(XmlWriter writer, SyndicationCategory category, string version) { SyndicationFeedFormatter.WriteElementExtensions(writer, category, version); }
public FeedResult(SyndicationFeedFormatter formattedfeed) { this.formattedfeed = formattedfeed; }
protected void WriteElementExtensions(XmlWriter writer, SyndicationLink link, string version) { SyndicationFeedFormatter.WriteElementExtensions(writer, link, version); }
protected void WriteElementExtensions(XmlWriter writer, SyndicationPerson person, string version) { SyndicationFeedFormatter.WriteElementExtensions(writer, person, version); }
protected static SyndicationCategory CreateCategory(SyndicationItem item) => SyndicationFeedFormatter.CreateCategory(item);
private string ToFeedText(SyndicationFeedFormatter pFormatter) { var settings = new XmlWriterSettings { CheckCharacters = true, CloseOutput = true, ConformanceLevel = ConformanceLevel.Document, Encoding = Encoding.UTF8, Indent = true, IndentChars = " ", NamespaceHandling = NamespaceHandling.OmitDuplicates, NewLineChars = "\r\n", NewLineHandling = NewLineHandling.Replace, NewLineOnAttributes = true, OmitXmlDeclaration = false }; //var sb = new StringBuilder(); //using (var writer = XmlWriter.Create(sb, settings)) using (var stream = new MemoryStream()) using (var writer = XmlWriter.Create(stream, settings)) { pFormatter.WriteTo(writer); writer.Flush(); writer.Close(); //return sb.ToString(); return Encoding.UTF8.GetString(stream.ToArray()); } }
protected static SyndicationLink CreateLink(SyndicationItem item) => SyndicationFeedFormatter.CreateLink(item);
public FeedResult(SyndicationFeedFormatter feed) { _feed = feed; }
public FeedResult(SyndicationFeedFormatter feedForamtter) { this.FeedFormatter = feedForamtter; }