public void WriteRuleSet(RuleSet ruleSet, VocabularyInfoCollection referencedVocabs, StreamWriter writer)
        {
            SortedList sl = new SortedList();

            this.WriteStartOfPage(ruleSet);

            this.WriteReferencedVocabs(referencedVocabs);

            foreach (Rule rule in ruleSet.Rules.Values)
            {
                sl.Add(rule.Name + "|" + rule.GetHashCode(), rule);
            }

            int counter = 0;

            foreach (Rule rule in sl.Values)
            {
                WriteRule(rule, counter);
                this.WriteRuleSeparator();
                counter++;
            }

            this.WriteEndOfPage();

            this.writer.Flush();

            return;
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public BizTalkBaseObjectCollectionEx GetVocabularies()
        {
            TraceManager.SmartTrace.TraceIn();

            BizTalkBaseObjectCollectionEx vocabularies = new BizTalkBaseObjectCollectionEx();

            try
            {
                RuleSetDeploymentDriver rsdd = new RuleSetDeploymentDriver(this.server, this.database);
                RuleStore rs = rsdd.GetRuleStore();

                VocabularyInfoCollection vic = rs.GetVocabularies(Microsoft.RuleEngine.RuleStore.Filter.All);

                foreach (VocabularyInfo vi in vic)
                {
                    RuleArtifact ra = new RuleArtifact();
                    ra.Name          = vi.Name;
                    ra.MajorVersion  = vi.MajorRevision;
                    ra.MinorVersion  = vi.MinorRevision;
                    ra.QualifiedName = ra.Name + "," + ra.MajorVersion + "," + ra.MinorVersion;
                    vocabularies.Add(ra);
                }
            }
            catch (Exception ex)
            {
                TraceManager.SmartTrace.TraceError(ex);
            }

            TraceManager.SmartTrace.TraceOut();
            return(vocabularies);
        }
        /// <summary>
        ///
        /// </summary>
        public void PrepareVocabs()
        {
            TraceManager.SmartTrace.TraceIn();
            vdefs = new Hashtable();

            try
            {
                RuleSetDeploymentDriver rsdd = new RuleSetDeploymentDriver(this.server, this.database);
                RuleStore store = rsdd.GetRuleStore();

                VocabularyInfoCollection vocabularyInfos = store.GetVocabularies(RuleStore.Filter.All);

                foreach (VocabularyInfo vi in vocabularyInfos)
                {
                    Vocabulary v = store.GetVocabulary(vi);

                    foreach (VocabularyDefinition o in v.Definitions)
                    {
                        if (!vdefs.ContainsKey(o.Id))
                        {
                            vdefs.Add(o.Id, o);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                TraceManager.SmartTrace.TraceError(ex);
            }

            TraceManager.SmartTrace.TraceOut();
        }
        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 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);
            }
        }
Exemple #6
0
        public List <VocabularyInfo> GetVocabularies()
        {
            List <VocabularyInfo>   vocabularyList = new List <VocabularyInfo>();
            RuleSetDeploymentDriver driver         = new RuleSetDeploymentDriver();

            try
            {
                RuleStore ruleStore = driver.GetRuleStore();
                VocabularyInfoCollection vocabularies = ruleStore.GetVocabularies(RuleStore.Filter.All);
                if (vocabularies.Count < 1)
                {
                    return(vocabularyList);
                }
                for (int i = 0; i < vocabularies.Count; i++)
                {
                    vocabularyList.Add(vocabularies[i]);
                }
            }
            catch (RuleEngineConfigurationException confEx)
            {
                DoRuleEvent("GetVocabularies", string.Format("Rule engine configuration exception: {0}", confEx.Message), true);
            }
            catch (RuleEngineArgumentNullException nullEx)
            {
                DoRuleEvent("GetVocabularies", string.Format("Rule engine argument null exception: {0}", nullEx.Message), true);
            }
            return(vocabularyList);
        }
Exemple #7
0
        public void ExportVocabulary(string filename, string vocabName)
        {
            RuleSetDeploymentDriver driver = new RuleSetDeploymentDriver();

            try
            {
                RuleStore ruleStore = driver.GetRuleStore();
                VocabularyInfoCollection vocabularies = ruleStore.GetVocabularies(vocabName, RuleStore.Filter.All);
                if (vocabularies.Count < 1)
                {
                    DoRuleEvent("ExportVocabulary", string.Format("No Vocabulary named {0} exists in rule store {1}", vocabName, ruleStore.Location));
                    return;
                }
                driver.ExportVocabularyToFileRuleStore(vocabularies[0], filename);
            }
            catch (RuleEngineConfigurationException confEx)
            {
                DoRuleEvent("ExportVocabulary", string.Format("Rule engine configuration exception: {0}", confEx.Message), true);
            }
            catch (RuleEngineArgumentNullException nullEx)
            {
                DoRuleEvent("ExportVocabulary", string.Format("Rule engine argument null exception: {0}", nullEx.Message), true);
            }
            DoRuleEvent("ExportVocabulary", string.Format("Vocabulary {0} saved to {1}", vocabName, filename));
        }
Exemple #8
0
        private void tabPageDeleteVocabulary_Enter(object sender, EventArgs e)
        {
            listViewDeleteVocabulary.Items.Clear();
            tabPageDeleteVocabulary.Tag = listViewDeleteVocabulary;
            //this.actionableListView = listViewDeleteVocabulary;
            richTextBox2.Text = string.Empty;
            VocabularyInfoCollection vocabularies = BreHelper.GetPublishedVocabularies();

            LoadVocabularies(vocabularies);
        }
Exemple #9
0
        private static List <RuleSetInfoCollection> GetDependentRuleSetsOnVocabulary(string brlFileName)
        {
            List <RuleSetInfoCollection> list = new List <RuleSetInfoCollection>();
            FileRuleStore            frs      = new FileRuleStore(brlFileName);
            VocabularyInfoCollection coll     = frs.GetVocabularies(RuleStore.Filter.All);

            foreach (VocabularyInfo item in coll)
            {
                list.Add(frs.GetDependentRuleSets(item));
            }
            return(list);
        }
Exemple #10
0
 private void LoadVocabularies(VocabularyInfoCollection vocabularies)
 {
     foreach (VocabularyInfo item in vocabularies)
     {
         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.CreateDeleteVocabularyActions(item.Name, item.MajorRevision.ToString(), item.MinorRevision.ToString());
         listViewDeleteVocabulary.Items.Add(listViewItem);
     }
 }
        // for export
        private static void CopyVocabularies(RuleStore sourceRuleStore, RuleStore targetRuleStore)
        {
            VocabularyInfoCollection vocabInfoList = sourceRuleStore.GetVocabularies(RuleStore.Filter.All);

            foreach (VocabularyInfo vocabInfoItem in vocabInfoList)
            {
                Vocabulary vocabItem = sourceRuleStore.GetVocabulary(vocabInfoItem);

                string[] excludedVocabularyNames = { "Predicates", "Common Values", "Common Sets", "Functions" };
                if (!excludedVocabularyNames.Contains(vocabItem.Name))
                {
                    targetRuleStore.Add(vocabItem);
                }
            }
        }
        public static Vocabulary[] LoadVocabFromFile(string filename, string vocabName)
        {
            RuleStore store = new FileRuleStore(filename);
            VocabularyInfoCollection vocabularies = store.GetVocabularies(vocabName, RuleStore.Filter.All);

            if (vocabularies.Count < 1)
            {
                throw new ApplicationException(string.Format("EXCEPTION: No Vocabulary named {0} exists in rule store {1}", vocabName, filename));
            }
            Vocabulary[] vocabularyArray = new Vocabulary[vocabularies.Count];
            for (int i = 0; i < vocabularies.Count; i++)
            {
                vocabularyArray[i] = store.GetVocabulary(vocabularies[i]);
            }
            return(vocabularyArray);
        }
        private void WriteReferencedVocabs(VocabularyInfoCollection referencedVocabs)
        {
            if (referencedVocabs != null && referencedVocabs.Count > 0)
            {
                this.writer.WriteLine("	<table class='TableData' ID='Table3'>");
                this.writer.WriteLine("		<tr>");
                this.writer.WriteLine("			<td width='10'></td>");
                this.writer.WriteLine("			<td class='TableTitle'>Referenced Vocabularies:</td>");
                this.writer.WriteLine("		</tr>");

                foreach (VocabularyInfo vi in referencedVocabs)
                {
                    this.writer.WriteLine("		<tr>");
                    this.writer.WriteLine("			<td width='10'></td>");
                    this.writer.WriteLine("			<td class='TableData'><a class='TableData' href='../Vocabulary/{0} {1}.{2}.html'>{0} {1}.{2}</a></td>", vi.Name, vi.MajorRevision, vi.MinorRevision);
                    this.writer.WriteLine("		</tr>");
                }

                this.writer.WriteLine("	</table>");
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="ruleSet"></param>
        /// <param name="outputFolder"></param>
        /// <returns></returns>
        public string ExportRuleSetToFile(RuleArtifact ruleSet, string outputFolder)
        {
            TraceManager.SmartTrace.TraceIn();
            string fileName = null;

            try
            {
                RuleSetDeploymentDriver rsdd = new RuleSetDeploymentDriver(this.server, this.database);
                RuleStore store = rsdd.GetRuleStore();

                RuleSetInfo rsi = new RuleSetInfo(ruleSet.Name, ruleSet.MajorVersion, ruleSet.MinorVersion);
                VocabularyInfoCollection referencedVocabs = store.GetReferencedVocabularies(rsi);
                RuleSet rs = store.GetRuleSet(rsi);

                fileName = Path.Combine(outputFolder, ruleSet.XmlFileName);
                rsdd.ExportRuleSetToFileRuleStore(rsi, fileName);


                fileName = Path.Combine(outputFolder, ruleSet.HtmlFileName);
                StreamWriter  sw     = new StreamWriter(fileName);
                RuleSetWriter writer = new RuleSetWriter(sw);

                writer.VocabularyDefinitions = vdefs;
                writer.WriteRuleSet(rs, referencedVocabs, sw);

                sw.Flush();
                sw.Close();
            }
            catch (Exception ex)
            {
                TraceManager.SmartTrace.TraceError(ex);
                TraceManager.SmartTrace.TraceError("FileName will be set to NULL");
            }

            TraceManager.SmartTrace.TraceOut();
            return(fileName);
        }
        // for import
        private static void CopyVocabularies(RuleStore sourceRuleStore, RuleStore targetRuleStore, Microsoft.BizTalk.RuleEngineExtensions.RuleSetDeploymentDriver dd)
        {
            VocabularyInfoCollection vocabInfoList = sourceRuleStore.GetVocabularies(RuleStore.Filter.All);

            foreach (VocabularyInfo vocabInfoItem in vocabInfoList)
            {
                Vocabulary vocabItem = sourceRuleStore.GetVocabulary(vocabInfoItem);

                string[] excludedVocabularyNames = { "Predicates", "Common Values", "Common Sets", "Functions" };
                if (!excludedVocabularyNames.Contains(vocabItem.Name))
                {
                    try
                    {
                        targetRuleStore.Add(vocabItem);
                    }
                    catch (Exception e)
                    {
                        //targetRuleStore.Remove(vocabItem);
                        //targetRuleStore.Add(vocabItem);
                        //targetRuleStore.Publish(vocabItem);
                    }
                }
            }
        }