Beispiel #1
0
        /// <summary>
        /// Write the Example section in the text viewer.
        /// </summary>
        /// <param name="examp"></param>
        /// <returns></returns>
        public static String WriteExample(example examp)
        {
            var exampleStream = "    -------------------------- " + examp.ExampleName + " --------------------------\r\n\r\n";
            exampleStream += "    C:\\PS>" + examp.ExampleCmd + "\r\n\r\n";
            exampleStream += "    " + examp.ExampleDescription + "\r\n\r\n";
            exampleStream += "    " + examp.ExampleOutput + "\r\n\r\n";

            return exampleStream;
        }
        /// <summary>
        /// This routine handles the Save button on the Examples 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 AddExample_Click(object sender, RoutedEventArgs args)
        {

            TreeViewItem SelectedNode = (TreeViewItem)MainWindow.NavControl.CmdletTreeView.SelectedItem;
            if (SelectedNode != null)
            {
                int count = SelectedNode.Items.Count;
                if (this.ExamplesControl1.ExampleNameTextBox.Text == "")
                {
                    this.ExamplesControl1.ExampleNameTextBox.Text = "Example " + (count + 1).ToString();
                }

                if (this.ExamplesControl1.ExampleID.Text == "")
                //This is a new example
                {
                    //Add new exampe info.
                    TreeViewItem ParentNode = new TreeViewItem();
                    if ((String)SelectedNode.Header == "Examples")
                    {
                        ParentNode = (TreeViewItem)SelectedNode.Parent;
                    }
                    else
                    {
                        ParentNode = (TreeViewItem)SelectedNode.Parent;
                        ParentNode = (TreeViewItem)ParentNode.Parent;
                    }

                    cmdletDescription Cmdletdesc = (cmdletDescription)ParentNode.DataContext;
                    example examDetails = new example();
                    examDetails.ExampleCmd = this.ExamplesControl1.ExampleCommandTextBox.Text;
                    examDetails.ExampleDescription = this.ExamplesControl1.ExampleDescriptionTextBox.Text;
                    examDetails.ExampleName = this.ExamplesControl1.ExampleNameTextBox.Text;
                    examDetails.ExampleOutput = this.ExamplesControl1.ExampleOutputTextBox.Text;
                    examDetails.ExampleID = count;
                    TreeViewItem NewExampleNode = new TreeViewItem();
                    NewExampleNode.DataContext = examDetails;
                    NewExampleNode.Header = examDetails.ExampleName;
                    if (Cmdletdesc.Examples == null)
                    {
                        Collection<example> Examples = new Collection<example>();
                        Examples.Add(examDetails);
                        Cmdletdesc.Examples = Examples;
                        SelectedNode.DataContext = Examples;
                    }
                    else
                    {
                        Cmdletdesc.Examples.Add(examDetails);
                    }
                    MainWindow.ResetExamplesPage();
                    if ((String)SelectedNode.Header == "Examples")
                    {


                        if (sender != null)
                        {
                            SelectedNode.Items.Add(NewExampleNode);
                            SelectedNode.IsExpanded = true;
                            //int count = SelectedNode.Items.Count;
                            TreeViewItem ChildNode = (TreeViewItem)SelectedNode.Items[count];
                            ChildNode.IsSelected = true;
                        }
                        else
                        {
                            SelectedNode.Items.Add(NewExampleNode);
                            SelectedNode.IsExpanded = true;
                        }
                    }

                }


                else //this is an existing example
                {
                    //Update Example info.
                    if (SelectedNode.Header.ToString() == "Examples")
                    {
                        Collection<example> examDetails = (Collection<example>)SelectedNode.DataContext;
                        example examDetail = new example();
                        examDetail.ExampleCmd = this.ExamplesControl1.ExampleCommandTextBox.Text;
                        examDetail.ExampleDescription = this.ExamplesControl1.ExampleDescriptionTextBox.Text;
                        examDetail.ExampleName = this.ExamplesControl1.ExampleNameTextBox.Text;
                        examDetail.ExampleOutput = this.ExamplesControl1.ExampleOutputTextBox.Text;
                        examDetails.Add(examDetail);
                        //SelectedNode.Header = this.ExampleNameTextBox.Text;

                    }
                    else
                    {
                        example examDetails = (example)SelectedNode.DataContext;
                        examDetails.ExampleCmd = this.ExamplesControl1.ExampleCommandTextBox.Text;
                        examDetails.ExampleDescription = this.ExamplesControl1.ExampleDescriptionTextBox.Text;
                        examDetails.ExampleName = this.ExamplesControl1.ExampleNameTextBox.Text;
                        examDetails.ExampleOutput = this.ExamplesControl1.ExampleOutputTextBox.Text;
                        SelectedNode.Header = this.ExamplesControl1.ExampleNameTextBox.Text;
                    }

                }
            }


        }
        /// <summary>
        /// This routine removes examples from the tree.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void DeleteExample_Click(object sender, RoutedEventArgs args)
        {
            if (this.ExamplesControl1.ExampleID.Text == "")
            {
                //Safe to simply reset the Examples page.
                MainWindow.ResetExamplesPage();
            }
            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;
                //int ItemToRemove = selectedNode.Items.IndexOf();
                //
                cmdletDescription selectedCmdlet = (cmdletDescription)CmdletNode.DataContext;
                example selectedExample = (example)selectedNode.DataContext;

                foreach (cmdletDescription mycmdlet in MainWindow.CmdletsHelps)
                {

                    if (mycmdlet.CmdletName == selectedCmdlet.CmdletName)
                    {
                        Collection<example> myExamples = mycmdlet.Examples;
                        example exampletoRemove = new example();
                        foreach (example myexample in myExamples)
                        {
                            if (myexample.ExampleID == selectedExample.ExampleID)
                            {
                                exampletoRemove = myexample;

                            }
                        }
                        if (exampletoRemove.ExampleID.ToString() != null)
                        {
                            mycmdlet.Examples.Remove(exampletoRemove);
                            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>
        /// This one pastes one example at a time
        /// </summary>
        /// <param name="selectedExample"></param>
        /// <param name="copiedExample"></param>
        /// <param name="count"></param>
        public void copyExample(example selectedExample, example copiedExample, int count)
        {
            MainWindow.ExamplesControl1.ExampleCommandTextBox.Text = copiedExample.ExampleCmd;
            MainWindow.ExamplesControl1.ExampleDescriptionTextBox.Text = copiedExample.ExampleDescription;
            MainWindow.ExamplesControl1.ExampleOutputTextBox.Text = copiedExample.ExampleOutput;
            MainWindow.ExamplesControl1.ExampleNameTextBox.Text = copiedExample.ExampleName;
            AddExample_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 createExampleItemSection(XmlWriter writer, example result)
        {
            try
            {

                //Start a <command:example> section
                writer.WriteRaw("		<command:example>\r\n");
                //writer.WriteComment("Example item section");
                writer.WriteRaw("			<maml:title>\r\n");
                if (result.ExampleName != null)
                {
                    String ExampleTitle = HttpUtility.HtmlEncode("--------------  " + result.ExampleName.Replace("-", "").Trim() + " --------------");
                    writer.WriteRaw(ExampleTitle);
                }

                writer.WriteRaw("			</maml:title>\r\n");

                //Introduction
                writer.WriteRaw("			<maml:introduction>\r\n");
                writer.WriteRaw("				<maml:para>C:\\PS&gt;</maml:para>\r\n");
                writer.WriteRaw("C:\\PS&gt;");
                writer.WriteRaw("			</maml:introduction>\r\n");
                //  writer.WriteRaw();

                //Dev code section
                writer.WriteRaw("  			<dev:code>");
                //writer.WriteRaw("Command to run");
                writer.WriteRaw(HttpUtility.HtmlEncode(result.ExampleCmd));
                writer.WriteRaw("</dev:code>\r\n");

                //Dev remarks: Example description
                writer.WriteRaw("  			<dev:remarks>\r\n");
                //writer.WriteComment("Example description");
                writer.WriteRaw("				<maml:para>");
                writer.WriteRaw(HttpUtility.HtmlEncode(result.ExampleDescription));
                writer.WriteRaw("</maml:para>\r\n");
                writer.WriteRaw("				<maml:para></maml:para>\r\n");
                writer.WriteRaw("				<maml:para></maml:para>\r\n");
                writer.WriteRaw("				<maml:para>");
                writer.WriteRaw(HttpUtility.HtmlEncode(result.ExampleOutput));
                writer.WriteRaw("\r\n				</maml:para>\r\n");
                writer.WriteRaw("				<maml:para></maml:para>\r\n");
                writer.WriteRaw("  			</dev:remarks>\r\n");
                //writer.WriteRaw();

                //Example output section
                writer.WriteRaw("			<command:commandLines>\r\n");
                //writer.WriteComment("Example Output");
                writer.WriteRaw("				<command:commandLine>\r\n");
                writer.WriteRaw("					<command:commandText>\r\n");
                //writer.WriteComment("Example output section");
                //writer.WriteRaw(HttpUtility.HtmlEncode(result.ExampleOutput));
                writer.WriteRaw("					</command:commandText>\r\n");
                writer.WriteRaw("				</command:commandLine>\r\n");
                writer.WriteRaw("			</command:commandLines>\r\n");


                //End example secion
                writer.WriteRaw("		</command:example>\r\n");


                //<command:example>
                //  <maml:title>
                //    <!-- EXAMPLE 1-->
                //  </maml:title>
                //  <maml:introduction>
                //    <maml:para>C:\PS&gt;</maml:para>
                //  </maml:introduction>
                //  <dev:code><!-- Command to run --></dev:code>
                //  <dev:remarks>
                //    <maml:para><!-- Example description--></maml:para>
                //    <maml:para></maml:para>
                //    <maml:para></maml:para>
                //    <maml:para>      </maml:para>
                //    <maml:para></maml:para>
                //  </dev:remarks>
                //  <command:commandLines>
                //    <command:commandLine>
                //      <command:commandText><!-- Example output section--></command:commandText>
                //    </command:commandLine>
                //  </command:commandLines>
                //</command:example>
            }
            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;
        }
Beispiel #8
0
        public XmlWriter createExampleItemSection(XmlWriter writer, example result)
        {
            try
            {
                //Start a <command:example> section
                writer.WriteRaw("		<command:example>\r\n");
                //writer.WriteComment("Example item section");
                writer.WriteRaw("			<maml:title>\r\n");
                if (result.ExampleName != null)
                {
                    String ExampleTitle = HttpUtility.HtmlEncode("--------------  " + result.ExampleName.Replace("-", "").Trim() + " --------------");
                    writer.WriteRaw(ExampleTitle);
                }

                writer.WriteRaw("			</maml:title>\r\n");

                //Introduction
                writer.WriteRaw("			<maml:introduction>\r\n");
                writer.WriteRaw("				<maml:para>C:\\PS&gt;</maml:para>\r\n");
                writer.WriteRaw("C:\\PS&gt;");
                writer.WriteRaw("			</maml:introduction>\r\n");
                //  writer.WriteRaw();

                //Dev code section
                writer.WriteRaw("  			<dev:code>");
                //writer.WriteRaw("Command to run");
                writer.WriteRaw(HttpUtility.HtmlEncode(result.ExampleCmd));
                writer.WriteRaw("</dev:code>\r\n");

                //Dev remarks: Example description
                writer.WriteRaw("  			<dev:remarks>\r\n");
                //writer.WriteComment("Example description");
                writer.WriteRaw("				<maml:para>");
                writer.WriteRaw(HttpUtility.HtmlEncode(result.ExampleDescription));
                writer.WriteRaw("</maml:para>\r\n");
                writer.WriteRaw("				<maml:para></maml:para>\r\n");
                writer.WriteRaw("				<maml:para></maml:para>\r\n");
                writer.WriteRaw("				<maml:para>");
                writer.WriteRaw(HttpUtility.HtmlEncode(result.ExampleOutput));
                writer.WriteRaw("\r\n				</maml:para>\r\n");
                writer.WriteRaw("				<maml:para></maml:para>\r\n");
                writer.WriteRaw("  			</dev:remarks>\r\n");
                //writer.WriteRaw();

                //Example output section
                writer.WriteRaw("			<command:commandLines>\r\n");
                //writer.WriteComment("Example Output");
                writer.WriteRaw("				<command:commandLine>\r\n");
                writer.WriteRaw("					<command:commandText>\r\n");
                //writer.WriteComment("Example output section");
                //writer.WriteRaw(HttpUtility.HtmlEncode(result.ExampleOutput));
                writer.WriteRaw("					</command:commandText>\r\n");
                writer.WriteRaw("				</command:commandLine>\r\n");
                writer.WriteRaw("			</command:commandLines>\r\n");


                //End example secion
                writer.WriteRaw("		</command:example>\r\n");


                //<command:example>
                //  <maml:title>
                //    <!-- EXAMPLE 1-->
                //  </maml:title>
                //  <maml:introduction>
                //    <maml:para>C:\PS&gt;</maml:para>
                //  </maml:introduction>
                //  <dev:code><!-- Command to run --></dev:code>
                //  <dev:remarks>
                //    <maml:para><!-- Example description--></maml:para>
                //    <maml:para></maml:para>
                //    <maml:para></maml:para>
                //    <maml:para>      </maml:para>
                //    <maml:para></maml:para>
                //  </dev:remarks>
                //  <command:commandLines>
                //    <command:commandLine>
                //      <command:commandText><!-- Example output section--></command:commandText>
                //    </command:commandLine>
                //  </command:commandLines>
                //</command:example>
            }
            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);
        }