Introduced
Re-imagine the Windows 8 Store Apps Communication
Get Network Information
Serialization-JSON
Serialization-XML
Serialization-RSS Atom
Example
1, demonstrate how to obtain information about the network
Communication/networkinfo.xaml.cs
* * Demonstrates how to obtain information about the network * * using System;
Using System.Collections.Generic;
Using Windows.Networking.Connectivity;
Using Windows.UI.Xaml.Controls;
Using Windows.UI.Xaml.Navigation;
Using System.Linq;
Namespace Xamldemo.communication {public sealed partial class Networkinfo:page {public Networkinfo () {this.
InitializeComponent (); } protected override void Onnavigatedto (NavigationEventArgs e) {/* * networ Kinformation-for access to network information//Get the Connectionprofile object connect currently for Internet connection
Ionprofile connectionprofile = Networkinformation.getinternetconnectionprofile ();
if (connectionprofile = null) return;
The name of this connection configuration Lblmsg.text = "ProfileName:" + connectionprofile.profilename;
Lblmsg.text + = Environment.NewLine; The network connection level for this connection (WINDOWS.NETWORKING.CONNECTIVITY.NEtworkconnectivitylevel enum)//None-no connection//localaccess-only allow access to local network/Co Nstrainedinternetaccess-Restricted Internet access//internetaccess-local and Internet access Lblmsg.text + = "
Networkconnectivitylevel: "+ connectionprofile.getnetworkconnectivitylevel ();
Lblmsg.text + = Environment.NewLine;
The event that triggers when the network state changes networkinformation.networkstatuschanged + = networkinformation_networkstatuschanged;
NetworkAdapter NetworkAdapter = Connectionprofile.networkadapter; if (NetworkAdapter!= null) {Lblmsg.text + = "NetworkAdapterID:" + networkadapter.networkadap Terid;
Network adapter ID Lblmsg.text + = Environment.NewLine; Lblmsg.text + = "Inboundmaxbitspersecond:" + networkadapter.inboundmaxbitspersecond;
Maximum inbound data transfer rate (unit: bit/s) Lblmsg.text + = Environment.NewLine; Lblmsg.text + = "Outboundmaxbitspersecond: "+ networkadapter.outboundmaxbitspersecond;
Maximum outbound data transfer rate (unit: bit/s) Lblmsg.text + = Environment.NewLine; Lblmsg.text + = "Networktypes:" + networkAdapter.NetworkItem.GetNetworkTypes ();
Network type Lblmsg.text + = Environment.NewLine;
} Lblmsg.text + = Environment.NewLine; Get all available connections ireadonlylist<connectionprofile> connectionprofiles = Networkinformation.getconnectionprofil
ES (); foreach (Connectionprofile cp in connectionprofiles) {Lblmsg.text = "ProfileName:" + CP.
ProfileName;
Lblmsg.text + = Environment.NewLine; Gets the usage of local data within a specified time period for this connection datausage datausage = cp.
Getlocalusage (DateTime.Now.AddHours ( -1), DateTime.Now); Lblmsg.text + = "BytesSent:" + datausage.bytessent;
Number of bytes sent lblmsg.text + = Environment.NewLine; Lblmsg.text + = "bytesreceived:" + datausage.bytesreceived;
Number of bytes received lblmsg.text + = Environment.NewLine;
//Below are some things that are not commonly used connectioncost connectioncost = Connectionprofile.getconnectioncost ();
Dataplanstatus dataplanstatus = Connectionprofile.getdataplanstatus ();
Networksecuritysettings networksecuritysettings = connectionprofile.networksecuritysettings;
ireadonlylist<lanidentifier> lanidentifiers = Networkinformation.getlanidentifiers (); } void Networkinformation_networkstatuschanged (object sender) {}}}
Entity classes for demonstrating serialization and deserialization
Communication/serializer/product.cs
* * * To demonstrate the serialization and deserialization of the entity class * * * when serialized and deserialized through DataContractJsonSerializer or DataContractSerializer, it supports DataContract, Datam
Ember, Knowntype * Of course if all do not declare DataContract, DataMember also no problem * * using System;
Using System.Collections.Generic;
Using System.Runtime.Serialization; namespace XamlDemo.Communication.Serializer {[DataContract (name= "Product")] public class Product {[D
Atamember (Name = "ProductId", IsRequired = true, order = 1)] public int productId {get; set;}
[DataMember (name = "Name", IsRequired = true, order = 2)] public string Name {get; set;}
Public decimal price {get; set;}
[DataMember (Name = "Createtime", IsRequired = true, order = 3)] public DateTime createtime {get; set;} public static list<product> GetProducts () {list<product> products = new List<prod
Uct> ();
for (int i = 0; i < 5; i++) { Products. ADD (new Product {ProductId = i, name = "Name:" + i.tostring ().
PadLeft (4, ' 0 '), Price = i *, Createtime = DateTime.Now.AddDays (-i)
});
return to Products; }
}
}