Пример #1
0
        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);
     }
 }
        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());
            }
        }
        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);
            }
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
        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;
        }