offline network detection in microsoft silverlight 3

24
Offline Detection in SL 3 and .NET Framework Peter Smith Program Manager, .NET Networking Microsoft Corporation

Upload: goodfriday

Post on 08-Jun-2015

464 views

Category:

Business


1 download

DESCRIPTION

Come hear how to structure Silverlight applications to support a sometimes connected scenario, and learn how to avoid the common pitfalls of implementing network detection.

TRANSCRIPT

Page 1: Offline Network Detection in Microsoft Silverlight 3

Offline Detection in SL 3 and .NET Framework

Peter SmithProgram Manager, .NET NetworkingMicrosoft Corporation

Page 2: Offline Network Detection in Microsoft Silverlight 3

Why Offline Detection?

Silverlight now has the ability to run from the user’s desktop, just like a normal application

Sometimes when your code runs, the user will not be online

You have to detect and handle this case

Page 3: Offline Network Detection in Microsoft Silverlight 3

The One Take-Away Point

How do you know if you are online?

1. Can you connect to your server?2. Have you validated the response?

Microsoft can help by telling you when to try again

Page 4: Offline Network Detection in Microsoft Silverlight 3

Demonstration

A very simple Silverlight 3 application that does network detection

demo

Page 5: Offline Network Detection in Microsoft Silverlight 3

Why Offline is So Hard

Is the network useful? Driver issuesVirtual PCs!Coffee shop problemMaybe you shouldn’t connect!

Page 6: Offline Network Detection in Microsoft Silverlight 3

The One Take-Away Point

How do you know if you are online?

1. Can you connect to your server?2. Have you validated the response?

Microsoft can help by telling you when to try again

Page 7: Offline Network Detection in Microsoft Silverlight 3

VB.NET Sample

REM function that gets called when the network changesPrivate Sub OnNetworkChange (ByVal s As Object, _ ByVal a As EventArgs)

REM Perform detection hereEnd Sub

REM set up the system to call that functionPublic Sub New() AddHandler NetworkInformation. _ NetworkChange.NetworkAddressChanged, _ AddressOf OnNetworkChangeEnd Sub

Page 8: Offline Network Detection in Microsoft Silverlight 3

C# Sample

private void OnNetworkChange (Object sender, EventArgs Args){ // Put network detection here}

public MainPage(){ NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler (OnNetworkChange);}

Page 9: Offline Network Detection in Microsoft Silverlight 3

Patterns For Your Code

Ask the user

Before you connect, validate

Constantly validate results

Page 10: Offline Network Detection in Microsoft Silverlight 3

Ask the User

Add two buttons to your application

One is “retry” and tries to connect again

The other is “offline mode” and prevents the application from even trying

Page 11: Offline Network Detection in Microsoft Silverlight 3

Before You Connect, Validate

Put a standard file on your serverDownload and check contentsNo server==really offlineRevalidate on network change

Got a file from your server, but it’s not yours? You might be have the “coffee shop” problem and must retry

Page 12: Offline Network Detection in Microsoft Silverlight 3

Constantly Check Results

Check all downloadsNot just status code!No server==really offlineRevalidate on network change

Got a file from your server, but it’s not yours? You might be have the “coffee shop” problem and must retry

Page 13: Offline Network Detection in Microsoft Silverlight 3

The One Take-Away Point

How do you know if you are online?

1. Can you connect to your server?2. Have you validated the response?

Microsoft can help by telling you when to try again

Page 14: Offline Network Detection in Microsoft Silverlight 3

Thank you!

Questions?

My email is [email protected]

NCL (System.Net) blog is http://blogs.msdn.com/ncl/

The team forum is http://social.msdn.microsoft.com/Forums/en-US/ncl/threads/

Page 15: Offline Network Detection in Microsoft Silverlight 3

Please Complete an Evaluation FormYour feedback is important!

Evaluation forms can be found on each chairTemp Staff at the back of the room have additional evaluation form copies

Page 16: Offline Network Detection in Microsoft Silverlight 3

© 2009 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.

Page 17: Offline Network Detection in Microsoft Silverlight 3

Extra Slides!

These slides go into more detail about the advantages and disadvantages of the different code patterns for network detection

Page 18: Offline Network Detection in Microsoft Silverlight 3

Advantages of Ask the User

The user might know that they’ve done something special (but undetectable) to go on lineThe user might also know that it’s a bad time to go online

Page 19: Offline Network Detection in Microsoft Silverlight 3

Disadvantages to Ask the User

The user might not know that they’ve gone online (and get it wrong)They also probably think it’s your job normally

Page 20: Offline Network Detection in Microsoft Silverlight 3

Advantages of the Before Pattern

It’s simpleYou only have to understand one file (and you can just make it XML)

Page 21: Offline Network Detection in Microsoft Silverlight 3

Disadvantages of "Before"

It’s not always possible to drop a file on your company serverIt has an extra bit of work at startupSometimes the network changes, but you don’t detect it in time (and ruin a downloaded file)

Page 22: Offline Network Detection in Microsoft Silverlight 3

Advantages of Constantly Check

Starts up faster – no extra file to downloadRequires no changes to your server

Page 23: Offline Network Detection in Microsoft Silverlight 3

Disadvantages to Constantly Check

Checking is hard! You have to understand all of the different file types that your application might haveChecking is “noisy”: there are lots of reasons why your server might not have given a good reply

Page 24: Offline Network Detection in Microsoft Silverlight 3