/// <summary> /// This routine removes a related link from the tree. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> public void DeleteLink_Click(object sender, RoutedEventArgs args) { if (this.RelatedLinks1.LinkIDTextBox.Text == "") { //Safe to simply reset the Examples page. MainWindow.ResetLinksPage(); } else //We must remove the current record from the Examples list { TreeViewItem selectedNode = (TreeViewItem)MainWindow.NavControl.CmdletTreeView.SelectedItem; TreeViewItem ParentNode = (TreeViewItem)selectedNode.Parent; TreeViewItem CmdletNode = (TreeViewItem)ParentNode.Parent; ParentNode.IsSelected = true; ParentNode.Items.Remove(selectedNode); cmdletDescription selectedCmdlet = (cmdletDescription)CmdletNode.DataContext; relatedlink selectedLink = (relatedlink)selectedNode.DataContext; foreach (cmdletDescription mycmdlet in MainWindow.CmdletsHelps) { if (mycmdlet.CmdletName == selectedCmdlet.CmdletName) { Collection <relatedlink> myLinks = mycmdlet.RelatedLinks; relatedlink linktoRemove = new relatedlink(); foreach (relatedlink mylink in myLinks) { if (mylink.LinkID == selectedLink.LinkID) { linktoRemove = mylink; } } if (linktoRemove.LinkID.ToString() != null) { mycmdlet.RelatedLinks.Remove(linktoRemove); ParentNode.Items.Remove(selectedNode); } } } } }
public XmlWriter createLinksSection(XmlWriter writer, relatedlink result) { try { writer.WriteRaw(" <maml:navigationLink>\r\n"); writer.WriteRaw(" <maml:linkText>"); //writer.WriteComment("Related link text"); writer.WriteRaw(HttpUtility.HtmlEncode(result.LinkText)); writer.WriteRaw("</maml:linkText>\r\n"); //End related links section writer.WriteRaw(" <maml:uri/>\r\n"); writer.WriteRaw(" </maml:navigationLink>\r\n"); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "Error writing the XML File.", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } return(writer); }
/// <summary> /// This routine handles the Save button on the Related Link page /// It adds the new record to the tree. /// If this is already in the tree it updates it with the latest /// info in the page. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> public void AddRelatedLink_Click(object sender, RoutedEventArgs args) { TreeViewItem SelectedNode = (TreeViewItem)MainWindow.NavControl.CmdletTreeView.SelectedItem; if (SelectedNode != null) { int count = SelectedNode.Items.Count; if (this.RelatedLinks1.LinkIDTextBox.Text == "") //This is a new link { //Add new related link info. TreeViewItem ParentNode = (TreeViewItem)SelectedNode.Parent; cmdletDescription Cmdletdesc = (cmdletDescription)ParentNode.DataContext; int LinkCount = 0; if (Cmdletdesc.RelatedLinks != null) { LinkCount = Cmdletdesc.RelatedLinks.Count; } relatedlink linkDetails = new relatedlink(); linkDetails.LinkText = this.RelatedLinks1.RelatedLinkTextBox.Text; linkDetails.LinkID = LinkCount; TreeViewItem NewLinkNode = new TreeViewItem(); NewLinkNode.DataContext = linkDetails; NewLinkNode.Header = linkDetails.LinkText; if (Cmdletdesc.RelatedLinks == null) { Collection<relatedlink> Links = new Collection<relatedlink>(); Links.Add(linkDetails); Cmdletdesc.RelatedLinks = Links; SelectedNode.DataContext = Links; } else { Cmdletdesc.RelatedLinks.Add(linkDetails); } MainWindow.ResetLinksPage(); if ((String)SelectedNode.Header == "Related Links") { if (sender != null) { SelectedNode.Items.Add(NewLinkNode); SelectedNode.IsExpanded = true; TreeViewItem ChildNode = (TreeViewItem)SelectedNode.Items[count]; ChildNode.IsSelected = true; } else { SelectedNode.Items.Add(NewLinkNode); SelectedNode.IsExpanded = true; } } } else //this is an existing link { if (SelectedNode.Header.ToString() == "Related Links") { //Update link info. Collection<relatedlink> linkDetails = (Collection<relatedlink>)SelectedNode.DataContext; relatedlink linkDetail = new relatedlink(); linkDetail.LinkText = this.RelatedLinks1.RelatedLinkTextBox.Text; linkDetails.Add(linkDetail); } else { relatedlink linkDetails = (relatedlink)SelectedNode.DataContext; linkDetails.LinkText = this.RelatedLinks1.RelatedLinkTextBox.Text; SelectedNode.Header = this.RelatedLinks1.RelatedLinkTextBox.Text; } } } }
/// <summary> /// This routine removes a related link from the tree. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> public void DeleteLink_Click(object sender, RoutedEventArgs args) { if (this.RelatedLinks1.LinkIDTextBox.Text == "") { //Safe to simply reset the Examples page. MainWindow.ResetLinksPage(); } else //We must remove the current record from the Examples list { TreeViewItem selectedNode = (TreeViewItem)MainWindow.NavControl.CmdletTreeView.SelectedItem; TreeViewItem ParentNode = (TreeViewItem)selectedNode.Parent; TreeViewItem CmdletNode = (TreeViewItem)ParentNode.Parent; ParentNode.IsSelected = true; ParentNode.Items.Remove(selectedNode); cmdletDescription selectedCmdlet = (cmdletDescription)CmdletNode.DataContext; relatedlink selectedLink = (relatedlink)selectedNode.DataContext; foreach (cmdletDescription mycmdlet in MainWindow.CmdletsHelps) { if (mycmdlet.CmdletName == selectedCmdlet.CmdletName) { Collection<relatedlink> myLinks = mycmdlet.RelatedLinks; relatedlink linktoRemove = new relatedlink(); foreach (relatedlink mylink in myLinks) { if (mylink.LinkID == selectedLink.LinkID) { linktoRemove = mylink; } } if (linktoRemove.LinkID.ToString() != null) { mycmdlet.RelatedLinks.Remove(linktoRemove); ParentNode.Items.Remove(selectedNode); } } } } }
/// <summary> /// This is the static method which Asim helped me with. /// I get all the Cmdlet Mamal info from here. /// I need to pass the cmdletDescription record before adding it to the CmdletHelps collection. /// /// </summary> public static cmdletDescription GetExistingHelpInfo(cmdletDescription CmdletHelp, String CmdletName, String path) { //String path1 = @"C:\Windows\System32\WindowsPowerShell\v1.0\en-US\Microsoft.PowerShell.Commands.Management.dll-Help.xml"; XmlDocument doc = new XmlDocument(); doc.Load(path); XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable); ns.AddNamespace("", "http://msh"); ns.AddNamespace("command", "http://schemas.microsoft.com/maml/dev/command/2004/10"); ns.AddNamespace("maml", "http://schemas.microsoft.com/maml/2004/10"); ns.AddNamespace("dev", "http://schemas.microsoft.com/maml/dev/2004/10"); XmlNodeList commandNodes = doc.SelectNodes("//command:command", ns); foreach (XmlNode commandNode in commandNodes) { XmlNode nameNode = commandNode.SelectSingleNode("command:details/command:name", ns); if (nameNode.InnerText.Trim().ToLower() == CmdletName.ToLower()) { // MessageBox.Show(commandNode.OuterXml); XmlNode tempNode = null; tempNode = commandNode.SelectSingleNode("command:details/maml:description", ns); if (tempNode != null) { CmdletHelp.OldShortDescription = CmdletHelp.ShortDescription = tempNode.InnerText.Trim(); } tempNode = commandNode.SelectSingleNode("maml:description", ns); if (tempNode != null) { CmdletHelp.OldLongDescription = CmdletHelp.LongDescription = tempNode.InnerText.Trim(); } tempNode = commandNode.SelectSingleNode("command:inputTypes/command:inputType/dev:type/maml:name", ns); if (tempNode != null) { CmdletHelp.OldInputType = CmdletHelp.InputType = tempNode.InnerText.Trim(); } tempNode = commandNode.SelectSingleNode("command:inputTypes/command:inputType/dev:type/maml:description", ns); if (tempNode != null) { CmdletHelp.OldInputDesc = CmdletHelp.InputDesc = tempNode.InnerText.Trim(); } tempNode = commandNode.SelectSingleNode("command:returnValues/command:returnValue/dev:type/maml:name", ns); if (tempNode != null) { CmdletHelp.OldOutputType = CmdletHelp.OutputType = tempNode.InnerText.Trim(); } tempNode = commandNode.SelectSingleNode("command:returnValues/command:returnValue/dev:type/maml:description", ns); if (tempNode != null) { CmdletHelp.OldOutputDesc = CmdletHelp.OutputDesc = tempNode.InnerText.Trim(); } tempNode = commandNode.SelectSingleNode("maml:alertSet/maml:alert", ns); if (tempNode != null) { CmdletHelp.OldNote = CmdletHelp.Note = tempNode.InnerText.Trim(); } XmlNodeList exampleNodes = commandNode.SelectNodes("command:examples/command:example", ns); int exampleCount = 0; Collection<example> CmdletExamples = new Collection<example>(); foreach (XmlNode exampleNode in exampleNodes) { example CmdletExample = new example(); tempNode = exampleNode.SelectSingleNode("maml:title", ns); if (tempNode != null) { CmdletExample.OldExampleName = CmdletExample.ExampleName = tempNode.InnerText.Trim().Replace("-", ""); if (CmdletExample.ExampleName.Length == 0 || CmdletExample.ExampleName.Replace(" ", "") == "") { CmdletExample.ExampleName = CmdletExample.OldExampleName = "Unkown"; } } CmdletExample.ExampleID = exampleCount; tempNode = exampleNode.SelectSingleNode("dev:code", ns); if (tempNode != null) { CmdletExample.OldExampleCmd = CmdletExample.ExampleCmd = tempNode.InnerText.Trim(); } tempNode = exampleNode.SelectSingleNode("dev:remarks", ns); if (tempNode != null) { int NodeCount = 0; foreach (XmlNode DescriptionNode in tempNode) { if (NodeCount == 0) { CmdletExample.OldExampleDescription = CmdletExample.ExampleDescription = DescriptionNode.InnerText.Trim(); } else { CmdletExample.OldExampleOutput += DescriptionNode.InnerText.Trim(); CmdletExample.ExampleOutput = CmdletExample.OldExampleOutput; } NodeCount++; } } tempNode = exampleNode.SelectSingleNode("command:commandLines", ns); if (tempNode != null) { CmdletExample.OldExampleOutput += tempNode.InnerText.Trim(); CmdletExample.ExampleOutput = CmdletExample.OldExampleOutput; } exampleCount++; CmdletExamples.Add(CmdletExample); } CmdletHelp.Examples = CmdletExamples; Collection<relatedlink> RelatedLinks = new Collection<relatedlink>(); XmlNodeList NodeLinks = commandNode.SelectNodes("maml:relatedLinks/maml:navigationLink", ns); int LinkCount = 0; foreach (XmlNode linkNode in NodeLinks) { relatedlink RelatedLink = new relatedlink(); tempNode = linkNode.SelectSingleNode("maml:linkText", ns); if (tempNode != null) { RelatedLink.OldLinkText = RelatedLink.LinkText = tempNode.InnerText.Trim(); if (RelatedLink.LinkText.Length == 0) { RelatedLink.LinkText = RelatedLink.LinkText = "Unkown"; } } RelatedLink.LinkID = LinkCount; LinkCount++; RelatedLinks.Add(RelatedLink); } CmdletHelp.RelatedLinks = RelatedLinks; //iterate through parameters XmlNodeList parameterNodes = commandNode.SelectNodes("command:parameters/command:parameter", ns); if (CmdletHelp.ParameterDecription != null) { foreach (parameterDecription CmdletParameter in CmdletHelp.ParameterDecription) { //maml:description foreach (XmlNode parameterNode in parameterNodes) { tempNode = parameterNode.SelectSingleNode("maml:name", ns); if (tempNode != null) { if (CmdletParameter.Name.ToLower() == tempNode.InnerText.Trim().ToLower()) { tempNode = parameterNode.SelectSingleNode("maml:description", ns); if (tempNode != null) { CmdletParameter.OldDescription = CmdletParameter.NewDescription = tempNode.InnerText.Trim(); } tempNode = parameterNode.SelectSingleNode("dev:defaultValue", ns); if (tempNode != null) { CmdletParameter.DefaultValue = CmdletParameter.OldDefaultValue = tempNode.InnerText.Trim(); } tempNode = parameterNode.SelectSingleNode("@globbing", ns); if (tempNode.Value.ToLower().Trim() == "true") { CmdletParameter.Globbing = CmdletParameter.OldGlobbing = true; } else { CmdletParameter.Globbing = CmdletParameter.OldGlobbing = false; } } } } } } //I do not have code parameters. Get only help ones and mark them in red. foreach (XmlNode parameterNode in parameterNodes) { Boolean ParameterFound = false; tempNode = parameterNode.SelectSingleNode("maml:name", ns); String ParameterName = tempNode.InnerText.Trim(); if (CmdletHelp.ParameterDecription != null) { foreach (parameterDecription CmdletParameter in CmdletHelp.ParameterDecription) { if (CmdletParameter.Name.ToLower() == ParameterName.ToLower()) { ParameterFound = true; break; } } } if (ParameterFound == false) { //Get help parameter. parameterDecription CmdletParameter = new parameterDecription(); CmdletParameter.HelpOnlyParameter = true; MainWindow.ObsoleteInfo = true; tempNode = parameterNode.SelectSingleNode("maml:name", ns); if (tempNode != null) { // if (CmdletParameter.Name.ToLower() == tempNode.InnerText.Trim().ToLower()) // { tempNode = parameterNode.SelectSingleNode("maml:description", ns); if (tempNode != null) { CmdletParameter.OldDescription = CmdletParameter.NewDescription = tempNode.InnerText.Trim(); } tempNode = parameterNode.SelectSingleNode("dev:defaultValue", ns); if (tempNode != null) { CmdletParameter.DefaultValue = CmdletParameter.OldDefaultValue = tempNode.InnerText.Trim(); } tempNode = parameterNode.SelectSingleNode("@globbing", ns); if (tempNode.Value.ToLower().Trim() == "true") { CmdletParameter.Globbing = CmdletParameter.OldGlobbing = true; } else { CmdletParameter.Globbing = CmdletParameter.OldGlobbing = false; } tempNode = parameterNode.SelectSingleNode("@pipelineInput", ns); if (tempNode != null) { if (tempNode.Value.ToLower().Trim() == "true (ByPropertyName)") { CmdletParameter.VFPBPN = CmdletParameter.VFPBPN = true; } else if (tempNode.Value.ToLower().Trim() == "true (ByValue, ByPropertyName)") { CmdletParameter.VFPBPN = CmdletParameter.VFPBPN = true; CmdletParameter.VFP = CmdletParameter.VFP = true; } else if (tempNode.Value.ToLower().Trim() == "true (ByValue)") { CmdletParameter.VFP = CmdletParameter.VFP = true; } else { CmdletParameter.VFPBPN = CmdletParameter.VFPBPN = false; CmdletParameter.VFP = CmdletParameter.VFP = false; } } tempNode = parameterNode.SelectSingleNode("@position", ns); if (tempNode != null) { CmdletParameter.Position = tempNode.Value.ToLower().Trim(); } tempNode = parameterNode.SelectSingleNode("@required", ns); if (tempNode != null) { if (tempNode.Value.ToLower().Trim() == "true") { CmdletParameter.isMandatory = true; } } tempNode = parameterNode.SelectSingleNode("dev:type/maml:name", ns); if (tempNode != null) { if (tempNode.InnerText != null) { CmdletParameter.ParameterType = tempNode.InnerText.Trim().ToLower(); } } CmdletParameter.Name = ParameterName; CmdletParameter.CmdletName = CmdletName; if (CmdletHelp.ParameterDecription == null) { CmdletHelp.ParameterDecription = new Collection<parameterDecription>(); } CmdletHelp.ParameterDecription.Add(CmdletParameter); } } } // break; } } return CmdletHelp; }
/// <summary> /// Paste one related link at a time /// </summary> /// <param name="selectedLink"></param> /// <param name="copiedLink"></param> /// <param name="count"></param> public void copyLink(relatedlink selectedLink, relatedlink copiedLink, int count) { MainWindow.RelatedLinks1.RelatedLinkTextBox.Text = copiedLink.LinkText; AddRelatedLink_Click(null, null); }
/// <summary> /// This is the OnPaste routine. If the action is paste, /// it calls the correct paste function above. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void OnPaste(object sender, RoutedEventArgs e) { TreeViewItem SelectedItem = (TreeViewItem)this.NavigationControl1.CmdletTreeView.SelectedItem; switch (MainWindow.ClipBoardRecord.TypeName) { case "cmdlet description info": if (SelectedItem.DataContext is cmdletDescription) { cmdletDescription copiedinfo = (cmdletDescription)MainWindow.ClipBoardRecord.ClipBoardItem; cmdletDescription selectedCmdlet = (cmdletDescription)SelectedItem.DataContext; selectedCmdlet.ShortDescription = copiedinfo.ShortDescription; selectedCmdlet.LongDescription = copiedinfo.LongDescription; selectedCmdlet.InputType = copiedinfo.InputType; selectedCmdlet.InputDesc = copiedinfo.InputDesc; selectedCmdlet.OutputType = copiedinfo.OutputType; selectedCmdlet.OutputDesc = copiedinfo.OutputDesc; selectedCmdlet.Note = copiedinfo.Note; SelectedItem.DataContext = selectedCmdlet; doDefaultTreeViewSelectionChange(); } else { System.Windows.Forms.MessageBox.Show("You have placed " + MainWindow.ClipBoardRecord.TypeName.ToString() + " type on the tools clip board.\nMake sure to paste it on a matching node type.", "Error pasting copied record", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } break; case "parameters description info": if (SelectedItem.DataContext is Collection<parameterDecription>) { Collection<parameterDecription> copiedParameters = (Collection<parameterDecription>)MainWindow.ClipBoardRecord.ClipBoardItem; Collection<parameterDecription> selectedParameters = (Collection<parameterDecription>)SelectedItem.DataContext; foreach (parameterDecription param in selectedParameters) { foreach (parameterDecription copiedparam in copiedParameters) { if (param.Name == copiedparam.Name) { copyParameterInfo(param, copiedparam); break; } } } SelectedItem.DataContext = selectedParameters; doDefaultTreeViewSelectionChange(); } else { System.Windows.Forms.MessageBox.Show("You have placed " + MainWindow.ClipBoardRecord.TypeName.ToString() + " type on the tools clip board.\nMake sure to paste it on a matching node type.", "Error pasting copied record", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } break; case "parameter decription info": if (SelectedItem.DataContext is parameterDecription) { parameterDecription copiedParameter = (parameterDecription)MainWindow.ClipBoardRecord.ClipBoardItem; parameterDecription selectedPrameter = (parameterDecription)SelectedItem.DataContext; copyParameterInfo(selectedPrameter, copiedParameter); SelectedItem.DataContext = selectedPrameter; doDefaultTreeViewSelectionChange(); } else { System.Windows.Forms.MessageBox.Show("You have placed " + MainWindow.ClipBoardRecord.TypeName.ToString() + " type on the tools clip board.\nMake sure to paste it on a matching node type.", "Error pasting copied record", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } break; case "example info": if (SelectedItem.DataContext is Collection<example> || SelectedItem.DataContext is example) { if (SelectedItem.DataContext is Collection<example>) { example copiedExample = (example)MainWindow.ClipBoardRecord.ClipBoardItem; Collection<example> selectedExamples = (Collection<example>)SelectedItem.DataContext; example newExample = new example(); copyExample(newExample, copiedExample, selectedExamples.Count); selectedExamples.Add(newExample); SelectedItem.DataContext = selectedExamples; } else { TreeViewItem parentNode = (TreeViewItem)SelectedItem.Parent; Collection<example> ParentExamples = (Collection<example>)parentNode.DataContext; example copiedExample = (example)MainWindow.ClipBoardRecord.ClipBoardItem; example selectedExample = (example)SelectedItem.DataContext; copyExample(selectedExample, copiedExample, ParentExamples.Count); SelectedItem.DataContext = selectedExample; } doDefaultTreeViewSelectionChange(); } else { System.Windows.Forms.MessageBox.Show("You have placed " + MainWindow.ClipBoardRecord.TypeName.ToString() + " type on the tools clip board.\nMake sure to paste it on a matching node type.", "Error pasting copied record", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } break; case "examples description info": if (SelectedItem.DataContext is Collection<example>) { Collection<example> copiedExamples = (Collection<example>)MainWindow.ClipBoardRecord.ClipBoardItem; Collection<example> selectedExamples = (Collection<example>)SelectedItem.DataContext; foreach (example copiedExample in copiedExamples) { example newExample = new example(); copyExample(newExample, copiedExample, selectedExamples.Count); selectedExamples.Add(newExample); } SelectedItem.DataContext = selectedExamples; doDefaultTreeViewSelectionChange(); } else { System.Windows.Forms.MessageBox.Show("You have placed " + MainWindow.ClipBoardRecord.TypeName.ToString() + " type on the tools clip board.\nMake sure to paste it on a matching node type.", "Error pasting copied record", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } break; case "related link info": if (SelectedItem.DataContext is relatedlink || SelectedItem.DataContext is Collection<relatedlink>) { if (SelectedItem.DataContext is Collection<relatedlink>) { relatedlink copiedLink = (relatedlink)MainWindow.ClipBoardRecord.ClipBoardItem; Collection<relatedlink> selectedLinks = (Collection<relatedlink>)SelectedItem.DataContext; relatedlink newrelatedlink = new relatedlink(); copyLink(newrelatedlink, copiedLink, selectedLinks.Count); selectedLinks.Add(newrelatedlink); SelectedItem.DataContext = selectedLinks; } else { TreeViewItem parentNode = (TreeViewItem)SelectedItem.Parent; Collection<relatedlink> ParentLinks = (Collection<relatedlink>)parentNode.DataContext; relatedlink copiedLink = (relatedlink)MainWindow.ClipBoardRecord.ClipBoardItem; relatedlink selectedLink = (relatedlink)SelectedItem.DataContext; copyLink(selectedLink, copiedLink, ParentLinks.Count); SelectedItem.DataContext = selectedLink; } doDefaultTreeViewSelectionChange(); } else { System.Windows.Forms.MessageBox.Show("You have placed " + MainWindow.ClipBoardRecord.TypeName.ToString() + " type on the tools clip board.\nMake sure to paste it on a matching node type.", "Error pasting copied record", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } break; case "related links info": if (SelectedItem.DataContext is Collection<relatedlink>) { Collection<relatedlink> copiedLinks = (Collection<relatedlink>)MainWindow.ClipBoardRecord.ClipBoardItem; Collection<relatedlink> selectedLinks = (Collection<relatedlink>)SelectedItem.DataContext; foreach (relatedlink copiedLink in copiedLinks) { relatedlink newLink = new relatedlink(); copyLink(newLink, copiedLink, selectedLinks.Count); selectedLinks.Add(newLink); } SelectedItem.DataContext = selectedLinks; doDefaultTreeViewSelectionChange(); } else { System.Windows.Forms.MessageBox.Show("You have placed " + MainWindow.ClipBoardRecord.TypeName.ToString() + " type on the tools clip board.\nMake sure to paste it on a matching node type.", "Error pasting copied record", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } break; } }
public XmlWriter createLinksSection(XmlWriter writer, relatedlink result) { try { writer.WriteRaw(" <maml:navigationLink>\r\n"); writer.WriteRaw(" <maml:linkText>"); //writer.WriteComment("Related link text"); writer.WriteRaw(HttpUtility.HtmlEncode(result.LinkText)); writer.WriteRaw("</maml:linkText>\r\n"); //End related links section writer.WriteRaw(" <maml:uri/>\r\n"); writer.WriteRaw(" </maml:navigationLink>\r\n"); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "Error writing the XML File.", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } return writer; }
/// <summary> /// This routine handles the Save button on the Related Link page /// It adds the new record to the tree. /// If this is already in the tree it updates it with the latest /// info in the page. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> public void AddRelatedLink_Click(object sender, RoutedEventArgs args) { TreeViewItem SelectedNode = (TreeViewItem)MainWindow.NavControl.CmdletTreeView.SelectedItem; if (SelectedNode != null) { int count = SelectedNode.Items.Count; if (this.RelatedLinks1.LinkIDTextBox.Text == "") //This is a new link { //Add new related link info. TreeViewItem ParentNode = (TreeViewItem)SelectedNode.Parent; cmdletDescription Cmdletdesc = (cmdletDescription)ParentNode.DataContext; int LinkCount = 0; if (Cmdletdesc.RelatedLinks != null) { LinkCount = Cmdletdesc.RelatedLinks.Count; } relatedlink linkDetails = new relatedlink(); linkDetails.LinkText = this.RelatedLinks1.RelatedLinkTextBox.Text; linkDetails.LinkID = LinkCount; TreeViewItem NewLinkNode = new TreeViewItem(); NewLinkNode.DataContext = linkDetails; NewLinkNode.Header = linkDetails.LinkText; if (Cmdletdesc.RelatedLinks == null) { Collection <relatedlink> Links = new Collection <relatedlink>(); Links.Add(linkDetails); Cmdletdesc.RelatedLinks = Links; SelectedNode.DataContext = Links; } else { Cmdletdesc.RelatedLinks.Add(linkDetails); } MainWindow.ResetLinksPage(); if ((String)SelectedNode.Header == "Related Links") { if (sender != null) { SelectedNode.Items.Add(NewLinkNode); SelectedNode.IsExpanded = true; TreeViewItem ChildNode = (TreeViewItem)SelectedNode.Items[count]; ChildNode.IsSelected = true; } else { SelectedNode.Items.Add(NewLinkNode); SelectedNode.IsExpanded = true; } } } else //this is an existing link { if (SelectedNode.Header.ToString() == "Related Links") { //Update link info. Collection <relatedlink> linkDetails = (Collection <relatedlink>)SelectedNode.DataContext; relatedlink linkDetail = new relatedlink(); linkDetail.LinkText = this.RelatedLinks1.RelatedLinkTextBox.Text; linkDetails.Add(linkDetail); } else { relatedlink linkDetails = (relatedlink)SelectedNode.DataContext; linkDetails.LinkText = this.RelatedLinks1.RelatedLinkTextBox.Text; SelectedNode.Header = this.RelatedLinks1.RelatedLinkTextBox.Text; } } } }