Пример #1
0
        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);
        }
Пример #2
0
        static void CleanUp(string RSName)
        {
            // Clean up deployed ruleset
            Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver dd = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver();
            RuleStore sqlrs;
            bool      bDeployed = false;

            sqlrs = dd.GetRuleStore();

            RuleSetInfoCollection rss = new RuleSetInfoCollection();

            rss = sqlrs.GetRuleSets(RSName, RuleStore.Filter.Latest);

            int i = 0;

            if (rss.Count > 0)
            {
                for (i = 0; i < rss.Count; i++)
                {
                    bDeployed = dd.IsRuleSetDeployed(rss[i]);
                    if (bDeployed)
                    {
                        dd.Undeploy(rss[i]);
                    }
                    sqlrs.Remove(rss[i]);
                }
            }
        }         // End of Cleanup()
        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
        }
Пример #4
0
        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));
        }
        /// <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);
        }
Пример #6
0
        private void tabPage3_Enter(object sender, EventArgs e)
        {
            listViewUnDeployPolicy.Items.Clear();
            tabPage3.Tag             = listViewUnDeployPolicy;
            richTextBoxUnDeploy.Text = string.Empty;
            RuleSetInfoCollection ruleSetCollection = BizTalkDeploymentTool.Helpers.BreHelper.GetDeployedRuleSets();

            LoadDeployedPolicies(ruleSetCollection);
        }
Пример #7
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);
                }
            }
        }
Пример #8
0
        // 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);
            }
        }
Пример #9
0
        private void tabPageDeletePolicy_Enter(object sender, EventArgs e)
        {
            listViewDeletePolicy.Items.Clear();
            tabPageDeletePolicy.Tag = listViewDeletePolicy;
            //this.actionableListView = listViewDeletePolicy;
            richTextBox1.Text = string.Empty;
            RuleSetInfoCollection ruleSetCollection = BizTalkDeploymentTool.Helpers.BreHelper.GetPublishedUndeployedRuleSets();

            LoadDeletePolicies(ruleSetCollection);
        }
Пример #10
0
        private void LoadPoliciesAndVocabularies()
        {
            treeView1.Nodes.Clear();
            TreeNode parentNode          = treeView1.Nodes.Add("BRE");
            TreeNode policiesNode        = parentNode.Nodes.Add("Policies");
            TreeNode vocabulariesNode    = parentNode.Nodes.Add("Vocabularies");
            TreeNode nodePublishedPolicy = policiesNode.Nodes.Add("Published");
            TreeNode nodeDeployedPolicy  = policiesNode.Nodes.Add("Deployed");
            RuleSetInfoCollection ruleSetCollectionPublished = BizTalkDeploymentTool.Helpers.BreHelper.GetPublishedUndeployedRuleSets();
            RuleSetInfoCollection ruleSetCollectionDeployed  = BizTalkDeploymentTool.Helpers.BreHelper.GetDeployedRuleSets();

            foreach (RuleSetInfo item in ruleSetCollectionPublished)
            {
                TreeNode node = nodePublishedPolicy.Nodes.Add(string.Format("{0} {1}.{2}", item.Name, item.MajorRevision.ToString(), item.MinorRevision.ToString()));
                node.Tag = BreActionFactory.CreateDeployActions(item.Name, item.MajorRevision.ToString(), item.MinorRevision.ToString());
            }

            foreach (RuleSetInfo item in ruleSetCollectionDeployed)
            {
                TreeNode node = nodeDeployedPolicy.Nodes.Add(string.Format("{0} {1}.{2}", item.Name, item.MajorRevision.ToString(), item.MinorRevision.ToString()));
                node.Tag = BreActionFactory.CreateUnDeployActions(item.Name, item.MajorRevision.ToString(), item.MinorRevision.ToString());
            }

            /* foreach (var ruleSets in BreHelper.GetPublishedUndeployedRuleSets())
             * {
             *   TreeNode node = treeView1.Nodes[0].Nodes.Add(ruleSets);
             *   node.ImageIndex = 4;
             *   node.SelectedImageIndex = 4;
             *   TreeNode appPool = node.Nodes.Add("Application Pools");
             *   appPool.ImageIndex = 1;
             *   appPool.SelectedImageIndex = 1;
             *   appPool.ContextMenuStrip = contextMenuStripServer;
             *   foreach (Microsoft.Web.Administration.ApplicationPool item in IISHelper.GetAppPools(server))
             *   {
             *       TreeNode pool = appPool.Nodes.Add(item.Name);
             *       pool.ImageIndex = 1;
             *       pool.SelectedImageIndex = 1;
             *       pool.Tag = item;
             *   }
             *   foreach (var item in IISHelper.GetSites(server))
             *   {
             *       TreeNode nodeSites = node.Nodes.Add(item);
             *       nodeSites.ImageIndex = 2;
             *       nodeSites.SelectedImageIndex = 2;
             *       nodeSites.ContextMenuStrip = contextMenuStripWebSite;
             *       foreach (var application in IISHelper.GetSiteAppList(item))
             *       {
             *           TreeNode applicationNode = nodeSites.Nodes.Add(application);
             *           applicationNode.ImageIndex = 3;
             *           applicationNode.SelectedImageIndex = 3;
             *           applicationNode.ContextMenuStrip = contextMenuStripDeletApp;
             *       }
             *   }
             * }*/
        }
Пример #11
0
        public RuleSet LoadRuleFromFile(string filename, string rulesetName)
        {
            RuleStore             store    = new FileRuleStore(filename);
            RuleSetInfoCollection ruleSets = store.GetRuleSets(rulesetName, RuleStore.Filter.Latest);

            if (ruleSets.Count != 1)
            {
                throw new ApplicationException(string.Format("EXCEPTION: No Ruleset named {0} exists in rule store {1}", rulesetName, filename));
            }
            return(store.GetRuleSet(ruleSets[0]));
        }
Пример #12
0
 private void LoadDeletePolicies(RuleSetInfoCollection ruleSetCollection)
 {
     foreach (RuleSetInfo item in ruleSetCollection)
     {
         ListViewItem listViewItem = new ListViewItem(new string[] { item.Name, item.MajorRevision.ToString(), item.MinorRevision.ToString(), "Published", string.Empty });
         listViewItem.SubItems[3].ForeColor   = Color.SteelBlue;
         listViewItem.SubItems[3].Font        = new Font(btnVocabularies.Font.Name, btnVocabularies.Font.Size, FontStyle.Bold);
         listViewItem.UseItemStyleForSubItems = false;
         listViewItem.Tag = BreActionFactory.CreateDeletePolicyActions(item.Name, item.MajorRevision.ToString(), item.MinorRevision.ToString());
         listViewDeletePolicy.Items.Add(listViewItem);
     }
 }
Пример #13
0
        /// <summary>
        /// ITestStep.Execute() implementation
        /// </summary>
        /// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
        /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
        public void Execute(System.Xml.XmlNode testConfig, Context context)
        {
            // Using Policy Tester

            // Retrieve Rule-Set from Policy file
            string RuleStoreName             = context.ReadConfigAsString(testConfig, "RuleStoreName");
            string RuleSetInfoCollectionName = context.ReadConfigAsString(testConfig, "RuleSetInfoCollectionName");
            string DebugTracking             = context.ReadConfigAsString(testConfig, "DebugTracking");
            string SampleXML  = context.ReadConfigAsString(testConfig, "SampleXML");
            string XSD        = context.ReadConfigAsString(testConfig, "XSD");
            string ResultFile = context.ReadConfigAsString(testConfig, "ResultFile");

            RuleStore             ruleStore = new FileRuleStore(RuleStoreName);
            RuleSetInfoCollection rsInfo    = ruleStore.GetRuleSets(RuleSetInfoCollectionName, RuleStore.Filter.Latest);

            if (rsInfo.Count != 1)
            {
                // oops ... error
                throw new ApplicationException();
            }

            RuleSet ruleset = ruleStore.GetRuleSet(rsInfo[0]);

            // Create an instance of the DebugTrackingInterceptor
            DebugTrackingInterceptor dti = new DebugTrackingInterceptor(DebugTracking);

            // Create an instance of the Policy Tester class
            PolicyTester policyTester = new PolicyTester(ruleset);

            XmlDocument xd1 = new XmlDocument();

            xd1.Load(SampleXML);

            TypedXmlDocument doc1 = new TypedXmlDocument(XSD, xd1);

            // Execute Policy Tester
            try
            {
                policyTester.Execute(doc1, dti);
            }
            catch (Exception e)
            {
                context.LogException(e);
                throw;
            }

            FileInfo     f = new FileInfo(ResultFile);
            StreamWriter w = f.CreateText();

            w.Write(doc1.Document.OuterXml);
            w.Close();
        }
        public void ExecutePolicy()
        {
            // Retrieve Rule-Set from the filestore

            RuleStore ruleStore = new FileRuleStore("MedicalInsurancePolicy.xml");

            //Grab the latest version of the rule-set

            RuleSetInfoCollection rsInfo = ruleStore.GetRuleSets("MedicalInsurancePolicy", RuleStore.Filter.Latest);

            if (rsInfo.Count != 1)
            {
                // oops ... error
                throw new ApplicationException();
            }

            RuleSet ruleset = ruleStore.GetRuleSet(rsInfo[0]);

            // Create an instance of the DebugTrackingInterceptor to provide an output trace
            DebugTrackingInterceptor dti = new DebugTrackingInterceptor("outputtrace.txt");

            //Create an instance of the Policy Tester class
            PolicyTester policyTester = new PolicyTester(ruleset);

            //Create the set of short term facts

            //XML facts

            XmlDocument xd1 = new XmlDocument();

            xd1.Load(@"..\..\sampleClaim.xml");

            TypedXmlDocument doc1 = new TypedXmlDocument("MedicalClaims", xd1);

            // .NET facts
            Microsoft.Samples.BizTalk.MedicalClaimsProcessingandTestingPolicies.Claims.ClaimResults results = new Microsoft.Samples.BizTalk.MedicalClaimsProcessingandTestingPolicies.Claims.ClaimResults();

            object[] shortTermFacts = new object[] { doc1, results, new TimeStamp(DateTime.Now) };

            //Execute Policy Tester
            try
            {
                policyTester.Execute(shortTermFacts, dti);
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            }
            System.Console.WriteLine("Status: " + results.Status);
            System.Console.WriteLine("Reason: " + results.Reason);
        }
        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);
            }
        }
Пример #16
0
        static RuleSet LoadFromFile(string filename, string rulesetName)
        {
            // load the ruleset from a file
            RuleStore             ruleStore = new FileRuleStore(filename);
            RuleSetInfoCollection rsInfo    = ruleStore.GetRuleSets(rulesetName, RuleStore.Filter.Latest);

            if (rsInfo.Count != 1)
            {
                // oops ... error
                throw new ApplicationException();
            }
            RuleSet newRS = ruleStore.GetRuleSet(rsInfo[0]);

            return(newRS);
        }
Пример #17
0
 public void TestBre()
 {
     try
     {
         Microsoft.RuleEngine.RuleSetDeploymentDriver driver = new Microsoft.RuleEngine.RuleSetDeploymentDriver("epsbtsvm", "BizTalkRuleEngineDb");
         RuleSetInfoCollection ruleSets = driver.GetRuleStore().GetRuleSets(RuleStore.Filter.All);
         foreach (RuleSetInfo set in ruleSets)
         {
             driver.ExportRuleSetToFileRuleStore(set, @"C:\temp\" + set.Name);
         }
     }
     catch (Exception ex)
     {
         HandleException("TestBRE", ex);
     }
 }
Пример #18
0
        public static RuleSetInfoCollection GetNamedRuleSets(string name)
        {
            RuleSetInfoCollection namedRuleCollection = new RuleSetInfoCollection();

            Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver dd = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver();
            RuleSetInfoCollection ruleCollection = dd.GetDeployedRuleSets();

            foreach (RuleSetInfo rule in ruleCollection)
            {
                if (rule.Name == name)
                {
                    namedRuleCollection.Add(rule);
                }
            }
            return(namedRuleCollection);
        }
Пример #19
0
        }         // End of Cleanup()

        public void Execute()
        {
            //Using Policy Tester

            // Retrieve Rule-Set from Policy file
            RuleStore             ruleStore = new FileRuleStore("LoanProcessing.xml");
            RuleSetInfoCollection rsInfo    = ruleStore.GetRuleSets("LoanProcessing", RuleStore.Filter.Latest);

            if (rsInfo.Count != 1)
            {
                // oops ... error
                throw new ApplicationException();
            }

            RuleSet ruleset = ruleStore.GetRuleSet(rsInfo[0]);

            // Create an instance of the DebugTrackingInterceptor
            DebugTrackingInterceptor dti = new DebugTrackingInterceptor("outputtraceforLoanPocessing.txt");

            //Create an instance of the Policy Tester class
            PolicyTester policyTester = new PolicyTester(ruleset);

            XmlDocument xd1 = new XmlDocument();

            xd1.Load("sampleLoan.xml");

            TypedXmlDocument doc1 = new TypedXmlDocument("Microsoft.Samples.BizTalk.LoansProcessor.Case", xd1);

            //Execute Policy Tester
            try
            {
                policyTester.Execute(doc1, dti);
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            }

            FileInfo     f = new FileInfo("LoanPocessingResults.xml");
            StreamWriter w = f.CreateText();

            w.Write(doc1.Document.OuterXml);
            w.Close();
        }
Пример #20
0
        static void CleanUp()
        {
            // Clean up deployed ruleset
            Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver dd = new Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver();
            RuleStore sqlrs;
            bool      bDeployed = false;

            sqlrs = dd.GetRuleStore();

            RuleSetInfoCollection rss = new RuleSetInfoCollection();

            rss = sqlrs.GetRuleSets("SampleRuleset", RuleStore.Filter.All);

            int i = 0;

            if (rss.Count > 0)
            {
                for (i = 0; i < rss.Count; i++)
                {
                    bDeployed = dd.IsRuleSetDeployed(rss[i]);
                    if (bDeployed)
                    {
                        dd.Undeploy(rss[i]);
                    }
                    sqlrs.Remove(rss[i]);
                }
            }

            try
            {
                // Delete the SampleRuleStore.xml
                File.Delete("SampleRuleStore.xml");
            }
            catch
            {
                Console.Write("Cannot delete SampleRuleStore.xml as it is being edited currently. Please delete this file before you run the sample again.");
            }
        }
Пример #21
0
        public void TestBre2()
        {
            const string       connStr = "Data Source=(local);Initial Catalog=BizTalkMgmtDb;Integrated Security=True;Min Pool Size=10;MultipleActiveResultSets=True;Connect Timeout=30;Network Library=dbnmpntw;Application Name=ShoBiz";
            BtsCatalogExplorer bce     = new BtsCatalogExplorer();

            bce.ConnectionString = connStr;

            SqlRuleStore srs = new SqlRuleStore(connStr.Replace("BizTalkMgmtDb", "BizTalkRuleEngineDb"));

            RuleSetInfoCollection rsic = srs.GetRuleSets(RuleStore.Filter.LatestPublished);

            foreach (Policy p in bce.Applications["EPS Cloud Catalog"].Policies)
            {
                PrintLine("Policy Name: {0}", p.Name);
            }

            foreach (RuleSetInfo info in rsic)
            {
                PrintLine("RuleSet found: {0} ({1}.{2})", info.Name, info.MajorRevision, info.MinorRevision);

                RuleSet rs = srs.GetRuleSet(info);

                RuleDisplayStringExtractor rdse = new RuleDisplayStringExtractor(srs, info);

                PrintLine("rules count: {0}", rs.Rules.Count);
                if (rs.Rules.Count == 0)
                {
                    continue;
                }
                IEnumerator iter = rs.Rules.GetEnumerator();
                while (iter.MoveNext())
                {
                    DictionaryEntry de = (DictionaryEntry)iter.Current;
                    Rule            r  = de.Value as Rule;
                    PrintLine("Rule Display String Extractor ({0}): {1}", r.Name, rdse.ExtractRuleDisplayString(r));
                }
            }
        }
Пример #22
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;
                }
            }
        }