Msdevcon.ru#msdevcon. Windows Phone 8 Networking Survival Kit Andy Wigley Microsoft UK.

Slides:



Advertisements
Similar presentations
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Advertisements

© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Preface Demo A Quick Thank You How Did We Do It?
Windows 8 (1) (2) (3) Windows 8 (1) (2) (3)
Building Scalable Web Apps with Windows Azure Name Title Microsoft Corporation.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
APIWP7.1WP8W8 System.Net.WebClient  System.Net.HttpWebRequest (async only) System.Net.Http.HttpClient (NuGet) Windows.Web.Syndication.SyndicationClient.
Feature: Reprint Outstanding Transactions Report © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
Feature: Purchase Requisitions - Requester © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Building Web APIs in Windows Azure Name Title Microsoft Corporation.
MIX 09 4/15/ :14 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
demo Default WANGPSLookup Default WANGPS.
Co- location Mass Market Managed Hosting ISV Hosting.
Windows 7 Training Microsoft Confidential. Windows ® 7 Compatibility Version Checking.
Multitenant Model Request/Response General Model.
30 April 2014 Building Apps for Windows Phone 8.1 Jump Start WinRT Apps & Silverlight.
Feature: Purchase Order Prepayments II © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Announcing Demo Announcing.
Feature: OLE Notes Migration Utility
Feature: Web Client Keyboard Shortcuts © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Feature: SmartList Usability Enhancements © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Session 1.
Built by Developers for Developers…. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
 Rico Mariani Architect Microsoft Corporation.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Assign an Item to Multiple Sites © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
PeerFinder.Role = PeerRole.Client; PeerFinder.Role = PeerRole.Host;
Windows 8 (1) (2) (3) Windows 8 (1) (2) (3)
WinHEC /22/2017 © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Print Remaining Documents © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
Connect with life Connect with life
Windows Azure Connect Name Title Microsoft Corporation.
NEXT: Overview – Sharing skills & code.
FonePlus Hugh Teegan Architect Mobile Devices Microsoft Corporation.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Document Attachment –Replace OLE Notes © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
Feature: Customer Combiner and Modifier © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Feature: Employee Self Service Timecard Entry © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Ian Ellison-Taylor General Manager Microsoft Corporation PC27.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
demo Instance AInstance B Read “7” Write “8”

customer.
demo © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
demo Demo.
Feature: Void Historical/Open Transaction Updates © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
WebClient client; 10 // Constructor public MainPage() { InitializeComponent(); client = new WebClient(); client.DownloadStringCompleted.
demo QueryForeign KeyInstance /sm:body()/x:Order/x:Delivery/y:TrackingId1Z
Feature: Suggested Item Enhancements – Analysis and Assignment © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and.
projekt202 © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
The CLR CoreCLRCoreCLR © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks.
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
REM function that gets called when the network changes Private Sub OnNetworkChange (ByVal s As Object, _ ByVal a As EventArgs) REM Perform detection.

IoCompleteRequest (Irp);... p = NULL; …f(p);
Возможности Excel 2010, о которых следует знать
Title of Presentation 11/22/2018 3:34 PM
Title of Presentation 12/2/2018 3:48 PM
8/04/2019 9:13 PM © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Виктор Хаджийски Катедра “Металургия на желязото и металолеене”
Title of Presentation 5/12/ :53 PM
Шитманов Дархан Қаражанұлы Тарих пәнінің
Title of Presentation 5/24/2019 1:26 PM
Title of Presentation 7/24/2019 8:53 PM
03 | Async Programming & Networking Intro
Presentation transcript:

msdevcon.ru#msdevcon

Windows Phone 8 Networking Survival Kit Andy Wigley Microsoft UK

Http Programming with async and await

APIWP7.1WP8W8 System.Net.WebClient  System.Net.HttpWebRequest System.Net.Http.HttpClient  ( NuGet) Windows.Web.Syndication.SyndicationClient  Windows.Web.AtomPub.AtomPubClient  ASMX Web Services WCF Services OData Services

using System.Net;... WebClient client; public MainPage() {... client = new WebClient(); client.DownloadStringCompleted += client_DownloadStringCompleted; } void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { this.downloadedText = e.Result; } private void loadButton_Click(object sender, RoutedEventArgs e) { client.DownloadStringAsync(new Uri(" }

using System.Net; using System.Threading.Tasks;... private async void LoadWithWebClient() { var client = new WebClient(); string response = await client.DownloadStringTaskAsync( new Uri(" this.downloadedText = response; } private async void LoadWithHttpWebRequest() { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(" request.Method = HttpMethod.Get; HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync();... }

// Following requires HttpClient.Compression NuGet package var handler = new AdvancedREI.Net.Http.Compression.CompressedHttpClientHandler(); // Create the HttpClient HttpClient httpClient = new HttpClient(handler); // To use without compression support (but why do that?), use default HttpClient constructor // without the compression handler: HttpClient httpClient = new HttpClient(); // Optionally, define HTTP headers httpClient.DefaultRequestHeaders.Add("Accept", "application/json"); // Make the call HttpResponseMessage response = await httpClient.GetAsync( " response.EnsureSuccessStatusCode(); // Throws exception if bad HTTP status code string responseBodyAsText = await response.Content.ReadAsStringAsync();

DEMO HTTP Networking using Async Andy Wigley

Make Smart Decisions About Data Transfer

12

private const int IANA_INTERFACE_TYPE_OTHER = 1; private const int IANA_INTERFACE_TYPE_ETHERNET = 6; private const int IANA_INTERFACE_TYPE_PPP = 23; private const int IANA_INTERFACE_TYPE_WIFI = 71;... string network = string.Empty; // Get current Internet Connection Profile. ConnectionProfile internetConnectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile(); if (internetConnectionProfile != null) // if ‘null’, we are offline. { switch (internetConnectionProfile.NetworkAdapter.IanaInterfaceType) { case IANA_INTERFACE_TYPE_OTHER: cost += "Network: Other"; break; case IANA_INTERFACE_TYPE_ETHERNET: cost += "Network: Ethernet"; break; case IANA_INTERFACE_TYPE_WIFI: cost += "Network: Wifi\r\n"; break; default: cost += "Network: Unknown\r\n"; break; } }

DEMO Wire Serialization Andy Wigley

Wire Serialization FormatSize in Bytes ODATA XML73786 ODATA JSON ATOM34030 JSON ‘Lite’15540 JSON ‘Lite’ GZip8680

Implementing Compression

var request = HttpWebRequest.Create(" as HttpWebRequest; request.Accept = "application/json"; request.Method = HttpMethod.Get; request.Headers["Accept-Encoding"] = "gzip"; HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync(); // Read the response into a Stream object. System.IO.Stream responseStream = response.GetResponseStream(); string data; var stream = new GZipInputStream(response.GetResponseStream()); using (var reader = new System.IO.StreamReader(stream)) { data = reader.ReadToEnd(); } responseStream.Close();

private void EnableGZipResponses(DataServiceContext ctx) { ctx.WritingRequest += new EventHandler ( (_, args) => { args.Headers["Accept-Encoding"] = "gzip"; } ); ctx.ReadingResponse += new EventHandler ( (_, args) => { if (args.Headers.ContainsKey("Content-Encoding") && args.Headers["Content-Encoding"].Contains("gzip")) { args.Content = new GZipStream(args.Content); } } ); } Reference:

DEMO Compression Andy Wigley

Store Files in SkyDrive

DEMO Store Files in SkyDrive Andy Wigley

Accessing Local Services from the Emulator

DEMO Accessing local services from the emulator Andy Wigley

Bluetooth

try { PeerFinder.AlternateIdentities["Bluetooth:Paired"] = ""; var peers = await PeerFinder.FindAllPeersAsync(); } catch (Exception ex) { if ((uint)ex.HResult == 0x F) MessageBox.Show("Bluetooth is switched off"); }

// Register for incoming connection requests PeerFinder.ConnectionRequested += PeerFinder_ConnectionRequested; // Start advertising ourselves so that our peers can find us PeerFinder.DisplayName = "TicTacToe BT"; PeerFinder.Start();

// Register for incoming connection requests PeerFinder.ConnectionRequested += PeerFinder_ConnectionRequested; // Start advertising ourselves so that our peers can find us PeerFinder.DisplayName = "TicTacToe BT"; PeerFinder.Start();

StreamSocket socket; async void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args) { if ( args.PeerInformation.DisplayName == "RobsPhone" ) { socket = await PeerFinder.ConnectAsync(args.PeerInformation); PeerFinder.Stop(); }

DEMO Bluetooth communication Andy Wigley

NFC

ProximityDevice device = ProximityDevice.GetDefault(); // Make sure NFC is supported if (device != null) { PeerFinder.TriggeredConnectionStateChanged += OnTriggeredConnectionStateChanged; // Start finding peer apps, while making this app discoverable by peers PeerFinder.Start(); }

ProximityDevice device = ProximityDevice.GetDefault(); // Make sure NFC is supported if (device != null) { PeerFinder.TriggeredConnectionStateChanged += OnTriggeredConnStateChanged; // Include the Windows 8 version of our app as possible peer PeerFinder.AlternateIdentities.Add("Windows", "my Win8 appID"); // Start finding peer apps, while making this app discoverable by peers PeerFinder.Start(); }

void OnTriggeredConnStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args) { switch (args.State) { case TriggeredConnectState.Listening: // Connecting as host break; case TriggeredConnectState.PeerFound: // Proximity gesture is complete – setting up link break; case TriggeredConnectState.Connecting: // Connecting as a client break; case TriggeredConnectState.Completed: // Connection completed, get the socket streamSocket = args.Socket; break; case TriggeredConnectState.Canceled: // ongoing connection cancelled break; case TriggeredConnectState.Failed: // Connection was unsuccessful break; }

PeerFinder.AllowBluetooth = true; PeerFinder.AllowInfrastructure = true;

DEMO NFC ‘Tap to Connect’ and ‘Tap to Share’ Andy Wigley

Windows.Networking.Proximity.ProximityDevice proximityDevice; long publishedMessageId = -1; private void PublishUriButton_Click(object sender, RoutedEventArgs e) { if (proximityDevice == null) proximityDevice = ProximityDevice.GetDefault(); // Make sure NFC is supported if (proximityDevice != null) { // Stop publishing the current message. if (publishedMessageId != -1) { proximityDevice.StopPublishingMessage(publishedMessageId); } // Publish the new one publishedMessageId = proximityDevice.PublishUriMessage( new Uri("zune:navigate?appid=351decc7-ea2f-e c-00237de2db9e")); }

Контакты Andy Wigley Microsoft & andywigley.com

© 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.