smart client development
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 audiencesTRANSCRIPT
What is “good application”?
Architecture…
… but what about me?
… and Nick has also a lot of letters for this machine
This is Nick
Smart Client Application should be
Simple
Useful
Deployable
Maintainable
Extensible
ACCEPTABLE
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
The Process
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
Architectural review
We need componentization
But it cumbersome
There is a ton of dependencies
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!
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
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
How it works?Who has service
I need?
I have!
[Import]
public IEnumerable<IYourService>
YourServices { get; set; }
[Export(typeof(IYourService)]
public class SomeService : IYourService
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
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.");
But what’s with “Compatibility”?Cross-Version Compatibility
Cross-Redistribution Compatibility
Backward Compatibility
Forward Compatibility
Binary Compatibility
Source Compatibility
API Compatibility
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
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”!
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);
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; }
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;
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
The Concept
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
Real life software
Processor
Storages
Queues
WorkerDispatcher
Async Process
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
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
WPF – Huh?
Architecture (should)= Simplicity
Are you familiar
with WPF?
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
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
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
Thank youQuestions?… and I do not need “Potential – Passion” slide anymore…
http://khason.net