Enterprise Library Extensibility Brian Button VP of Engineering Asynchrony Solutions, Inc....
-
Upload
sherilyn-perkins -
Category
Documents
-
view
216 -
download
2
Transcript of Enterprise Library Extensibility Brian Button VP of Engineering Asynchrony Solutions, Inc....
Enterprise Library Enterprise Library ExtensibilityExtensibility
Brian ButtonBrian ButtonVP of EngineeringVP of EngineeringAsynchrony Solutions, Inc.Asynchrony Solutions, [email protected]@asolutions.comhttp://oneagilecoder.asolutions.comhttp://oneagilecoder.asolutions.com
What We Will CoverWhat We Will Cover
How the Enterprise Library Configuration How the Enterprise Library Configuration Console worksConsole works
Steps needed to create your own design time Steps needed to create your own design time experienceexperience
Session PrerequisitesSession Prerequisites
Knowledge of last web cast on building your Knowledge of last web cast on building your own Enterprise Library runtime configurationown Enterprise Library runtime configuration
Familiarity with Enterprise Library conceptsFamiliarity with Enterprise Library concepts
Level 200Level 200
AgendaAgenda
Overview of Configuration ConsoleOverview of Configuration Console
Overview of a Design TimeOverview of a Design Time
5 steps needed to implement a design time5 steps needed to implement a design time
Q&AQ&A
Final farewellFinal farewell
Overview of Configuration Overview of Configuration ConsoleConsole
UI used to create Enterprise Library config.UI used to create Enterprise Library config.
Configuration Console – contConfiguration Console – cont
Console knows nothing about blocks at Console knows nothing about blocks at startupstartup
Configuration Console – contConfiguration Console – cont
But it discovers them at runtime by looking in But it discovers them at runtime by looking in its its binbin directory directory
Configuration Console – How Configuration Console – How does it find the assemblies?does it find the assemblies?
Through reflection, all assemblies in bin Through reflection, all assemblies in bin directory are inspecteddirectory are inspected
AssemblyInfo.cs AssemblyInfo.cs ConfigurationDesignManagerAttributeConfigurationDesignManagerAttribute
Design Manager class –Design Manager class –Extends Extends ConfigurationDesignManagerConfigurationDesignManager
Matching assemblies are loaded as design Matching assemblies are loaded as design timestimes
Overview of a Design TimeOverview of a Design Time
Design-times allow usersDesign-times allow usersCreate configuration for application blocksCreate configuration for application blocks
Store configuration into XML files (or elsewhere)Store configuration into XML files (or elsewhere)
Read and modify configuration from XML filesRead and modify configuration from XML files
Sits between the Configuration Console and Sits between the Configuration Console and the Application Block Runtime Configurationthe Application Block Runtime Configuration
Like we built last time with Animal Application Like we built last time with Animal Application BlockBlock
5 steps to creating your own 5 steps to creating your own Design TimeDesign Time
Markup assembly for runtime discoveryMarkup assembly for runtime discovery
Register assembly with Config ConsoleRegister assembly with Config Console
Create visual experienceCreate visual experience
Implement configuration writingImplement configuration writing
Implement configuration readingImplement configuration reading
Marking assembly for discoveryMarking assembly for discovery
[assembly: [assembly: ConfigurationDesignManager(typeof(AnimalConfigurationDesignManager))]ConfigurationDesignManager(typeof(AnimalConfigurationDesignManager))]
AssemblyInfo.csAssemblyInfo.cs
AnimalConfigurationDesignManager.csAnimalConfigurationDesignManager.cs
public class AnimalConfigurationDesignManager : ConfigurationDesignManagerpublic class AnimalConfigurationDesignManager : ConfigurationDesignManager{{
public override void Register(IServiceProvider serviceProvider) { }public override void Register(IServiceProvider serviceProvider) { }}}
Registering assembly with Registering assembly with Configuration ConsoleConfiguration Console
Root node needs to be registered in Root node needs to be registered in AnimalConfigurationDesignManagerAnimalConfigurationDesignManager
public class AnimalCommandRegistrar : CommandRegistrarpublic class AnimalCommandRegistrar : CommandRegistrar{{
public override void Register()public override void Register(){{
ConfigurationUICommand cmdConfigurationUICommand cmd = = CConfigurationUICommand.CreateSingleUICommand(onfigurationUICommand.CreateSingleUICommand(
ServiceProvider,ServiceProvider,"Animal Application Block","Animal Application Block","Add the Animal Application Block","Add the Animal Application Block",new AddAnimalSettingsNodeCommand(ServiceProvider),new AddAnimalSettingsNodeCommand(ServiceProvider),typeof(AnimalSettingsNode));typeof(AnimalSettingsNode));
AddUICommand(cmd, typeof(ConfigurationApplicationNode));AddUICommand(cmd, typeof(ConfigurationApplicationNode));AddDefaultCommands(typeof(AnimalSettingsNode));AddDefaultCommands(typeof(AnimalSettingsNode));
}}}}
Not an interesting visual Not an interesting visual experience… yetexperience… yet
Only our root node shows up at this pointOnly our root node shows up at this point
Creating the visual experienceCreating the visual experience
Need to register nodes for all other Need to register nodes for all other configurable entities in our blockconfigurable entities in our block
Create Node class that mirrors properties from Create Node class that mirrors properties from corresponding runtime configuration classcorresponding runtime configuration class
Ex: Ex: PigData -> PigSettingsNodePigData -> PigSettingsNode
Register those nodesRegister those nodes
AddMultipleChildNodeCommand(AddMultipleChildNodeCommand( "Pig", "Add a Pig", typeof(PigSettingsNode), typeof(AnimalSettingsNode));"Pig", "Add a Pig", typeof(PigSettingsNode), typeof(AnimalSettingsNode));
Settings Node ExampleSettings Node Examplepublic class PigData : AnimalDatapublic class PigData : AnimalData{{
[ConfigurationProperty(weightProperty, IsRequired = true)][ConfigurationProperty(weightProperty, IsRequired = true)]public int Weightpublic int Weight{{
get { return (int)base[weightProperty]; }get { return (int)base[weightProperty]; }set { base[weightProperty] = value; }set { base[weightProperty] = value; }
}}}}
public class PigSettingsNode : AnimalNodepublic class PigSettingsNode : AnimalNode{{
int weight;int weight;
[Required][Required][SRCategory("CategoryGeneral", typeof(Resources))][SRCategory("CategoryGeneral", typeof(Resources))][SRDescription("PigWeightDescription", typeof(Resources))][SRDescription("PigWeightDescription", typeof(Resources))]public int Weightpublic int Weight{{
get { return weight; }get { return weight; }set { weight = value; }set { weight = value; }
}}}}
Wiring up active default Wiring up active default behaviorbehavior
AnimalSettingsNode has a AnimalSettingsNode has a DefaultAnimalNode propertyDefaultAnimalNode property
Filled in manuallyFilled in manually
When specified node deleted, this property When specified node deleted, this property should be updatedshould be updated
Implemented in active behavior region of Implemented in active behavior region of AnimalSettingsNodeAnimalSettingsNode
Implementing Configuration Implementing Configuration WritingWriting
Very easy – we already have most of it Very easy – we already have most of it writtenwritten
Actually read/write logic handled by runtime Actually read/write logic handled by runtime classesclasses
We just need to provider code that causes UI We just need to provider code that causes UI nodes to be translated to runtime nodes to be translated to runtime configuration objects.configuration objects.
System.Configuration does the rest…System.Configuration does the rest…
Implementing Configuration Implementing Configuration WritingWriting
public class AnimalSettingsBuilderpublic class AnimalSettingsBuilder{{ public AnimalSettings Build()public AnimalSettings Build() {{ animalConfiguration.DefaultAnimal = settingsNode.DefaultAnimalNode.Name;animalConfiguration.DefaultAnimal = settingsNode.DefaultAnimalNode.Name;
foreach (AnimalNode animal in hierarchy.FindNodesByType(settingsNode, foreach (AnimalNode animal in hierarchy.FindNodesByType(settingsNode, typeof(AnimalNode)))typeof(AnimalNode))) {{ animalConfiguration.AnimalProviders.Add(animal.AnimalData);animalConfiguration.AnimalProviders.Add(animal.AnimalData); }}
return animalConfiguration;return animalConfiguration; }}}}
Implementing Configuration Implementing Configuration ReadingReading
Again, very easy because most of the code is Again, very easy because most of the code is already writtenalready written
Just need to add code to translate from Just need to add code to translate from existing configuration runtime objects into UI existing configuration runtime objects into UI nodes and insert the UI nodes in correct nodes and insert the UI nodes in correct place.place.
Implementing Configuration Implementing Configuration ReadingReading
public class AnimalSettingsNodeBuilder : NodeBuilderpublic class AnimalSettingsNodeBuilder : NodeBuilder{{ public AnimalSettingsNode Build()public AnimalSettingsNode Build() {{ AnimalSettingsNode rootNode = new AnimalSettingsNode();AnimalSettingsNode rootNode = new AnimalSettingsNode();
foreach (AnimalData animal in settings.AnimalProviders)foreach (AnimalData animal in settings.AnimalProviders) {{ AnimalNode providerNode = NodeCreationService.CreateNodeByDataType(AnimalNode providerNode = NodeCreationService.CreateNodeByDataType( animal.GetType(), new object[] { animal }) as AnimalNode;animal.GetType(), new object[] { animal }) as AnimalNode; rootNode.AddNode(providerNode);rootNode.AddNode(providerNode);
if (animal.Name == settings.DefaultAnimal)if (animal.Name == settings.DefaultAnimal) rootNode.DefaultAnimalNode = providerNode;rootNode.DefaultAnimalNode = providerNode; }} return rootNode;return rootNode; }}}}
Session SummarySession Summary
First webcast described how to implement First webcast described how to implement your own runtimeyour own runtime
This webcast described how to implement a This webcast described how to implement a design timedesign time
You are now fully qualified to implement and You are now fully qualified to implement and field your own Enterprise Library application field your own Enterprise Library application block!block!
For More InformationFor More Information
Microsoft patterns and practices sitesMicrosoft patterns and practices siteshttp://www.microsoft.com/practiceshttp://www.microsoft.com/practices
http://blogs.msdn.com/tomhollhttp://blogs.msdn.com/tomholl
http://oneagilecoder.asolutions.comhttp://oneagilecoder.asolutions.com
http://practices.gotdotnet.com/entlibhttp://practices.gotdotnet.com/entlib
Final FarewellFinal Farewell
On a personal note, this is my final webcast On a personal note, this is my final webcast as a member of the p&p team. I want to thank as a member of the p&p team. I want to thank all of those with whom I have worked, all of all of those with whom I have worked, all of you who have used our software, and the you who have used our software, and the cast and crew that has enabled me to do cast and crew that has enabled me to do these wonderful webcasts. This was a great these wonderful webcasts. This was a great 2-1/2 years, and I’ll remember it always.2-1/2 years, and I’ll remember it always.
Questions and AnswersQuestions and Answers
Submit text questions using the “Ask” button. Submit text questions using the “Ask” button.
Don’t forget to fill out the survey.Don’t forget to fill out the survey.
For upcoming and previously live webcasts: For upcoming and previously live webcasts: www.microsoft.com/webcastswww.microsoft.com/webcasts
Got webcast content ideas? Contact us at: Got webcast content ideas? Contact us at: http://http://go.microsoft.com/fwlink/?LinkIdgo.microsoft.com/fwlink/?LinkId=41781=41781
Today's webcast was presented using Microsoft Today's webcast was presented using Microsoft Office Live Meeting. Get a free 14- day trial by Office Live Meeting. Get a free 14- day trial by visiting: visiting: http://www.microsoft.com/http://www.microsoft.com/presentlivepresentlive