Presentation is loading. Please wait.

Presentation is loading. Please wait.

Enterprise Library Extensibility Brian Button VP of Engineering Asynchrony Solutions, Inc.

Similar presentations


Presentation on theme: "Enterprise Library Extensibility Brian Button VP of Engineering Asynchrony Solutions, Inc."— Presentation transcript:

1 Enterprise Library Extensibility Brian Button VP of Engineering Asynchrony Solutions, Inc. brian.button@asolutions.com http://oneagilecoder.asolutions.com

2 What We Will Cover How the Enterprise Library Configuration Console works Steps needed to create your own design time experience

3 Session Prerequisites Knowledge of last web cast on building your own Enterprise Library runtime configuration Familiarity with Enterprise Library concepts Level 200

4 Agenda Overview of Configuration Console Overview of a Design Time 5 steps needed to implement a design time Q&A Final farewell

5 Overview of Configuration Console UI used to create Enterprise Library config.

6 Configuration Console – cont Console knows nothing about blocks at startup

7 Configuration Console – cont But it discovers them at runtime by looking in its bin directory

8 Configuration Console – How does it find the assemblies? Through reflection, all assemblies in bin directory are inspected AssemblyInfo.csConfigurationDesignManagerAttribute Design Manager class – Extends ConfigurationDesignManager Matching assemblies are loaded as design times

9 Overview of a Design Time Design-times allow users Create configuration for application blocks Store configuration into XML files (or elsewhere) Read and modify configuration from XML files Sits between the Configuration Console and the Application Block Runtime Configuration Like we built last time with Animal Application Block

10 5 steps to creating your own Design Time Markup assembly for runtime discovery Register assembly with Config Console Create visual experience Implement configuration writing Implement configuration reading

11 Marking assembly for discovery [assembly: ConfigurationDesignManager(typeof(AnimalConfigurationDesignManager))] AssemblyInfo.csAnimalConfigurationDesignManager.cs public class AnimalConfigurationDesignManager : ConfigurationDesignManager { public override void Register(IServiceProvider serviceProvider) { } }

12 Registering assembly with Configuration Console Root node needs to be registered in AnimalConfigurationDesignManager public class AnimalCommandRegistrar : CommandRegistrar { public override void Register() { ConfigurationUICommand cmd = ConfigurationUICommand.CreateSingleUICommand( ServiceProvider, "Animal Application Block", "Add the Animal Application Block", new AddAnimalSettingsNodeCommand(ServiceProvider), typeof(AnimalSettingsNode)); AddUICommand(cmd, typeof(ConfigurationApplicationNode)); AddDefaultCommands(typeof(AnimalSettingsNode)); }}

13 Not an interesting visual experience… yet Only our root node shows up at this point

14 Creating the visual experience Need to register nodes for all other configurable entities in our block Create Node class that mirrors properties from corresponding runtime configuration class Ex: PigData -> PigSettingsNode Register those nodes AddMultipleChildNodeCommand( "Pig", "Add a Pig", typeof(PigSettingsNode), typeof(AnimalSettingsNode)); "Pig", "Add a Pig", typeof(PigSettingsNode), typeof(AnimalSettingsNode));

15 Settings Node Example public class PigData : AnimalData { [ConfigurationProperty(weightProperty, IsRequired = true)] public int Weight { get { return (int)base[weightProperty]; } set { base[weightProperty] = value; } }} public class PigSettingsNode : AnimalNode { int weight; [Required] [SRCategory("CategoryGeneral", typeof(Resources))] [SRDescription("PigWeightDescription", typeof(Resources))] public int Weight { get { return weight; } set { weight = value; } }}

16 Wiring up active default behavior AnimalSettingsNode has a DefaultAnimalNode property Filled in manually When specified node deleted, this property should be updated Implemented in active behavior region of AnimalSettingsNode

17 Implementing Configuration Writing Very easy – we already have most of it written Actually read/write logic handled by runtime classes We just need to provider code that causes UI nodes to be translated to runtime configuration objects. System.Configuration does the rest…

18 Implementing Configuration Writing public 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, typeof(AnimalNode))) foreach (AnimalNode animal in hierarchy.FindNodesByType(settingsNode, typeof(AnimalNode))) { animalConfiguration.AnimalProviders.Add(animal.AnimalData); animalConfiguration.AnimalProviders.Add(animal.AnimalData); } return animalConfiguration; return animalConfiguration; }}

19 Implementing Configuration Reading Again, very easy because most of the code is already written Just need to add code to translate from existing configuration runtime objects into UI nodes and insert the UI nodes in correct place.

20 Implementing Configuration Reading public 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( animal.GetType(), new object[] { animal }) as AnimalNode; AnimalNode providerNode = NodeCreationService.CreateNodeByDataType( 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; }}

21 Session Summary First webcast described how to implement your own runtime This webcast described how to implement a design time You are now fully qualified to implement and field your own Enterprise Library application block!

22 For More Information Microsoft patterns and practices sites http://www.microsoft.com/practices http://blogs.msdn.com/tomholl http://oneagilecoder.asolutions.com http://practices.gotdotnet.com/entlib

23 Final Farewell On a personal note, this is my final webcast as a member of the p&p team. I want to thank all of those with whom I have worked, all of you who have used our software, and the cast and crew that has enabled me to do these wonderful webcasts. This was a great 2-1/2 years, and I’ll remember it always.

24 Questions and Answers Submit text questions using the “Ask” button. Don’t forget to fill out the survey. For upcoming and previously live webcasts: www.microsoft.com/webcasts www.microsoft.com/webcasts Got webcast content ideas? Contact us at: http://go.microsoft.com/fwlink/?LinkId=41781 http://go.microsoft.com/fwlink/?LinkId=41781 Today's webcast was presented using Microsoft Office Live Meeting. Get a free 14- day trial by visiting: http://www.microsoft.com/presentlive Today's webcast was presented using Microsoft Office Live Meeting. Get a free 14- day trial by visiting: http://www.microsoft.com/presentlive http://www.microsoft.com/presentlive

25


Download ppt "Enterprise Library Extensibility Brian Button VP of Engineering Asynchrony Solutions, Inc."

Similar presentations


Ads by Google