As I mentioned last time, this subject of this post will be wiring up all the Modeling Services “architectural plumbing” to enable the Contoso business rule repository to enjoy all the goodness that Modeling Services has to offer.
In the current Modeling Services CTP the Repository is implemented as a sophisticated SQL Server database. As one would expect, wiring up the Modeling Services architectural plumbing consists of leveraging/altering a number of database objects (e.g., stored procedures, tables, views, etc) within the Repository. As Modeling Services is built on the SQL Server platform, all of this wiring can be accomplished using T-SQL. However, in this post we will leverage a handy add-on to Modeling Services that greatly reduces the learning curve involved with wiring up a custom model in the Repository – the PatternApplication Sample.
PatternApplication Setup
The bits for the PatternApplication Sample are available here. MSDN provides great instructions on how to install the PatternApplication Sample, so I won’t waste space repeating them here.
The sample code used in this series will assume that both the PatternApplication.dll and PatternApplication.mx files are located at the Modeling Services default install location of “C:\Program Files\Microsoft Oslo\1.0\bin\”. If the sample code is used as-is, then these files will need to be copied/moved to this location.
For the remainder of this series I we will be assuming that Visual Studio 2010 Beta 2 is development environment for the Contoso business rule repository, although Intellipad could also be used as well.
<Author’s Note>For the sake of brevity, I will assume that the reader is quite familiar using Visual Studio. As such, I will not be providing detailed step-by-step instructions for the VS activities.</Author’s Note>
Here are the basic steps for setting up the VS project:
Pattern Declarations
The PatternApplication Sample provides a declarative method for wiring up Modeling Services architectural plumbing to a model using ‘M’ code. The ‘M’ code provides metadata regarding what exactly needs to be wired for the model and this metadata is subsequently leveraged by a PatternApplication stored procedure to perform the wiring. A new ‘M’ file will be needed in the project to declare this metadata:
As the structures that define the wiring metadata are declared in the PatternApplication module, and this metadata will be declared for the structures in the RuleModel module, the following ‘M’ code is the first to be added to the PatternApplication.m file:
1: module PatternApplication
2: {
3: import RulesModel;
4: }
Next, metadata is declared regarding the RulesModel module:
4:
5: ModulePatternApplications
6: {
7: RulesModel_Pattern
8: {
9: Module => about(RulesModel.RulesTable).Declaration.DefinedIn,
10: Pattern => { Patterns.AlterSchemaPermissions}
11: }
12: }
13: }
The metadata above declares that the SQL Server RulesModel schema, which will be created based on the ‘M’ RulesModel module, should have its SQL Server permissions altered in accordance with Modeling Services patterns. This ensures that the RulesModel schema will adhere to the Modeling Services Security architecture.
Once metadata is declared for the RulesModel module, declarations are added for the Operator extent:
10: Pattern => {Patterns.AlterSchemaPermissions}
13:
14: EntityPatternApplications
15: {
16: Operator_Pattern
17: {
18: Module => about(RulesModel.OperatorsTable).Declaration.DefinedIn,
19: Extent => about(RulesModel.OperatorsTable).Declaration,
20: Pattern =>
21: {
22: Patterns.AddViewsInsteadOfTriggers,
23: Patterns.AddFolderForeignKey,
24: Patterns.AddAuditing,
25: Patterns.AddChangeTracking
26: }
27: }
28: }
29: }
The metadata above specifies that the OperatorsTable extent of the RulesModel module will be wired to support the following four Modeling Services patterns:
The use of the PatternApplication Sample is another example of Modeling Service’s productive “plug and chug” development paradigm. The following code snippet illustrates this by adding pattern metadata declarations for the Proposition extent:
27: },
28:
29: Proposition_Pattern
30: {
31: Module => about(RulesModel.PropositionsTable).Declaration.DefinedIn,
32: Extent => about(RulesModel.PropositionsTable).Declaration,
33: Pattern =>
34: {
35: Patterns.AddViewsInsteadOfTriggers,
36: Patterns.AddFolderForeignKey,
37: Patterns.AddAuditing,
38: Patterns.AddChangeTracking
39: }
40: }
41: }
42: }
Given this “plug an chug” paradigm, I won’t take the time here to illustrate the metadata declarations for the remaining RulesModel extents. For those interested readers a link to the Visual Studio solution is provided at the bottom of this post.
Next Time
At this stage of development Contoso’s model for business rules is ready for deployment into the Modeling Services Repository. The subject of the next post will be adding the required steps necessary to deploy and wire Contoso’s business rule repository in SQL Server.
SkyDrive Files