//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);
                }
            }
        }
Exemple #2
0
        /* public static int ExportPolicy(string name, int majorVersion, int minorVersion,string filepath, out string message)
         * {
         *   RuleSetInfo rInfo = new RuleSetInfo(name, majorVersion, minorVersion);
         *   Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver rdd = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver();
         *   rdd.ExportRuleSetToFileRuleStore(rInfo, filepath);
         *   RuleStore store = rdd.GetRuleStore();
         *
         * }*/


        public static int DeployPolicy(string policyName, int majorVersion, int minorVersion, out string message)
        {
            int result = 0;

            try
            {
                Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver rdd = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver();
                RuleSetInfo rsi = new RuleSetInfo(policyName, majorVersion, minorVersion);
                rdd.Deploy(rsi);
                message = "Successfully Deployed";
            }
            catch (Exception exe)
            {
                message = exe.Message;
                return(-1);
            }

            return(result);
        }
        static void DeployRuleSet(RuleSet ruleset)
        {
            // Clean up the existing ruleset(s) in the rule store first
            // before publishing and deploying veriosn 1.0
            CleanUp(ruleset.Name);

            // now we have the ruleset, need to copy it to the database
            Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver dd = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver();
            RuleStore sqlrs;

            sqlrs = dd.GetRuleStore();
            // add the RuleSet to the database (and publish it)
            try
            {
                sqlrs.Add(ruleset, true);
            }
            catch (RuleStoreRuleSetAlreadyPublishedException)
            {
                Console.WriteLine("Warning: Ruleset \"" + ruleset.Name + "\" is already published");
            }
            catch
            {
                throw;
            }
            // now deploy the ruleset
            try
            {
                dd.Deploy(new RuleSetInfo(ruleset.Name,
                                          ruleset.CurrentVersion.MajorRevision, ruleset.CurrentVersion.MinorRevision));
            }
            catch (RuleEngineDeploymentAlreadyDeployedException)
            {
                Console.WriteLine("Warning: Ruleset \"" + ruleset.Name + "\" is already deployed");
            }
            catch
            {
                throw;
            }
        }