Sie sind auf Seite 1von 34

Design und Realisierung

von sicheren Add-in-Modellen


Jörg Neumann
Jörg Neumann
 Principal Consultant bei Acando
 Associate bei Thinktecture
 MVP im Bereich „Client App Dev“
 Beratung, Schulung, Coaching
 Buchautor, Speaker
 Mail
– Joerg.Neumann@Acando.de
– Joerg.Neumann@thinktecture.com
 Blog
– www.HeadWriteLine.BlogSpot.com
Agenda
 Warum erweiterbare Anwendungen?
 Herausforderungen, Probleme und Lösungen
 Das Managed Add-In Framework
Warum Extensibility?
 Kapselung
– Fehler leichter finden
– Erweiterbarkeit der App gewährleisten
– Wiederverwendung von Erweiterungen
– Getrennte Entwicklung im Team
 Erweiterungen durch 3rd Parties
– Sicherheit & Stabilität sind wichtig
– Versionierung ist ein wichtiger Punkt
Begriffsdefinition
 Dependency Injection
– Contract First-Design
– Für das dynamische Nachladen von Modulen
– Einfachheit und Produktivität
– Sicherheit spielt eine untergeordnete Rolle
 Add-In
– Für die Erweiterung der Anwendung
– 3rd Party Model
– Sicherheit, Stabilität, Versionierung
Einflussfaktoren
 Discovery & Loading
 Metadaten
 Security
 Hosting
 Versionierung
 UI-Integration
Technische Hürden (1)
 Assemblies können nicht entladen werden
 Externer Code soll nicht
– die Stabilität des Hosts beeinträchtigen können
– unerlaubt auf Host, OS oder das Netzwerk
zugreifen

MyApp

Host
OS / Netzwerk…
3rd party code
Demo

Dominick Baier [www.LeastPrivilege.com] | Jörg Neumann


[www.HeadWriteLine.BlogSpot.com]
„Version 1“ Probleme
 Finden von AddIns
 Aktivieren von AddIns
 Isolation
 Sandboxing
 Lifetime Management
„Version 2“ Probleme
 Vorwärts- und Rückwärts-Kompatibilität
 Komplexität im Griff behalten
 Neue Isolations Anforderungen
System.AddIn (MAF)
 Managed Add-In Framework
 Teil von .NET 3.5
 Features
– Add-In Discovery
– Add-In Store
– Sicheres Laden/Entladen/Ausführen von Add-Ins
– Versionierung
Die Add-In Pipeline

Inherits
Add-In View Abstract Inherits Inherits Inherits Abstract
Base Class Add-In View IContract Host View Base Class

Add-In Add-In Host Host


Add-In Contract Application
Views Adapters Adapters Views

Add-In Add-In V1 to V2 V1 to V2 Host Application


V2 Views V2 Adapter Adapter Views V2 V2

Remoting-Grenze
Discovery

AddIns MyApplication.exe

AddInSideAdapters Host.Views.dll

AddInViews PipelineSegments.store

Contracts

HostSideAdapters
Hosting
 AppDomain- oder Prozess-Isolation
 Kommunikation über .NET-Remoting

Application Process Add-In Process


Default Add-In Add-In Add-In
AppDomain AppDomain AppDomain 1 AppDomain 2

Add-In 1 Add-In 2 Add-In 4 Add-In 5

Add-In 3 Add-In 6
Demo

Dominick Baier [www.LeastPrivilege.com] | Jörg Neumann


[www.HeadWriteLine.BlogSpot.com]
Nutzung in Client-Anwendungen
 Visuelle Add-Ins
– Fenster
– Eingebettete Elemente
 Problemstellungen
– UI-Elemente sind nicht serialisierbar
– Übertragung per Referenz nicht möglich
Client-Support
 Support für WPF
– Basiert auf WPF-Interop
– Visual-Objekte (und Ableitungen) können
verwendet werden
– Window Handle wird übertragen
– Läuft auch in XBAP-Anwendungen
– Kein Process-Hosting möglich
WPF-Support
 Contract
– INativeHandleContract
– Namespace: System.AddIn.Contract
– Assembly: System.Addin.Contract.dll
 Adapter
– ViewToContractAdapter
– ContractToViewAdapter
– Namespace:
System.AddIn.Pipeline.FrameworkElementAdapters
– Assembly: System.Windows.Presentation.dll
UI-Elemente übertragen

INativeHandleContract
IntPtr GetHandle();

FrameworkElementAdapters
FrameworkElement ContractToViewAdapter(INativeHandleContract hwnd);
INativeHandleContract ViewToContractAdapter(FrameworkElement root);
UI-Elemente übertragen

INativeHandleContract GetUI() FrameworkElement GetUI()


FrameworkElementAdapters. FrameworkElementAdapters.
ViewToContractAdapter() ContractToViewAdapter()

FrameworkElement INativeHandleContract FrameworkElement


GetUI() GetUI() GetUI()
Windows Forms Support

 Kein Support für Windows Forms


 Eigene Implementierung
– Übertragung von WinForms-Elementen
– Add-In-Verwaltungsdialoge
– Command-Modell für Menüs und Toolbars
– Download: http://headwriteline.blogspot.com
Windows Forms Add-In Proxy
Ressourcen
 CLR Security (CAS Helper)
http://www.codeplex.com/clrsecurity

 CLR Add-In Team Blog


http://blogs.msdn.com/clraddins

 Add-In Samples
http://www.codeplex.com/clraddins

 Windows Forms Support für MAF


http://www.HeadWriteLine.BlogSpot.com
{ In-depth support and consulting for
software architects and developers }
http://www.thinktecture.com/

joerg.neumann@thinktecture.com
www.HeadWriteLine.BlogSpot.com

35
Windows Forms Add-In Proxy
Commands
ICommand IUICommand

Name Command
ParentCommand Text
ChildCommands ParentCommand
Enabled ChildCommands
Tooltip
Visible
Checked
HasState
BeginGroup
Index
DisplayStyle
Image
CommandType
ShortcutKeys
Command Services
ICommandContext
ICommandService
UICommandService
ShowSurface()
event SurfaceShown

ICommandService IUICommandService

GetMainMenu() GetMainMenu()
GetMainToolbar() GetMainToobar()
GetCommand() GetUICommand()
CreateCommand() CreateMenuItem()
CreateToolbarItem()
CreateSeparator()
GetIconArray()
GetImageArray()
Command-Contracts

IAddInCommandContract
InitializeCommands(ICommandContext)
NotifyCommandExecuted(ICommand)
WindowProxyBase GetSurface()

IAddInContract AddInHostView : IAddInContract


InitializeCommands(ICommandContext) InitializeCommands(ICommandContext)
NotifyCommandExecuted(ICommand) NotifyCommandExecuted(ICommand)
WindowProxyBase GetSurface() WindowProxyBase GetSurface()
Components

AddInHost WindowProxyPanel

AddInPath SetWindow()
AvailableAddIns TabInto()
LoadedAddIns
CommandContext
MainMenuStrip
MainToolStrip AddInManagerForm
WindowProxyPanel
AutoSurfaceBinding AddInPath
CreateCommands() AvailableAddIns
RegisterAddIn() LoadedAddIns
UnregisterAddIn() ActivatedAddIns
DeactivateAddIn() DeactivatedAddIns
ShowAddInManager() ShowActiv.Options
GetToolItem() AddInActiv.Type
CommandExecuted AddInSecurityLevel
SurfaceShown
Kommunikation

InitializeCommands(ICommandContext)

CreateCommand(ICommand)

Add-In Host
NotifyCommandExecuted(ICommand)

ShowSurface(WindowProxy)
Contract
Assembly

Application Add-In
Assembly Add-In
Assembly
Assembly V2

Das könnte Ihnen auch gefallen