Silverlight 1 September 2007 Silverlight 2 October 2008 Silverlight 1 September 2007.
Silverlight 2 for Developers - TechEd New Zealand 2008
-
Upload
jonas-folleso -
Category
Technology
-
view
4.769 -
download
0
description
Transcript of Silverlight 2 for Developers - TechEd New Zealand 2008
![Page 1: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/1.jpg)
![Page 2: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/2.jpg)
2
Silverlight 2 for Developers
Jonas FollesøSenior ConsultantCapgemini
Session Code: WEB304
![Page 3: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/3.jpg)
3
![Page 4: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/4.jpg)
4
Agenda
Blend 2.5CRUDDesignersPatternsTestingQ&A
![Page 5: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/5.jpg)
5
Dive Log App
![Page 6: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/6.jpg)
6
Outside data
PublicPublicInternetInternetmashup APIsmashup APIs
ExistingExistingIntranetIntranetservicesservices
New servicesNew servicesyou buildyou build
RSS/AtomRSS/AtomFeedsFeeds
ImagesImagesSoundsSoundsVideosVideos
![Page 7: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/7.jpg)
7
A bit of history: Silverlight 1
PublicPublicInternetInternetmashup APIsmashup APIs
ExistingExistingIntranetIntranetservicesservices
New servicesNew servicesyou buildyou build
RSS/AtomRSS/AtomFeedsFeeds
ImagesImagesSoundsSoundsVideosVideos
JavaScript
HTML
?AJAX (XmlHttpRequest)
1.0<XAML/>
![Page 8: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/8.jpg)
8
Today: Silverlight 2
2
Managed Code (C#/VB)
PublicPublicIntInteernetrnetmashup APIsmashup APIs
ExistingExistingIntrIntraanetnetservicesservices
New servicesNew servicesyou buildyou build
RSS/AtomRSS/AtomFeedsFeeds
ImagesImagesSoundsSoundsVideosVideos
HTML
![Page 9: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/9.jpg)
9
Services that describe themselves
SOAPSOAPservices in the services in the enterpriseenterprise
Services for Services for your Silverlightyour Silverlightprojectproject
ADO.NET ADO.NET Data ServicesData Services
SOAP SOAP servicesserviceson the Interneton the Internet
Computer-ReadableMetadata
(e.g. WSDL)
AutomaticProxy
Generation
WCF
![Page 10: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/10.jpg)
10
Securing Silverlight ServicesSilverlight will use auth. info in the browser
HTML
E.g.: ASP.NET Login
User:Password:
DiveLog.comDiveLog.com…/Login.aspx…/Login.aspx../MyApp.aspx../MyApp.aspx../MyService.svc../MyService.svc
Credentials
Auth info (e.g. cookie)
Service calls + Auth info
Silverlight code does not normallydeal with credentials…
![Page 11: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/11.jpg)
11
HTTP Requests in Silverlight
HttpWebRequestHttpWebRequest
High-level components and User CodeHigh-level components and User Code
Browser Plugin APIsBrowser Plugin APIs
Web Browser- Cookies- Authenticated sessions- Caching- Proxy server to use
Web Browser- Cookies- Authenticated sessions- Caching- Proxy server to use
Windows/MacNetworking LayerWindows/MacNetworking Layer
Restrictions
Restrictions
![Page 12: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/12.jpg)
12
Blend – The dark is not that scary…
![Page 13: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/13.jpg)
13
Dive Log UI and Data
![Page 14: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/14.jpg)
14
Everything in code behind…is probably not a good idea
![Page 15: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/15.jpg)
15
A team of sad coders and designers
![Page 16: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/16.jpg)
![Page 17: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/17.jpg)
17
Different people reading about MVC in different places take different ideas from it and describe these as “MVC”.
Martin Fowler, GUI Architectures Essay
![Page 18: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/18.jpg)
18Separated Presentation Patterns
![Page 19: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/19.jpg)
19
Data & Domain Data & Domain LogicLogic(Model)(Model)
UIUI(View)(View)
Interaction Interaction (Controller/Presenter)(Controller/Presenter)
![Page 20: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/20.jpg)
20
Represent the state and behavior of the presentation independently of the GUI controls used in the interface.
Martin Fowler, Presentation Model Essay
![Page 21: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/21.jpg)
21
Makes your app easier to design…makes the designers like you
![Page 22: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/22.jpg)
22
Everything in code-behind
Data ModelData Model
ViewView
XAMLXAML
Code-BehindCode-BehindEvent HandlersEvent Handlers
![Page 23: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/23.jpg)
23
Presentation Model
Data ModelData Model
ViewView
XAMLXAML
Code-BehindCode-Behind
Presentation ModelPresentation Model
State + State + OperationsOperations
Change notification
Data-binding and commands
![Page 24: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/24.jpg)
24
Dive Log Presentation Model
Dive Log ServiceDive Log Service
Dive LogDive Log
XAMLXAML
Code-BehindCode-Behind
Dive Log View Dive Log View ModelModelState + State +
OperationsOperations
Change notification
Data-binding and commands
![Page 25: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/25.jpg)
25
Data BindingImplement INotifyPropertyChanged and use ObservableCollection<T> for collections
ViewView <ListBox ItemsSource="{Binding Path=Dives}" SelectedItem="{Binding Path=SelectedDive, Mode=TwoWay}" />
Presentation ModelPresentation Model
State + OperationsState + Operations
![Page 26: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/26.jpg)
26
Data BindingImplement INotifyPropertyChanged and use ObservableCollection<T> for collections
ViewView
XAML
Code-BehindCode-Behind
Presentation ModelPresentation Modelpublic class PageViewModel : INotifyPropertyChanged{ public event PropertyChangedEventHandler PropertyChanged; public ObservableCollection<Dive> Dives { ... } public Dive SelectedDive { ... }}
![Page 27: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/27.jpg)
27
IValueConverter
Converts data bound valuesE.g. Bind temperature to color
public object Convert(object, value, Type targetType, object parameter, CultureInfo culture){ int temp = System.Convert.ToInt32(value); Color color = Colors.Black; if(temp < 5) color = Colors.Blue; else if(temp < 20) color = Colors.Yellow; else color = Colors.Red;
return new SolidColorBrush(color);}
ViewView<UserControl.Resources> <demo:ColorConverter x:Key="colorConverter" /></UserControl.Resources>
<TextBox Text="{Binding Temperature, Mode=TwoWay}" Background="{Binding Temperature, Converter={StaticResource colorConverter}}"/>
![Page 28: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/28.jpg)
28
Building a Presentation Model
![Page 29: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/29.jpg)
29
User Interaction
But what about Word?
ViewViewprivate void btnSave_Clicked(object sender, ExecutedEventArgs e){ ((PageViewModel)DataContext).Save();}
![Page 30: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/30.jpg)
30
Objects are used to represent actions. A command object encapsulates an action and its parameters.
This allows a decoupling of the invoker of the command and the handlers of the command.
![Page 31: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/31.jpg)
31
Commands in SilverlightViewView
<Button Content="Save Dives" input:CommandService.Command="SaveDives" />
Presentation ModelPresentation Modelpublic PageViewModel(){ Commands.SaveDives.Executed += new EventHandler<ExecutedEventArgs>(SaveDives);}
private void SaveDives(object sender, ExecutedEventArgs e){ // code to save dives..}
![Page 32: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/32.jpg)
32
The strategy pattern is a software design pattern, whereby algorithms can be selected at runtime.
Presentation ModelPresentation Modelpublic PageViewModel(){ if(HtmlPage.IsEnabled) { client = new DiveLogServiceClient(); } else { client = new ServiceStub(); }}
![Page 33: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/33.jpg)
33
![Page 34: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/34.jpg)
34
![Page 35: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/35.jpg)
35
Dealing with dependencies
The Presentation Model is coupled with both the stub service and the real service.
Makes code less flexible for changeMakes code harder to test
Object should not be responsible for creating their own dependencies – Inversion of Control
![Page 36: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/36.jpg)
36
Dependency Injection (DI)
One form of Inversion of Control (IoC) Create dependencies outside the object and, inject them into it
But who creates the dependency?
Presentation ModelPresentation Modelpublic PageViewModel(IDiveLogServiceClient proxy){ this.proxy = proxy}
![Page 37: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/37.jpg)
37
Dependency Injection by hand
Should the page be responsible for creating dependencies?
ViewViewpublic Page(){ InitializeComponent(); if (HtmlPage.IsEnabled) this.DataContext = new PageViewModel(new DiveLogServiceClient()); else this.DataContext = new PageViewModel(new ServiceStub());}
![Page 38: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/38.jpg)
38
IoC Containers
Presentation ModelPresentation Model[Inject]public PageViewModel(IDiveLogServiceClient proxy){ this.proxy = proxy}
ViewViewpublic Page(){ InitializeComponent(); IKernel iocContainer = new StandardKernel(); this.DataContext = iocContainer.Get<PageViewModel>();}
![Page 39: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/39.jpg)
39
IoC ContainersWhat about design time support in Blend?
ViewView<UserControl.DataContext> <dive:PageViewModel /></UserControl.DataContext>
Need to find a way to use IoC and set DataContext declaratively…
![Page 40: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/40.jpg)
40
Using DI on the ViewModel
![Page 41: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/41.jpg)
41
Testing is important!
![Page 42: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/42.jpg)
42
Testing Silverlight Code
The standard solutions do not applyThe Silverlight CLR is a subsetAll networking is asynchronous
But it’s still familiar…[TestClass], [TestMethod], [Asynchronous]
![Page 43: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/43.jpg)
43
Asynchronous TestsHow do we “wait” before doing assertions?
![Page 44: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/44.jpg)
44
Unit Testing in Silverlight
![Page 45: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/45.jpg)
45
![Page 46: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/46.jpg)
46
Resources
www.microsoft.com/teched Tech·Talks Tech·Ed BloggersLive Simulcasts Virtual Labs
http://microsoft.com/technet
Evaluation licenses, pre-released products, and MORE!
http://microsoft.com/msdn
Developer’s Kit, Licenses, and MORE!
![Page 47: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/47.jpg)
Related Content
Code and lots of good resources on http://jonas.follesoe.noCode and lots of good resources on http://jonas.follesoe.no
WEB311 Designing Compelling Silverlight User Experiences with Expression Studio 2WEB311 Designing Compelling Silverlight User Experiences with Expression Studio 2Wednesday, 3-9-2008 14:20 - 15:35, NZ Room 4, SkyCityWednesday, 3-9-2008 14:20 - 15:35, NZ Room 4, SkyCity
Hands-on Labs (session codes and titles)Hands-on Labs (session codes and titles)
![Page 48: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/48.jpg)
Track ResourcesWEB311 Designing Compelling Silverlight User Experiences with Expression Studio 2WEB311 Designing Compelling Silverlight User Experiences with Expression Studio 2Wednesday, 3-9-2008 14:20 - 15:35, NZ Room 4, SkyCityWednesday, 3-9-2008 14:20 - 15:35, NZ Room 4, SkyCity
![Page 49: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/49.jpg)
49
Please Please complete ancomplete anevaluationevaluation
![Page 50: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/50.jpg)
50
© 2008 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 51: Silverlight 2 for Developers - TechEd New Zealand 2008](https://reader035.fdocuments.net/reader035/viewer/2022062615/54848003b4af9f290e8b473d/html5/thumbnails/51.jpg)
51
Photo Copyright Notices
All diving photos taken by Hege Røkenes and licensed under the creative commons license. http://flickr.com/photos/hegerokenes/
Photos of Martin Fowler taken by Dave Thomas and licensed under the creative commons license.http://flickr.com/photos/pragdave/