如何编写业务策略 Import-Export 和部署脚本
本部分介绍如何使用 RuleSetDeploymentDriver 以编程方式导入/导出和部署策略。
以下示例将显示如何将策略导出到文件:
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);
}
}
}
}
以下示例将显示如何从文件中导入策略并对其进行部署:
using System;
using Microsoft.RuleEngine;
using Microsoft.BizTalk.RuleEngineExtensions;
namespace SimpleImport
{
class ImportPolicy
{
[STAThread]
static void Main(string[] args)
{
String filename = args[0];
Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver dd;
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);
}
}
}
}
注意
代码假定对词汇没有依存关系;如果策略使用词汇,则必须首先导入这些词汇。