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

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
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
Trailers Game
- The Banner Saga 2 [PS4/XOne/PC] PC Launch Trailer
- Welkin Road [PC] Early Access Trailer
- 7th Dragon III Code: VFD [3DS] Character Creation Trailer
- Human: Fall Flat [PS4/XOne/PC] Coming Soon Trailer
- Battlefleet Gothic: Armada [PC] Eldar Trailer
- Neon Chrome [PS4/XOne/PC] PC Release Date Trailer
- Rocketbirds 2: Evolution [Vita/PS4] Launch Trailer
- Battleborn [PS4/XOne/PC] 12 Min Gameplay Trailer
- 7 Days to Die [PS4/XOne/PC] Console Trailer
- Total War: Warhammer [PC] The Empire vs Chaos Warriors Gameplay Trailer
- Umbrella Corps [PS4/PC] Mercenary Customization Trailer
- Niten [PC] Debut Trailer
- Stellaris [PC] Aiming for the Stars - Dev. Diary Trailer #1
- LawBreakers [PC] Dev Diary #4: Concept Art Evolutions
programming4us programming4us
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 windows Phone 7 windows Phone 8
programming4us programming4us
 
programming4us
Natural Miscarriage
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Game Trailer