コード例 #1
0
        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);
            }
        }
コード例 #2
0
        public ArrayList GetFacts(string policyName)
        {
            #region From rules Engine

            ArrayList shortermFacts = new ArrayList();
            Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver dd = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver();
            RuleStore sqlrs;
            sqlrs = dd.GetRuleStore();
            RuleSetInfoCollection rsInfoCollection = sqlrs.GetRuleSets(policyName, RuleStore.Filter.Latest);
            foreach (RuleSetInfo rsInfo in rsInfoCollection)
            {
                RuleSet   ruleset     = sqlrs.GetRuleSet(rsInfo);
                ArrayList bindingList = Microsoft.RuleEngine.RuleSetBindingFinder.GetBindings(ruleset);
                foreach (object o in bindingList)
                {
                    if (o is Microsoft.RuleEngine.ClassBinding)
                    {
                        Microsoft.RuleEngine.ClassBinding cb = o as Microsoft.RuleEngine.ClassBinding;
                        if (cb.TypeName != "TrackSource.BizTalkRules.LongTermFactsWrapper")
                        {
                            shortermFacts.Add(Activator.CreateInstance(cb.Type));
                        }
                    }
                }
            }
            return(shortermFacts);

            #endregion
        }
コード例 #3
0
        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 });
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        public void DeployRuleSet(RuleSet ruleSet, string server, string database, bool deploy)
        {
            DoRuleEvent("DeployRuleSet", string.Format("Ready to {3} Ruleset {0} with version {1}.{2}.", new object[] { ruleSet.Name, ruleSet.CurrentVersion.MajorRevision, ruleSet.CurrentVersion.MinorRevision, deploy ? "deploy" : "publish" }));
            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();

            try
            {
                ruleStore.Add(ruleSet, true);
            }
            catch (RuleStoreRuleSetAlreadyPublishedException)
            {
                DoRuleEvent("DeployRuleSet", string.Format("Ruleset {0} is already published", new object[] { ruleSet.Name }), true);
            }
            catch
            {
                throw;
            }
            if (deploy)
            {
                try
                {
                    driver.Deploy(new RuleSetInfo(ruleSet.Name, ruleSet.CurrentVersion.MajorRevision, ruleSet.CurrentVersion.MinorRevision));
                }
                catch (RuleEngineDeploymentAlreadyDeployedException)
                {
                    DoRuleEvent("DeployRuleSet", string.Format("Ruleset {0} is already deployed.", new object[] { ruleSet.Name }), true);
                }
                catch
                {
                    throw;
                }
                DoRuleEvent("DeployRuleSet", string.Format("Deployed Ruleset {0} with version {1}.{2}.", new object[] { ruleSet.Name, ruleSet.CurrentVersion.MajorRevision, ruleSet.CurrentVersion.MinorRevision }));
            }
        }
コード例 #6
0
        public static void DeployVocabulary(Vocabulary[] vocabularies, string server, string database, TaskLoggingHelper log)
        {
            for (int i = 0; i < vocabularies.Length; i++)
            {
                log.LogMessage("Ready to deploy Vocabulary {0} with version {1}.{2}.", new object[] { vocabularies[i].Name, vocabularies[i].CurrentVersion.MajorRevision, vocabularies[i].CurrentVersion.MinorRevision });
            }
            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();

            try
            {
                for (int i = 0; i < vocabularies.Length; i++)
                {
                    ruleStore.Add(vocabularies[i], true);
                }
            }
            catch (RuleStoreVocabularyAlreadyPublishedException exception)
            {
                log.LogMessage("Vocabulary {0} already exists.", new object[] { exception.VocabularyName });
            }
            catch
            {
                throw;
            }
            for (int i = 0; i < vocabularies.Length; i++)
            {
                log.LogMessage("Deployed Vocabulary {0} with version {1}.{2}.", new object[] { vocabularies[i].Name, vocabularies[i].CurrentVersion.MajorRevision, vocabularies[i].CurrentVersion.MinorRevision });
            }
        }
コード例 #7
0
        private static void ExecuteRulesEngine(IBaseMessage pInMsg, string rulesPolicy)
        {
            Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver rulesDriver = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver();
            SqlRuleStore sqlRuleStore = (SqlRuleStore)rulesDriver.GetRuleStore();
            RuleSetInfoCollection rsic = sqlRuleStore.GetRuleSets(rulesPolicy, RuleStore.Filter.All);
            RuleSet rs = sqlRuleStore.GetRuleSet(rsic[0]);

            Microsoft.RuleEngine.RuleEngine engine = new Microsoft.RuleEngine.RuleEngine(rs);
            engine.Assert(pInMsg);
            engine.Execute();
        }
コード例 #8
0
        static int Main(string[] args)
        {
            DeployRulesCommandLine cl = new DeployRulesCommandLine();

            if (!cl.ParseAndContinue(args))
            {
                return(-1);
            }

            if (string.IsNullOrEmpty(cl.ruleSetFile) && string.IsNullOrEmpty(cl.ruleSetName) && string.IsNullOrEmpty(cl.vocabularyName))
            {
                Console.WriteLine(cl.GetUsage());
                return(-1);
            }

            if (!string.IsNullOrEmpty(cl.ruleSetName) && !string.IsNullOrEmpty(cl.vocabularyName))
            {
                Console.WriteLine(cl.GetUsage());
                return(-1);
            }

            if (cl.unpublish)
            {
                // If we're unpublishing then we must also undeploy.
                cl.undeploy = true;
            }

            cl.PrintLogo();

            Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver dd =
                new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver();

            try
            {
                try
                {
                    if (!cl.undeploy && cl.ruleSetFile != string.Empty)
                    {
                        Console.WriteLine("Importing and publishing from file '{0}'...", cl.ruleSetFile);
                        dd.ImportAndPublishFileRuleStore(cl.ruleSetFile);
                    }
                }
                catch (System.Exception ex)
                {
                    if (cl.ruleSetName != string.Empty)
                    {
                        Console.WriteLine("Unable to import/publish {0} ({1}). Attempting deploy operation.", cl.ruleSetFile, ex.Message);
                    }
                    else
                    {
                        throw;
                    }
                }

                if (!string.IsNullOrEmpty(cl.ruleSetName))
                {
                    ProcessPolicies(cl, dd);
                }

                if (!string.IsNullOrEmpty(cl.vocabularyName) && cl.unpublish)
                {
                    ProcessVocabularies(cl, dd);
                }

                Console.WriteLine("Operation complete.");
            }
            catch (Microsoft.RuleEngine.RuleEngineDeploymentAlreadyDeployedException ex)
            {
                Console.WriteLine("Operation did not complete: " + ex.Message);
            }
            catch (Microsoft.RuleEngine.RuleEngineDeploymentNotDeployedException ex)
            {
                Console.WriteLine("Operation did not complete: " + ex.Message);
            }
            catch (RuleEngineDeploymentRuleSetExistsException ex)
            {
                Console.WriteLine("Operation did not complete: " + ex.Message);
            }
            catch (RuleEngineDeploymentVocabularyExistsException ex)
            {
                Console.WriteLine("Operation did not complete: " + ex.Message);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("Failed: " + ex.ToString());
                Console.WriteLine();
                return(-1);
            }

            Console.WriteLine();
            return(0);
        }
コード例 #9
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;
                }
            }
        }