Example #1
0
        //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);
                }
            }
        }
Example #2
0
        //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 ProcessVocabularies(
            DeployRulesCommandLine cl, Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver dd)
        {
            RuleStore ruleStore            = dd.GetRuleStore();
            VocabularyInfoCollection vInfo = ruleStore.GetVocabularies(cl.vocabularyName, RuleStore.Filter.All);

            Version version = ParseVersion(cl.ruleSetVersion);

            VocabularyInfo matchingVocabularyInfo = null;

            foreach (VocabularyInfo currentRsi in vInfo)
            {
                if (currentRsi.MajorRevision == version.Major &&
                    currentRsi.MinorRevision == version.Minor)
                {
                    matchingVocabularyInfo = currentRsi;
                    break;
                }
            }

            if (matchingVocabularyInfo == null)
            {
                Console.WriteLine(
                    "No published vocabulary with name '" + cl.vocabularyName + "' and version '" + cl.ruleSetVersion + "'.");
            }
            else if (cl.unpublish)
            {
                Console.WriteLine("Unpublishing vocabulary '{0}' version {1}.{2}...", cl.vocabularyName, version.Major, version.Minor);
                ruleStore.Remove(matchingVocabularyInfo);
            }
        }
        public static void UnDeployVocabulary(string vocabName, string serverName, string databaseName, TaskLoggingHelper log)
        {
            log.LogMessage("Ready to undeploy Vocabulary name {0}.", new object[] { vocabName });
            Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver driver;
            if ((databaseName != string.Empty) && (serverName != string.Empty))
            {
                driver = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver(serverName, databaseName);
            }
            else
            {
                driver = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver();
            }
            RuleStore ruleStore = driver.GetRuleStore();
            VocabularyInfoCollection vocabularies = ruleStore.GetVocabularies(vocabName, RuleStore.Filter.All);

            foreach (VocabularyInfo vocabulary in vocabularies)
            {
                log.LogMessage("Found vocabulary {0} with version {1}.{2}.", new object[] { vocabulary.Name, vocabulary.MajorRevision, vocabulary.MinorRevision });
            }
            log.LogMessage("Start Undeploy...", new object[] { });
            try
            {
                ruleStore.Remove(vocabularies);
            }
            catch
            {
                throw;
            }
            log.LogMessage("Vocabularies with name {0} removed.", new object[] { vocabName });
        }
        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);
            }
        }
Example #6
0
        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;
                }
            }
        }