/// <summary> /// /// </summary> /// <returns></returns> public BizTalkBaseObjectCollectionEx GetRuleSets() { TraceManager.SmartTrace.TraceIn(); BizTalkBaseObjectCollectionEx ruleSets = new BizTalkBaseObjectCollectionEx(); try { RuleSetDeploymentDriver rsdd = new RuleSetDeploymentDriver(this.server, this.database); RuleStore rs = rsdd.GetRuleStore(); RuleSetInfoCollection rsic = rs.GetRuleSets(Microsoft.RuleEngine.RuleStore.Filter.All); foreach (RuleSetInfo rsi in rsic) { RuleArtifact ra = new RuleArtifact(); ra.Name = rsi.Name; ra.MajorVersion = rsi.MajorRevision; ra.MinorVersion = rsi.MinorRevision; ra.QualifiedName = ra.Name + "," + ra.MajorVersion + "," + ra.MinorVersion; ruleSets.Add(ra); } } catch (Exception ex) { TraceManager.SmartTrace.TraceError(ex); } TraceManager.SmartTrace.TraceOut(); return(ruleSets); }
public List <RuleSetInfo> GetRuleSets() { List <RuleSetInfo> ruleSetList = new List <RuleSetInfo>(); RuleSetDeploymentDriver driver = new RuleSetDeploymentDriver(); try { RuleStore ruleStore = driver.GetRuleStore(); RuleSetInfoCollection ruleSets = ruleStore.GetRuleSets(RuleStore.Filter.All); if (ruleSets.Count <= 0) { return(ruleSetList); } for (int i = 0; i < ruleSets.Count; i++) { ruleSetList.Add(ruleSets[i]); } } catch (RuleEngineConfigurationException confEx) { DoRuleEvent("GetRuleSets", string.Format("Rule engine configuration exception: {0}", confEx.Message), true); } catch (RuleEngineArgumentNullException nullEx) { DoRuleEvent("GetRuleSets", string.Format("Rule engine argument null exception: {0}", nullEx.Message), true); } return(ruleSetList); }
public void ExportRule(string filename, string rulesetName) { RuleSetDeploymentDriver driver = new RuleSetDeploymentDriver(); try { RuleStore ruleStore = driver.GetRuleStore(); RuleSetInfoCollection ruleSets = ruleStore.GetRuleSets(rulesetName, RuleStore.Filter.Latest); if (ruleSets.Count != 1) { DoRuleEvent("ExportRule", string.Format("No Ruleset named {0} exists in rule store {1}", rulesetName, ruleStore.Location)); return; } driver.ExportRuleSetToFileRuleStore(ruleSets[0], filename); } catch (RuleEngineConfigurationException confEx) { DoRuleEvent("ExportRule", string.Format("Rule engine configuration exception: {0}", confEx.Message), true); } catch (RuleEngineArgumentNullException nullEx) { DoRuleEvent("ExportRule", string.Format("Rule engine argument null exception: {0}", nullEx.Message), true); } DoRuleEvent("ExportRule", string.Format("Rule {0} saved to {1}", rulesetName, filename)); }
//Importing policies private static void CopyPolicies(RuleStore sourceRuleStore, RuleStore targetRuleStore, Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver dd) { RuleSetInfoCollection sourceRulesetInfoList = sourceRuleStore.GetRuleSets(RuleStore.Filter.All); RuleSetInfoCollection targetRulesetInfoList = targetRuleStore.GetRuleSets(RuleStore.Filter.All); foreach (RuleSetInfo targetItem in targetRulesetInfoList) { if (targetItem.Published) { } } foreach (RuleSetInfo item in sourceRulesetInfoList) { RuleSet policy = sourceRuleStore.GetRuleSet(item); RuleSet targetPolicy = targetRuleStore.GetRuleSet(item); try { System.Console.Out.WriteLine("Importing Policy ({0}) ..", policy.Name); targetRuleStore.Add(policy); } catch (Microsoft.RuleEngine.RuleStoreRuleSetAlreadyPublishedException e) { System.Console.Out.WriteLine("Importing Policy ({0}) : (RuleStoreRuleSetAlreadyPublishedException) Undeploying RulesetInfo {1}", policy.Name, item.Name); //dd.Undeploy(item); //System.Console.Out.WriteLine("Importing Policy ({0}) : (RuleStoreRuleSetAlreadyPublishedException) Successfully undeployed RulesetInfo {1}, next remove policy ", policy.Name, item.Name); bool toDeploy = false; try { targetRuleStore.Remove(policy); } catch (Microsoft.RuleEngine.RuleStoreRuleSetDeployedException ex) { dd.Undeploy(item); targetRuleStore.Remove(policy); toDeploy = true; } targetRuleStore.Add(policy); targetRuleStore.Publish(policy); if (toDeploy) { dd.Deploy(item); toDeploy = false; } } catch (Microsoft.RuleEngine.RuleStoreRuleSetDeployedException e) { System.Console.Out.WriteLine("Importing Policy ({0}) : (RuleStoreRuleSetDeployedException) Undeploying RulesetInfor {1}", policy.Name, item.Name); dd.Undeploy(item); targetRuleStore.Remove(policy); targetRuleStore.Add(policy); dd.Deploy(item); } } }
// for export private static void CopyPolicies(RuleStore sourceRuleStore, RuleStore targetRuleStore) { RuleSetInfoCollection rulesetInfoList = sourceRuleStore.GetRuleSets(RuleStore.Filter.All); foreach (RuleSetInfo item in rulesetInfoList) { RuleSet policy = sourceRuleStore.GetRuleSet(item); targetRuleStore.Add(policy); } }
//Importing policies private static void CopyPolicies(RuleStore sourceRuleStore, RuleStore targetRuleStore, Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver dd) { RuleSetInfoCollection sourceRulesetInfoList = sourceRuleStore.GetRuleSets(RuleStore.Filter.All); RuleSetInfoCollection targetRulesetInfoList = targetRuleStore.GetRuleSets(RuleStore.Filter.All); foreach (RuleSetInfo targetItem in targetRulesetInfoList) { if (targetItem.Published) { } } foreach (RuleSetInfo item in sourceRulesetInfoList) { RuleSet policy = sourceRuleStore.GetRuleSet(item); RuleSet targetPolicy = targetRuleStore.GetRuleSet(item); try { System.Console.Out.WriteLine("Importing Policy ({0}) .." , policy.Name); targetRuleStore.Add(policy); } catch (Microsoft.RuleEngine.RuleStoreRuleSetAlreadyPublishedException e) { System.Console.Out.WriteLine("Importing Policy ({0}) : (RuleStoreRuleSetAlreadyPublishedException) Undeploying RulesetInfo {1}", policy.Name, item.Name); //dd.Undeploy(item); //System.Console.Out.WriteLine("Importing Policy ({0}) : (RuleStoreRuleSetAlreadyPublishedException) Successfully undeployed RulesetInfo {1}, next remove policy ", policy.Name, item.Name); bool toDeploy = false; try { targetRuleStore.Remove(policy); } catch (Microsoft.RuleEngine.RuleStoreRuleSetDeployedException ex) { dd.Undeploy(item); targetRuleStore.Remove(policy); toDeploy = true; } targetRuleStore.Add(policy); targetRuleStore.Publish(policy); if (toDeploy) { dd.Deploy(item); toDeploy = false; } } catch (Microsoft.RuleEngine.RuleStoreRuleSetDeployedException e) { System.Console.Out.WriteLine("Importing Policy ({0}) : (RuleStoreRuleSetDeployedException) Undeploying RulesetInfor {1}", policy.Name, item.Name); dd.Undeploy(item); targetRuleStore.Remove(policy); targetRuleStore.Add(policy); dd.Deploy(item); } } }
private static void ProcessPolicies( DeployRulesCommandLine cl, Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver dd) { RuleStore ruleStore = dd.GetRuleStore(); RuleSetInfoCollection rsInfo = ruleStore.GetRuleSets(cl.ruleSetName, RuleStore.Filter.All); Version version = ParseVersion(cl.ruleSetVersion); RuleSetInfo matchingRuleSetInfo = null; foreach (RuleSetInfo currentRsi in rsInfo) { if (currentRsi.MajorRevision == version.Major && currentRsi.MinorRevision == version.Minor) { matchingRuleSetInfo = currentRsi; break; } } if (matchingRuleSetInfo == null) { Console.WriteLine( "No published ruleset with name '" + cl.ruleSetName + "' and version '" + cl.ruleSetVersion + "'."); } else if (cl.undeploy) { Console.WriteLine("Undeploying rule set '{0}' version {1}.{2}...", cl.ruleSetName, version.Major, version.Minor); if (dd.IsRuleSetDeployed(matchingRuleSetInfo)) { dd.Undeploy(matchingRuleSetInfo); } else { Console.WriteLine(" Rule set is not currently deployed."); } if (cl.unpublish) { Console.WriteLine("Unpublishing rule set '{0}' version {1}.{2}...", cl.ruleSetName, version.Major, version.Minor); ruleStore.Remove(matchingRuleSetInfo); } } else { Console.WriteLine("Deploying rule set '{0}' version {1}.{2}...", cl.ruleSetName, version.Major, version.Minor); dd.Deploy(matchingRuleSetInfo); } }
/// <summary> /// подключается к БД и возвращает все rule из БД /// </summary> /// <param name="severName"></param> /// <param name="dbName"></param> /// <returns></returns> public static RuleSetInfo[] GetRuleSetInfo(string severName, string dbName) { RuleStore ruleStore = ((IRuleSetDeploymentDriver)Microsoft.RuleEngine.RemoteUpdateService.RemoteUpdateService.LocateObject(Configuration.DeploymentDriverClass, Configuration.DeploymentDriverDll, new ArrayList() { severName, dbName }.ToArray())).GetRuleStore(); var ruleSetInfoCollection = ruleStore.GetRuleSets(RuleStore.Filter.All); var ruleSet = new RuleSetInfo[ruleSetInfoCollection.Count]; ruleSetInfoCollection.CopyTo(ruleSet, 0); return(ruleSet); }
public void UnDeployRuleSet(string ruleName, string server, string database) { DoRuleEvent("UnDeployRuleSet", string.Format("Ready to undeploy Rule name {0}.", new object[] { ruleName })); Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver driver; if ((server != string.Empty) && (database != string.Empty)) { driver = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver(server, database); } else { driver = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver(); } RuleStore ruleStore = driver.GetRuleStore(); RuleSetInfoCollection ruleSets = ruleStore.GetRuleSets(ruleName, RuleStore.Filter.All); foreach (RuleSetInfo ruleSet in ruleSets) { DoRuleEvent("UnDeployRuleSet", string.Format("Found Ruleset {0} with version {1}.{2}.", new object[] { ruleSet.Name, ruleSet.MajorRevision, ruleSet.MinorRevision })); } DoRuleEvent("UnDeployRuleSet", string.Format("Start Undeploy...", new object[] { })); bool bCont = true; while (bCont && ruleSets.Count > 0) { try { driver.Undeploy(ruleSets); bCont = false; } catch (RuleEngineDeploymentNotDeployedException ex) { DoRuleEvent("UnDeployRuleSet", string.Format("Ruleset {0} with version {1}.{2} was not deployed.", new object[] { ex.RuleSetName, ex.MajorVersion, ex.MinorVersion }), true); // remove from ruleSets and try again for (int i = 0; i < ruleSets.Count; i++) { if (ruleSets[i].Name.Equals(ex.RuleSetName) && ruleSets[i].MajorRevision == ex.MajorVersion && ruleSets[i].MinorRevision == ex.MinorVersion) { ruleSets.RemoveAt(i); break; } } } catch { throw; } } // We only need to ones published now ruleSets = ruleStore.GetRuleSets(ruleName, RuleStore.Filter.Published); foreach (RuleSetInfo ruleSet in ruleSets) { DoRuleEvent("UnDeployRuleSet", string.Format("Found Ruleset {0} with version {1}.{2} to be removed.", new object[] { ruleSet.Name, ruleSet.MajorRevision, ruleSet.MinorRevision })); } if (ruleSets.Count > 0) { DoRuleEvent("UnDeployRuleSet", string.Format("Start Remove...", new object[] { })); try { ruleStore.Remove(ruleSets); } catch { throw; } } }