public void Ctor_Type_SyndicationElementExtension_XmlObjectSerializer(string type, XmlObjectSerializer dataContractSerializer) { var content = new XmlSyndicationContent(type, new ExtensionObject { Value = 10 }, dataContractSerializer); Assert.Empty(content.AttributeExtensions); Assert.Equal(string.IsNullOrEmpty(type) ? "text/xml" : type, 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); }
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); }
public static List <Telemetry> GetTelemetryData(TelemetryInputs inputs) { string uri = @"https://management.core.windows.net/{subscriptionId}/services/ServiceBus/namespaces/{namespaceName}/NotificationHubs/{hubName}/metrics/{metricName}/rollups/{metricRollup}/Values?$filter={filterExpression}"; uri = uri.Replace("{subscriptionId}", inputs.SubscriptionId); uri = uri.Replace("{namespaceName}", inputs.NamespaceName); uri = uri.Replace("{hubName}", inputs.NotificationHubName); uri = uri.Replace("{metricName}", inputs.MetricName); uri = uri.Replace("{metricRollup}", inputs.Rollup.ToString()); string strFromDate = String.Format("{0:s}", inputs.FromDate); string strToDate = String.Format("{0:s}", inputs.ToDate); // See - http://msdn.microsoft.com/library/azure/dn163590.aspx for details string filterExpression = String.Format ("Timestamp%20gt%20datetime'{0}Z'%20and%20Timestamp%20lt%20datetime'{1}Z'", strFromDate, strToDate); uri = uri.Replace("{filterExpression}", filterExpression); X509Certificate2 certificate = new X509Certificate2(inputs.PathToCert, inputs.CertPassword); HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(uri); sendNotificationRequest.Method = "GET"; sendNotificationRequest.ContentType = "application/xml"; sendNotificationRequest.Headers.Add("x-ms-version", "2011-02-25"); sendNotificationRequest.ClientCertificates.Add(certificate); List <Telemetry> data = new List <Telemetry>(); try { HttpWebResponse response = (HttpWebResponse)sendNotificationRequest.GetResponse(); using (XmlReader reader = XmlReader.Create(response.GetResponseStream(), new XmlReaderSettings { CloseInput = true })) { SyndicationFeed feed = SyndicationFeed.Load <SyndicationFeed>(reader); foreach (SyndicationItem item in feed.Items) { XmlSyndicationContent syndicationContent = item.Content as XmlSyndicationContent; MetricValue value = syndicationContent.ReadContent <MetricValue>(); data.Add(new Telemetry(value.Timestamp, value.Total)); Console.WriteLine("Timestamp: {0} -> Total: {1}", value.Timestamp, value.Total); } } } catch (WebException exception) { string error = new StreamReader(exception.Response.GetResponseStream()).ReadToEnd(); Console.WriteLine(error); } return(data); }
public void Ctor_Reader_NoAttributes() { var content = new XmlSyndicationContent( 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 T DeserializeResourceDescription <T>(string resourceDescription) { DataContractSerializer serializer = new DataContractSerializer(typeof(T)); Atom10ItemFormatter formater = new Atom10ItemFormatter(); formater.ReadFrom(new XmlTextReader(new StringReader(resourceDescription))); XmlSyndicationContent content = formater.Item.Content as XmlSyndicationContent; return(content.ReadContent <T>(serializer)); }
public void Ctor_Reader_Attributes() { var content = new XmlSyndicationContent( 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); }
static void Main(string[] args) { //Expand this region to see the code for hosting a Syndication Feed. #region Service WebServiceHost host = new WebServiceHost(typeof(ProcessService), new Uri("http://localhost:8000/diagnostics")); //The WebServiceHost will automatically provide a default endpoint at the base address //using the proper binding (the WebHttpBinding) and endpoint behavior (the WebHttpBehavior) host.Open(); Console.WriteLine("Service host open"); //The syndication feeds exposed by the service are available //at the following URI (for Atom use feed/?format=atom) // http://localhost:8000/diagnostics/feed/?format=rss //These feeds can be viewed directly in an RSS-aware client //such as IE7. #endregion //Expand this region to see the code for accessing a Syndication Feed. #region Client // Change the value of the feed query string to 'atom' to use Atom format. XmlReader reader = XmlReader.Create("http://localhost:8000/diagnostics/feed?format=rss", new XmlReaderSettings() { //MaxCharactersInDocument can be used to control the maximum amount of data //read from the reader and helps prevent OutOfMemoryException MaxCharactersInDocument = 1024 * 64 }); SyndicationFeed feed = SyndicationFeed.Load(reader); foreach (SyndicationItem i in feed.Items) { XmlSyndicationContent content = i.Content as XmlSyndicationContent; ProcessData pd = content.ReadContent <ProcessData>(); Console.WriteLine(i.Title.Text); Console.WriteLine(pd.ToString()); } #endregion //Press any key to end the program. Console.ReadLine(); }