Once all business policies and their required
vocabularies are defined and well tested, you can deploy them to your
production environment. You have a few deployment options. The first is
to use the BizTalk Administration Console, which lets you add policies
to applications. Thus, you can export rules, dependent .NET classes, and
other artifacts used by policies into isolated MSI packages for
environment deployment. In many cases, it is the easiest solution.
You can also use the Business Rule Deployment Wizard
to package the policies and/or vocabulary for deployment. The Business
Rule Deployment Wizard will allow you to export a particular version of a
vocabulary definition or policy definition to an XML file. After
exporting all the required policies and vocabulary definitions, remember
to package all fact retrievers and custom .NET classes used as facts in
the solution. You will need to deploy those to the Global Assembly
Cache on your production server running the BRE. You will also need to
copy the XML schema definitions used by facts in your policies and
vocabulary to the same directory path in your production environment as
your development and testing environments.
NOTE
Remember to modify your database facts to point
to your production database before deploying the business policies and
vocabulary in production. If not, your rules will either fail or read
and write to your test database environment.
For more complicated scenarios, application
developers might like to package the rules as well as all other
collateral material in an interactive setup for the system administrator
to use while deploying the application to production. Such a setup
package should also contain schema files, .NET assemblies referenced by
the business policies, as well as fact retrievers or policy translators
used by the policies meant to be deployed. Using an interactive setup,
the application developer can prompt the system administrator for the
directory location in which he would like to deploy schemas and other
collateral files used by the business policies as well as the production
database server and database to be used for different database facts.
The following is a dump of a business policy exported
to XML. Note the references to the fact retriever assembly and fully
qualified class name, the database server information and table names,
as well as the schema file location in the fact definitions.
<brl xmlns="http://schemas.microsoft.com/businessruleslanguage/2002">
<ruleset name="RFP">
<version major="1" minor="4" description=""
modifiedby="myserver\user"
date="2004-02-15T00:29:02.6381024-05:00" />
<configuration>
<factretriever>
<assembly>DbFactRetriever, Version=1.0.1505.34508,
Culture=neutral, PublicKeyToken=d4e488d64aff1da4</assembly>
<class>
Que.BizTalk.RFP.myFactRetriever.RFPDbFactRetriever
</class>
</factretriever>
</configuration>
<bindings>
<xmldocument ref="xml_0" doctype="RFPEstimateXML.RulesRFP"
instances="16" selectivity="1" instance="0">
<selector>/*[local-name()='RFP' and namespace-uri()=
'http://RFPEstimateXML.RulesRFP"] </selector>
<schema>C:\RulesRFP.xsd</schema>
</xmldocument>
<datarow ref="db_1" server="myserver\Consulting"
dataset="Consulting" table="Rates" instances="16"
selectivity="1" isdataconnection="true"
instance="0" />
</bindings>
|
The following code snippet uses the Business Rules Framework to export a policy version to an XML file.
using System;
using Microsoft.RuleEngine;
using Microsoft.BizTalk.RuleEngineExtensions;
namespace SimpleExport
{
class ExportPolicy
{
[STAThread]
static void Main(string[] args)
{
if (args.Length != 3)
Console.WriteLine("Format: PolicyName MajorVersion MinorVersion");
else
{
string policyName = args[0];
int majorRev = Convert.ToInt16(args[1]);
int minorRev = Convert.ToInt16(args[2]);
RuleSetInfo rsi = new RuleSetInfo(policyName,majorRev,minorRev);
Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver dd;
dd = new
Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver();
string fileName = (rsi.Name + "-" + rsi.MajorRevision +
"." + rsi.MinorRevision + ".xml");
dd.ExportRuleSetToFileRuleStore(rsi,fileName);
}
}
}
}
The following code snippet uses the Business Rule
Engine Framework to import a policy version from an XML file into the
Rule Store and deploy it.
using System;
using Microsoft.RuleEngine;
using Microsoft.BizTalk.RuleEngineExtensions;
namespace SimpleImport
{
class ImportPolicy
{
[STAThread]
static void Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine("Format: ""XML File Name""");
return;
}
String filename = args[0];
Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver
dd = new
Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver();
SqlRuleStore sqlRuleStore = (SqlRuleStore) dd.GetRuleStore();
FileRuleStore fileRuleStore = new FileRuleStore(filename);
RuleSetInfoCollection rsic =
fileRuleStore.GetRuleSets(RuleStore.Filter.All);
foreach (RuleSetInfo rsi in rsic)
{
RuleSet ruleSet = fileRuleStore.GetRuleSet(rsi);
bool publishRuleSets = true;
sqlRuleStore.Add(ruleSet,publishRuleSets);
dd.Deploy(rsi);
}
}
}
}