Пример #1
0
        public SyndicationFeedFormatter GetProcesses(string format)
        {
            IEnumerable <Process> processes = new List <Process>(Process.GetProcesses());

            //SyndicationFeed also has convenience constructors
            //that take in common elements like Title and Content.
            SyndicationFeed f = new SyndicationFeed();


            f.LastUpdatedTime = DateTimeOffset.Now;
            f.Title           = SyndicationContent.CreatePlaintextContent("Currently running processes");
            f.Links.Add(SyndicationLink.CreateSelfLink(OperationContext.Current.IncomingMessageHeaders.To));

            f.Items = from p in processes
                      select new SyndicationItem()
            {
                LastUpdatedTime = DateTimeOffset.Now,
                Title           = SyndicationContent.CreatePlaintextContent(p.ProcessName),
                Summary         = SyndicationContent.CreateHtmlContent(String.Format("<b>{0}</b>", p.MainWindowTitle)),
                Content         = SyndicationContent.CreateXmlContent(new ProcessData(p))
            };


            // Choose a formatter according to the query string passed.
            if (format == "rss")
            {
                return(new Rss20FeedFormatter(f));
            }
            else
            {
                return(new Atom10FeedFormatter(f));
            }
        }
Пример #2
0
 // Creates entry from a given model
 // it assumes that the model has properties (of appropriate types) called "Id", "Title" and "LastUpdatedTime".
 SyndicationItem CreateEntryFromModel(object model)
 {
     return(new SyndicationItem()
     {
         Id = GetModelProperty(model, "Id"),
         Title = new TextSyndicationContent(GetModelProperty(model, "Title")),
         LastUpdatedTime = DateTimeOffset.Parse(
             DateTime.Now.ToString()),
         Authors = { new SyndicationPerson("") },
         Content = SyndicationContent.CreateXmlContent(model)
     });
 }
Пример #3
0
        static SyndicationItem CreateTraceSyndicationItem(XElement entry)
        {
            SyndicationItem result      = new SyndicationItem();
            XElement        traceRecord = entry.Descendants().First(e => e.Name.LocalName == "TraceRecord");

            result.Title = new TextSyndicationContent(
                traceRecord.Attributes().First(a => a.Name.LocalName == "Severity").Value + ": " +
                traceRecord.Descendants().First(e => e.Name.LocalName == "Description").Value);
            result.PublishDate     = new DateTimeOffset(long.Parse(entry.Descendants().First(e => e.Name.LocalName == "Timestamp").Value, CultureInfo.InvariantCulture), TimeSpan.Zero);
            result.LastUpdatedTime = result.PublishDate;
            result.Summary         = new TextSyndicationContent(HtmlEncode(traceRecord.ToString(), true), TextSyndicationContentKind.Html);
            result.Content         = SyndicationContent.CreateXmlContent(traceRecord);
            return(result);
        }
        public void CreateXmlContent_XmlSerializer_ReturnsExpected(XmlSerializer serializer)
        {
            XmlSyndicationContent content = SyndicationContent.CreateXmlContent(new ExtensionObject {
                Value = 10
            }, serializer);

            Assert.Empty(content.AttributeExtensions);
            Assert.Equal("text/xml", content.Type);
            Assert.Equal(10, content.Extension.GetObject <ExtensionObject>(new XmlSerializer(typeof(ExtensionObject))).Value);
            Assert.Equal(10, content.ReadContent <ExtensionObject>().Value);
            Assert.Equal(10, content.ReadContent <ExtensionObject>(new DataContractSerializer(typeof(ExtensionObject))).Value);
            Assert.Equal(10, content.ReadContent <ExtensionObject>((XmlObjectSerializer)null).Value);
            Assert.Equal(10, content.ReadContent <ExtensionObject>(new XmlSerializer(typeof(ExtensionObject))).Value);
            Assert.Equal(10, content.ReadContent <ExtensionObject>((XmlSerializer)null).Value);
        }
Пример #5
0
        private static SyndicationContent GetContent(string name, CacheItemDetail detail, CacheItemTelemetry telemetry, object value, Uri removeLink, bool expanded)
        {
            var defaultProps = new[]
            {
                new XElement("name", name),
                new XElement("type", value.GetType().ToString()),
                new XElement("remove", new XAttribute("href", removeLink))
            };

            var properties = defaultProps.Concat(GetContent(detail, telemetry)).Concat(GetContentValues(value, expanded));

            var content = new XElement("properties", properties);

            var sc = SyndicationContent.CreateXmlContent(content);

            return(sc);
        }
        public void CreateXmlContent_Reader_NoAttributes()
        {
            XmlSyndicationContent content = SyndicationContent.CreateXmlContent(
                new XElement("ParentObject",
                             new XElement("ExtensionObject",
                                          new XElement("Value", 10)
                                          )
                             ).CreateReader()
                );

            Assert.Empty(content.AttributeExtensions);
            Assert.Equal("text/xml", content.Type);
            Assert.Null(content.Extension);
            Assert.Equal(0, content.ReadContent <ExtensionObject>().Value);
            Assert.Equal(0, content.ReadContent <ExtensionObject>(new DataContractSerializer(typeof(ExtensionObject))).Value);
            Assert.Equal(0, content.ReadContent <ExtensionObject>((XmlObjectSerializer)null).Value);
            Assert.Equal(10, content.ReadContent <ExtensionObject>(new XmlSerializer(typeof(ExtensionObject))).Value);
            Assert.Equal(10, content.ReadContent <ExtensionObject>((XmlSerializer)null).Value);
        }
        public void CreateXmlContent_Reader_Attributes()
        {
            XmlSyndicationContent content = SyndicationContent.CreateXmlContent(
                new XElement("ParentObject", new XAttribute("type", "CustomType"), new XAttribute(XNamespace.Xmlns + "name", "ignored"), new XAttribute("name1", "value1"), new XAttribute(XNamespace.Get("namespace") + "name2", "value2"),
                             new XElement("ExtensionObject", new XAttribute("ignored", "value"),
                                          new XElement("Value", 10)
                                          )
                             ).CreateReader()
                );

            Assert.Equal(2, content.AttributeExtensions.Count);
            Assert.Equal("value1", content.AttributeExtensions[new XmlQualifiedName("name1")]);
            Assert.Equal("value2", content.AttributeExtensions[new XmlQualifiedName("name2", "namespace")]);
            Assert.Equal("CustomType", content.Type);
            Assert.Null(content.Extension);
            Assert.Equal(0, content.ReadContent <ExtensionObject>().Value);
            Assert.Equal(0, content.ReadContent <ExtensionObject>(new DataContractSerializer(typeof(ExtensionObject))).Value);
            Assert.Equal(0, content.ReadContent <ExtensionObject>((XmlObjectSerializer)null).Value);
            Assert.Equal(10, content.ReadContent <ExtensionObject>(new XmlSerializer(typeof(ExtensionObject))).Value);
            Assert.Equal(10, content.ReadContent <ExtensionObject>((XmlSerializer)null).Value);
        }
 public void CreateXmlContent_NullReader_ThrowsArgumentNullException()
 {
     AssertExtensions.Throws <ArgumentNullException>("reader", () => SyndicationContent.CreateXmlContent(null));
 }