smart client development

37
Tamir Khason http://khason.net Feb’ 09 Sponsored by:

Upload: tamir-khason

Post on 22-Jun-2015

4.770 views

Category:

Technology


3 download

DESCRIPTION

Those days, when it seemed, that web applications have overthrown standard “cumbersome” client apps, we’ll speak about present and future of consumer oriented desktop applications. This includes, but not restricted to patterns of LOB applications development with WPF, right multimedia support of DirectX bridge and new features, waiting for you in Windows 7. Also we’ll speak about subject oriented programming, will be introduced in NET. 4.0 and how to leverage it even today with the current version of Microsoft framework. tits will be shown during the session, thus restricted to mature audiences

TRANSCRIPT

Page 1: Smart Client Development

Tamir Khason

http://khason.net

Feb’ 09

Sponsored by:

Page 2: Smart Client Development

This is not a lesson

You should attend

Page 3: Smart Client Development

What is “good application”?

Page 4: Smart Client Development

Architecture…

Page 5: Smart Client Development

… but what about me?

… and Nick has also a lot of letters for this machine

This is Nick

Page 6: Smart Client Development

Smart Client Application should be

Simple

Useful

Deployable

Maintainable

Extensible

ACCEPTABLE

Page 7: Smart Client Development
Page 8: Smart Client Development

What is “Smart Client”?

My presentation July 2002 My presentation Feb’ 2009

WinForms User Interface

Deployed via central server

Uses local resources

Uses server based data and

processing

Works better connected

Works offline

Client User Interface

Zero footprint deployment

Users local resource

Synchronizes and distributes

data and processes

Smart sensitive to local

environment

Minimum dependencies

Page 9: Smart Client Development
Page 10: Smart Client Development

The Process

Page 11: Smart Client Development

Planning

Focus on FEATURES Focus on SCENARIOS

Stability

Incremental

improvement

Most probably “End-

to-End” scenarios will

not work

Excitement

Breakthroughs

Most probably will

leave existing

customers behind

Page 12: Smart Client Development

Architectural review

We need componentization

But it cumbersome

There is a ton of dependencies

Page 13: Smart Client Development

Dependencies management Types in a same component can depend one on each other

Cross-component dependencies must be controlled

Can be depend on component in lower layer

Must not be hard depend on component in higher layer

Must avoid to be soft depend on component in higher layer

Need someone else to manage dependencies on the same

layer

Less dependencies – better!

Also less assemblies – better!

… in general – less is better – simpler is better!

Page 14: Smart Client Development

10 Design dogmas

Component oriented Primitive Oriented

Rich APIs with lots of

features – ton of

dependencies

Great usability, poor

evolvability

Easy type discovery, but

need reflection

Good for higher level

components - not for the

core

No external dependencies

Great evolvability, often

very poor usability

Incoherent type discovery,

but not required reflection

Good for low level stable

framework

Page 15: Smart Client Development

Extensibility Framework? There is no “Official” extensibility framework, so you

can…

Create from scratch

Buy/use something good…

Wait for .NET 4.0

Use MEF - Managed Extensibility Framework + WPF today

Catalog

Value Resolver

Composition container

Part

Export Import

Part

Export Import

Part

Export Import

Page 16: Smart Client Development

How it works?Who has service

I need?

I have!

[Import]

public IEnumerable<IYourService>

YourServices { get; set; }

[Export(typeof(IYourService)]

public class SomeService : IYourService

Page 17: Smart Client Development

Who is who and what can it do?

Parts relate through contracts

Imports are contracts parts need

Exports are contracts parts offer

The Container is matchmaker

It queues catalogs

Parts can load lazily

Parts can have different lifetimes

Parts are extensible and reusable

Page 18: Smart Client Development

Contracts Preconditions, rather then endless try-catch blocks

Postconditions, rather then endless if-else blocks

The best about this is Static Analysis!

Assumption.SetPolicy(AssumptionPolicy.Break, new AssumptionHelper());…public NotNullSet(HashSet<T> set) Assumption.NotNull(set);…Assumption.IsTrue(typeof(T1) != typeof(T2), "The two types of values in a mapping cannot be the same type.");

Page 19: Smart Client Development

But what’s with “Compatibility”?Cross-Version Compatibility

Cross-Redistribution Compatibility

Backward Compatibility

Forward Compatibility

Binary Compatibility

Source Compatibility

API Compatibility

Page 20: Smart Client Development

Primitives and extensibility? APIs are published as interfaces into a

“programmability” assembly

Embed interfaces at compile time

Can be deployed to any version of the managed

application

We can “cast” one interface into other in runtime

– loose type coupling

We can add some aspects and logic in compile

time with custom compilers

In .NET 4.0 only!

By now – you can use PostSharp

Page 21: Smart Client Development

Generic co- and contravariance It’s scary, but simple

We can cast to ancestor types

But it not always works

So should we be able to pass Ixxx<TDerived> for

Ixxx<TBase>?

private void WriteSomething(object[] something) { }…var something = new string[] { "It's something" };WriteSomething(something);

private void WriteSomething(IEnumerable<object> something) { }…var something = new List<string> { "It's something" };WriteSomething(something); // Compiler says “NO”!

Page 22: Smart Client Development

Generic co- and contravariance If T is an output → IX<TDerived> for IX<T>

It’s covariance

…and can be used as IX<out T>

If T is an input → IX<TBase> for IX<T>

It’s contravariance

…and can be used as IX <in T>private void DoSomething(Func<object, IValueConverter> something) {

this.Converter = something(this.Whatever); // Oh, NOT!!!}

…var something = new Func<string, IValueConverter> { };DoSomething(something);

Page 23: Smart Client Development

AOP – WTF? You have INotifyPropertyChanged primitive

For each setter of each descendant you need to call

virtual method OnPropertyChanged

Rather then use automatic setters

public class MyPrimitive : INotifyPropertyChanged {public event PropertyChangedEventHandler PropertyChanged;protected virtual void OnPropertyChanged(string name) {

if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(name));

public class MyClass : MyPrimitive {private int _myProperty;public int MyProperty { get { return _myProperty; }

set { if (_myProperty != value) { _myProperty = value;OnPropertyChanged("MyProperty");

public int MyProperty { get; set; }

Page 24: Smart Client Development

AOP – WTF? The best is to create your own compilation rule…

… or even some dynamic primitives…

… but it only possible in .NET 4.0

Meanwhile, you can use PostSharp and

OnMethodBoundaryAspect primitive to tell compiler

what to do

All the rest will be done automagically

internal class SetterWrapper : OnMethodBoundaryAspect {public override void OnEntry(MethodExecutionEventArgs eventArgs) {var myPrimitive = eventArgs.Instance as MyPrimitive ;_propertyInfo = myPrimitive.Class.GetProperty(_propertyName);eventArgs.MethodExecutionTag = myPrimitive.OnBeforePropertyChange(_propertyInfo, newValue, oldValue);eventArgs.FlowBehavior = FlowBehavior.Return;

Page 25: Smart Client Development

Side by Side .NET 1.x and 2.x CLR - Side by Side on the same

machine

Good for programs

Bad for add-ins

Breaks on 3.x “red bits”

.NET 4.x CLR – Side by Side in process with 2.x CLR

Each module runs again its expected version of CLR

Can be done today by some unmanaged injections

Page 26: Smart Client Development

The Concept

Page 27: Smart Client Development

Real life software

Increase staff during peek

hours or replace staff on trouble

Perform Specialised tasks

Can process more than one

request at a time

Page 28: Smart Client Development

Real life software

Processor

Storages

Queues

WorkerDispatcher

Async Process

Page 29: Smart Client Development

Need a change of thinkingTo throw out

Local states

Client locks, transactions and scopes

Fault tolerance

To bring aboard

Asynchronous operations

Simplicity

Self descriptive behaviors and components

Page 30: Smart Client Development

Local resources? Windows Sensor and Location platform

Basically the better way to access well-known device types

Build context aware applications

Can be used today by wrapping HID_* methods

Microsoft Sync Framework

You can synchronize your application or device and provide

it offline capabilities

Build “sometimes connected” applications

“DirectHardware” is your friend and savior

DirectX helps you to leverage client’s hardware

It also can varnish a bit your app

Page 31: Smart Client Development

WPF – Huh?

Page 32: Smart Client Development

Architecture (should)= Simplicity

Page 33: Smart Client Development

Are you familiar

with WPF?

Page 34: Smart Client Development

We already have a lot of stuff We have trees in WPF

Logical tree – is what you put in XAML

Visual tree – the what WPF renders for us

Inheritance – frozen hybrid of two above

We have Context

All Data Context inherited via trees

Resources inherited via Logical tree

Routed events and commands can be used through Visual tree

Data Templates = Views

Page 35: Smart Client Development

2 conclude Think as consumer, not as developer

DO design APIs by using it (writing code)

Keep It Simple, Stupid!

Set goals, gates and make an order

Avoid integrating unfinished features (yes, even if it is

very cool feature)

Main

Staging branch

Feature branch

Feature branch

Staging branch

Staging branch

Page 36: Smart Client Development

2 Read My Blog

http://khason.net

Windows Client Developmenthttp://windowsclient.net

Windows Presentation Foundation (Toolkit, Futures, Ribbon, Labs, M-V-VM)http://codeplex.com/wpf

Managed Extensibility Framework (MEF)http://codeplex.com/mef

PostSharp + Aspect-Oriented Programming.NEThttp://postsharp.org

Microsoft WHDC site (Sensors)http://microsoft.com/whdc/sensors

Microsoft Sync Frameworkhttp://msdn.microsoft.com/en-us/sync

Page 37: Smart Client Development

Thank youQuestions?… and I do not need “Potential – Passion” slide anymore…

[email protected]

http://khason.net