NET Event - Migrating WinForm

36
From legacy to WPF/SL Migrating applications from Windows Form to WPF/Silverlight Raffaele Garofalo

description

Raffaele will provide a gap analysis and the potential problems or advantages of moving from a Win32 technology to a vectorial technology like WPF/Silverlight. A detailed discussion and samples will be provided to address when to use WPF and when to use Silverlight.

Transcript of NET Event - Migrating WinForm

Page 1: NET Event - Migrating WinForm

From legacy to WPF/SL

Migrating applications from Windows Form to WPF/Silverlight

Raffaele Garofalo

Page 2: NET Event - Migrating WinForm

Who am I?

Raffaele GarofaloNET Software ArchitectMCP (MCAD, MCSD, MCTS)

Blog: http://blog.raffaeu.com Twitter: @raffaeu Company: Nephila Capital Ltd. (

www.nephila.com)

I am Italian, sorry for my bad English

Page 3: NET Event - Migrating WinForm

My Books

Microsoft APRESS

Page 4: NET Event - Migrating WinForm

Summary

Reasons for migrating Choose the right technology Is Windows Form dead? Choose the right architecture The team Some useful tools

Page 5: NET Event - Migrating WinForm

Reasons for migrating

Legacy application that requires refactoring (partial)

Legacy application developed with a very old technology (FoxPro, VB6, …) (re-write)

Application that requires a more complex UI (User Interface) not sustainable with Windows Form (partial)

Specific request from the Customer (at the end, he has the money …)

New project (never start a new project with an old technology!)

Page 6: NET Event - Migrating WinForm

Always consider the budget!

You do not need to re-write everything, you can keep the existing UI and migrate only the new features

Windows Form can live in parallel with WPF/SL

You can host Windows Form in WPF (WindowsFormHost) and WPF in Windows Form (ElementHost) or SL in Windows Form (embed browser)

Page 7: NET Event - Migrating WinForm

Is Windows Form dead?

No, it is not. There are still thousands of active projects done in Windows Form

Win Form is still the following step after VB6

WPF is not intended to replace Windows Forms

It is not dead but it is an old technology. It is still available

It does not separate UI from code, I can’t employ a designer for the UI

Page 8: NET Event - Migrating WinForm

Choose the right technology First rule: WPF is for Standalone, Silverlight

is for Web, Phones Second rule: WPF works only on Windows

OS, Silverlight works on Windows, MAC, Linux Third rule: WPF is a more powerful

technology, Silverlight uses a restricted version of the NET Framework but more feasible for Web and Media

WPF requires a knowledge of XAML for WPF, Silverlight requires XAML for SL, HTML and JS and WCF

Page 9: NET Event - Migrating WinForm

What can I do with?

WPF

Full .NET Framework(i.e. Split() has 6 overrides)

UI objects derives from Visual base class

Routed events, more control

Cryptography more powerful

Not a lot of choices for Media management

SILVERLIGHT

Restricted version of .NET(i.e. Split() has 3 overrides)

UI objects derives from Control

Routed events, less control

SL supports only 4 hash algorithms

Great support to Media management and streaming

Page 10: NET Event - Migrating WinForm

What Microsoft suggests? SL If you're just starting out, and there's a question as to

which technology to choose (Silverlight or WPF) then start with Silverlight. It is generally easier to move up to WPF from Silverlight than it is to move the other way. Silverlight has a smaller API, and is therefore generally considered easier to learn.

If you need a desktop application with only basic system integration, consider building a Silverlight Out-of-Browser application. Silverlight 4 Trusted Applications with IDispatch support provide access to many system resources previously unavailable to web technologies.

If you need deep system integration, excellent multi-touch support, device access, local resources, and all the other things that go with a solid desktop application, then consider moving up to WPF.

If you're a C++ developer, you can choose to go with C++ and MFC, or use C++ with WPF on the front end, like the Expression team did.

Page 11: NET Event - Migrating WinForm

Still missing …

WPF

A good designer tool, VS is not cool as Blend

The Control toolkit is not exhaustive, you still need a third party control library

SILVERLIGHT

Same thing Interaction with HTML

and Javascript still lacks in some parts

Still requires to recompile your .dlls

Page 12: NET Event - Migrating WinForm

Composite Frameworks

Create an application using Modules (independent assemblies)

Specialize teams in different areas (UI, Presentation, Business)

Reusable architecture Increase quality and usability by

sharing common services and functionality

Page 13: NET Event - Migrating WinForm

Composite for WPF/SL

PRISM

Requires observer patterns (message broker)

Cool navigation service in V4

Only IoC with Unity (Microsoft)

Astonishing resources and documentation

CALIBURN

Auto-wiring Transitions between

Views Open source with less

technology limits Available also for

Windows Phone

Page 14: NET Event - Migrating WinForm

Demo

WinForm demo application (MSDN, Telerik) WPF demo application (MSDN, Codeplex) Silverlight demo application (MSDN, Telerik)

WPF showcasehttp://windowsclient.net/community/showcase.aspx

Silverlight showcasehttp://www.silverlight.net/showcase/

Page 15: NET Event - Migrating WinForm

Choose the right architecture Layered application or monolithic block? SOA or not SOA? If I work with Silverlight

that’s the only choice … TDD or not TDD? What about an O/RM? Entity Framework,

Nhibernate or what? What about security, especially if I am

working with SL? Design patterns, is M-V-VM mandatory?

Page 16: NET Event - Migrating WinForm

Layered application, why?

Why should I use a layered application if it requires: More code More time More effort More people More money

Page 17: NET Event - Migrating WinForm

Layered application, why? The application we are designing is

complex or it will be complex in the future I need to be able to make my application

scalable, maintainable and secure I want to split the project over multiple

teams and resources I need to recycle as many code/features

as I can I need to cover with test as much surface

as I can

Page 18: NET Event - Migrating WinForm

Layered applications

Page 19: NET Event - Migrating WinForm

SOA (Service Oriented Architecture)

REAL REASONS

We need to hide the datastore and the business logic

I need to spread the business logic over different technologies (WPF, Phones, REST)

I can’t migrate everything (like AS400 …) so I need a bridge between old/new

DEVELOPER’S REASONS I need to get certified

on WCF It is cool and I am the

only one that doesn’t use it yet

I can write 10 times more code to do the same thing

Page 20: NET Event - Migrating WinForm

TDD Overview

Add a test

Run the test

Pass the test

Make a change

Fail

Fix itPass the

test

Refactot

Page 21: NET Event - Migrating WinForm

TDD Overview. A good unit test …

Run fast (they have short setups, run times, and break downs).

Run in isolation (you should be able to reorder them).

Use data that makes them easy to read and to understand.

Use real data (e.g. copies of production data) when they need to.

Represent one step towards your overall goal.

Page 22: NET Event - Migrating WinForm

TDD Pros and Cons

PROS

Indicator of project’s health

Less time to fix bugs You should write

application using functional code

Good documentation for you code by function/requirements

CONS

One change may requires more effort on fixing tests than fixing real code

Time to write tests You may not always

need to write applications using functional code

Wrong test will document wrong requirement

Page 23: NET Event - Migrating WinForm

O/RM, which one?

Nhibernate, Entity Framework are free, others are not

Nhibernate is 100% flexible but no IDE

EF has an IDE but is not flexible Nhibernate has years and is open

source EF is still not mature and it is not

open source Nhibernate requires more

experience, it is not for newbie

Page 24: NET Event - Migrating WinForm

O/RM

PROS

You are not anymore Database technology driven

Write applications faster, do not need ton of SQL

Easier to test the data layer

CONS

Less flexibility because you can’t use all the power of a specific RDBMS

Devs tend to forget T-SQL/PL-SQL

The database become a simple container of data, no more logic in it

Page 25: NET Event - Migrating WinForm

Security real facts, did you know?

Most developers have no clue about security

Most of the intranet applications are not secure at all, especially WinForm

SOA implies an additional layer of security

The database should also be encrypted

A web application with “secret” data should be always SSL

The NET framework provides tons of utilities and facilities to apply security

Page 26: NET Event - Migrating WinForm

Security concerns for my application

Authentication, how the user will authenticate against the application

Authentication with SOA Authorization, are we applying also

granular security rights? Logging, do we know what is going

on? Do we have a trace? Data protection, is security applied

also at the data tier or do we use SA in SQL?

Page 27: NET Event - Migrating WinForm

M-V-VM Overview

VIEW

VIEWMODELMODEL

Page 28: NET Event - Migrating WinForm

M-V-VM Main concepts

Provides separation of concerns

It is natural pattern for XAML platforms

Enables the developer-designer workflow

Increases application testability

Page 29: NET Event - Migrating WinForm

Resources on M-V-VM

In the Box Visual Studio integration (SEE DEMO)

My Book Gary McLean’s book PRISM documentation

http://compositewpf.codeplex.com/ Josh Smith

http://joshsmithonwpf.wordpress.com/ Karl Shifflett

http://karlshifflett.wordpress.com/

Page 30: NET Event - Migrating WinForm

The Team

How big is the team I will work with? How much experience do they have?

Guru | Some exp. | newbie What was their previous project? Do

they know the difference between Client (WPF) and Web (SL)?

Is there a technology leader in the Team with some experience?

Page 31: NET Event - Migrating WinForm

The right one

Never put too many seniors: “Too many cooks spoil the dinner”

Never use big teams, lot of technical debates and few hours on writing code

Put together devs that love the technology they are working with, negativity is a cancer

Tools make a developer life easier (documentation, books, controls, …)

Page 32: NET Event - Migrating WinForm

Make your life easier

Choose a set of Controls, learn it and use it!

Apply one pattern for the UI, learn it and use it.

Do not “experiment” with customer money, do what you know and avoid the unknown

Do not over engineer, remember that the Customer can appreciate only what he can see … (a.k.a. no NASA web services)

Small steps, small releases, small iterations

Page 33: NET Event - Migrating WinForm

Some tools

Books Guidance Best practices Forums and Communities

Page 34: NET Event - Migrating WinForm

Books

My book Architecting Applications for the Enterprise

PRISM’s Developer Guide (MS PRESS)

WPF 4 Unleashed (Adam Nathan)Silverlight 4 Unleashed (L. Bugnion)

Page 35: NET Event - Migrating WinForm

Guidance

Codeplexhttp://wpfslguidance.codeplex.com/

MSDN“Developers Guide to Microsoft PRISM”

WPFhttp://windowsclient.net

Silverlighthttp://silverlight.net

Page 36: NET Event - Migrating WinForm

QA?