Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
programming4us
Windows 7

Microsoft Visio 2010 : Importing rule sets from XML

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
3/30/2012 11:27:43 AM
This method first requests the user to select the XML file (it can be in the standard Visio XML file format too) that contains the rule or rule sets to import from. It then iterates through the rule set and rule elements to add them to the selected VEDocument.

If it encounters a rule set with the same name as an existing rule set in the selected VEDocument, then the user is prompted to overwrite or not.

Imported rule sets are immediately added to the Rules Explorer tree view.

public void ImportRuleSets()
{
try
{
string title = "RuleSets";
string shortName = System.IO.Path.GetFileNameWithoutExtension( this.document.FullName);
string fileName = System.IO.Path.Combine( this.document.Path, shortName + ".xml");
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.Title = "Import " + title;
dlg.InitialDirectory = System.Environment.GetFolderPath( System.Environment.SpecialFolder.MyDocuments);
dlg.DefaultExt = ".xml";
dlg.Filter = "XML documents (.xml)|*.xml |Visio XML drawing (.vdx)|*.vdx|Visio XML template (.vtx)|*.vtx";
if (dlg.ShowDialog() == true)
{
fileName = dlg.FileName;
}
else return;
XDocument xdoc = XDocument.Load(fileName);
XNamespace xns = "http://schemas.microsoft.com/visio/2003/core";
XNamespace v14 = "http://schemas.microsoft.com/office/visio/2009/5/extension";
XNamespace vx = "http://schemas.microsoft.com/visio/2006/extension";
XElement docNode = xdoc.Element(xns + "VisioDocument");
if (docNode == null) return;
//Get the Validation element (abort if none found)
XElement validNode = docNode.Element(v14 + "Validation");
if (validNode == null) return;
//Get the RuleSets element (abort if none found)
XElement ruleSetsNode = validNode.Element(v14 + "RuleSets");
if (ruleSetsNode == null) return;
foreach (XElement ruleSetNode in ruleSetsNode.Elements(v14 + "RuleSet"))
{
//Get the NameU attribute
string rsName = ruleSetNode.Attribute("NameU").Value;
//Set the default response
System.Windows.MessageBoxResult process = System.Windows.MessageBoxResult.Yes;
//Check if the rule set exists already
if (this.VERuleSets.Count(ver => ver.NameU == rsName) >0)
{
rules setsimporting, from XML//Ask to replace an existing ruleset (or skip if declined)
process = System.Windows.MessageBox.Show( "The rule set, " + rsName + ", exists already.\\nDo you wish to replace it?",
"Import Ruleset", System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Question, System.Windows.MessageBoxResult.Yes);
if (process == System.Windows.MessageBoxResult.No) break;
rule sets, importing from XMLthis.VERuleSets[rsName].Delete();
}
else process = System.Windows.MessageBoxResult.Yes;
//Add a new VERuleSet object to this VEDocument
VERuleSet vrset = this.VERuleSets.AddRuleSet(rsName);
//Set the properties of the VERuleSet from the attributes
foreach (XAttribute xat in ruleSetNode.Attributes())
{
switch (xat.Name.LocalName)
{
case "Name":
vrset.Name = xat.Value;
break;
case "Description":
vrset.Description = xat.Value;
break;
case "RuleSetFlags":
vrset.RuleSetFlags = (Visio.VisRuleSetFlags)Convert.ToInt32( xat.Value);
break;
}
}
//Set the remaining properties of the VERuleSet from the elements
foreach (XElement xelm in ruleSetNode.Elements())
{
switch (xelm.Name.LocalName)
{
case "Rule":
string rName = xelm.Attribute("NameU").Value;
VERule vrle = vrset.VERules.AddRule(rName);
//Set the properties of the VERule from the attributes
foreach (XAttribute xat in xelm.Attributes())
{
switch (xat.Name.LocalName)
{
rules setsimporting, from XMLcase "Category":
vrle.Category = xat.Value;
break;
case "Description":
vrle.Description = xat.Value;
break;
case "TargetType":
vrle.TargetType = (Visio.VisRuleTargets)Convert.ToInt32( xat.Value);
break;
rule sets, importing from XML}
}
//Set the remaining properties of the VERule from the elements
foreach (XElement xelmR in xelm.Elements())
{
switch (xelmR.Name.LocalName)
{
case "RuleFilter":
vrle.FilterExpression = xelmR.Value;
break;
case "RuleTest":
vrle.TestExpression = xelmR.Value;
break;
}
}
break;
}
}
}
}
catch (Exception)
{
throw;
}
rules setsimporting, from XML}					  
Other -----------------
- Microsoft Visio 2010 : Exporting rule sets to XML
- Microsoft Access 2010 : Editing a Query in Design View
- Microsoft Access 2010 : Copying to and from Other Office Programs
- Microsoft Excel 2010 : Refreshing Pivot Table Data, Adding a Report Filter & Adding Pivot Table Data
- Microsoft Excel 2010 : Creating a Pivot Table & Rearranging a Pivot Table
- Windows 7 : Virtualization (part 2) - Native Hard Disk Support in Windows 7
- Windows 7 : Virtualization (part 1)
- Microsoft Project 2010 : Putting a Price Tag on Your Project & Incorporating Resource Costs
- Customizing Project 2010 : Creating and Editing Views
- Microsoft Outlook 2010 : Processing Messages Automatically - Controlling Rules & Sharing Rules with Others
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server