/// <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);
                        }
                    }
                }
            }
        }
Exemple #2
0
        public static void GetHelpInfoNotInCode(Collection <cmdletDescription> CodeCmdlets, 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);

            //TreeViewItem psSnapinNode =  ;
            foreach (XmlNode commandNode in commandNodes)
            //foreach (cmdletDescription cmdletHelp in CodeCmdlets)
            {
                cmdletDescription CmdletHelp = new cmdletDescription();
                XmlNode           nameNode   = commandNode.SelectSingleNode("command:details/command:name", ns);
                //CmdletHelp = cmdletHelp;
                Boolean CmdletFound = false;
                foreach (cmdletDescription cmdletHelp in CodeCmdlets)
                {
                    if (nameNode.InnerText.Trim().ToLower() == cmdletHelp.CmdletName.ToLower())
                    {
                        CmdletFound = true;
                        break;
                    }
                }
                if (CmdletFound == false)
                {
                    //Add cmdlet from help to code one and color it.
                    CmdletHelp = GetExistingHelpInfo(CmdletHelp, nameNode.InnerText.Trim(), path);


                    //Start building the Cmdlet navigation tree
                    TreeViewItem Node = new TreeViewItem();

                    Node.Header = nameNode.InnerText.Trim();
                    // Brushes MyBrush = "#FF363B44";
                    //MyBrush = 5;

                    Node.Foreground         = Brushes.Red;
                    Node.FontWeight         = FontWeights.Bold;
                    MainWindow.ObsoleteInfo = true;


                    TreeViewItem ParameterNode = new TreeViewItem();
                    TreeViewItem ExamplesNode  = new TreeViewItem();
                    TreeViewItem LinksNode     = new TreeViewItem();
                    //add the Parameters record to the tree
                    if (CmdletHelp.ParameterDecription != null)
                    {
                        foreach (parameterDecription nodeparameterDesc in CmdletHelp.ParameterDecription)
                        {
                            TreeViewItem paramItem = new TreeViewItem();
                            paramItem.Header        = (nodeparameterDesc.Name);
                            paramItem.DataContext   = nodeparameterDesc;
                            paramItem.Foreground    = Brushes.Red;
                            paramItem.FontWeight    = FontWeights.Bold;
                            MainWindow.ObsoleteInfo = true;
                            ParameterNode.Items.Add(paramItem);
                        }
                    }
                    ParameterNode.Header      = "Parameters";
                    ParameterNode.Foreground  = Brushes.Red;
                    ParameterNode.FontWeight  = FontWeights.Bold;
                    ParameterNode.DataContext = CmdletHelp.ParameterDecription;
                    ExamplesNode.Header       = "Examples";
                    ExamplesNode.Foreground   = Brushes.Red;
                    ExamplesNode.FontWeight   = FontWeights.Bold;
                    ExamplesNode.DataContext  = new Collection <example>();
                    if (CmdletHelp.Examples != null)
                    {
                        ExamplesNode.DataContext = CmdletHelp.Examples;
                        foreach (example examp in CmdletHelp.Examples)
                        {
                            TreeViewItem exmpNode = new TreeViewItem();
                            exmpNode.DataContext = examp;
                            exmpNode.Foreground  = Brushes.Red;
                            exmpNode.FontWeight  = FontWeights.Bold;
                            exmpNode.Header      = examp.ExampleName;
                            ExamplesNode.Items.Add(exmpNode);
                        }
                    }

                    LinksNode.Header      = "Related Links";
                    LinksNode.Foreground  = Brushes.Red;
                    LinksNode.FontWeight  = FontWeights.Bold;
                    LinksNode.DataContext = new Collection <relatedlink>();
                    if (CmdletHelp.RelatedLinks != null)
                    {
                        LinksNode.DataContext = CmdletHelp.RelatedLinks;
                        foreach (relatedlink examp in CmdletHelp.RelatedLinks)
                        {
                            TreeViewItem exmpNode = new TreeViewItem();
                            exmpNode.DataContext = examp;
                            exmpNode.Foreground  = Brushes.Red;
                            exmpNode.FontWeight  = FontWeights.Bold;
                            exmpNode.Header      = examp.LinkText;
                            LinksNode.Items.Add(exmpNode);
                        }
                    }
                    Node.Items.Add(ParameterNode);
                    Node.Items.Add(ExamplesNode);
                    Node.Items.Add(LinksNode);
                    //  Node.Header = CmdletHelp.CmdletName;
                    Node.DataContext = CmdletHelp;

                    //    TreeViewItem PsSnapinNode = new TreeViewItem();

                    MainWindow.PsSnapinNode.Items.Add(Node);
                    //Cmdlets.Add(CmdletHelp);
                }
            }
            // return CodeCmdlets;
        }
Exemple #3
0
        /// <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 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;
                    }
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// This routine is used to create the one Cmdlet help MAML
        /// at a time.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="CmdletHelp"></param>
        public void SaveHelpFileBody(XmlWriter writer, cmdletDescription CmdletHelp)
        {
            try
            {
                writer.WriteRaw("<command:command xmlns:maml=\"http://schemas.microsoft.com/maml/2004/10\" xmlns:command=\"http://schemas.microsoft.com/maml/dev/command/2004/10\" xmlns:dev=\"http://schemas.microsoft.com/maml/dev/2004/10\">\r\n");
                writer = MainWindow.helpWriter.writeCmdletDetails(writer, CmdletHelp);

                //Add Syntax section <command:syntax>
                writer.WriteRaw("	<command:syntax>");

                Collection <parameterDecription> ParamDescription  = CmdletHelp.ParameterDecription;
                Collection <parameterSet>        HelpParameterSets = CmdletHelp.ParameterSets;
                //Iterate through the Syntax section and add Syntax items.
                //foreach (parameterset in paramDescription.ParameterSets[0].Parameters[0].Name
                if (HelpParameterSets != null)
                {
                    foreach (parameterSet HelpParameterSet in HelpParameterSets)
                    {
                        writer.WriteRaw("		<command:syntaxItem>\r\n");
                        //Cdmlet Name.
                        writer.WriteRaw("			<maml:name>");
                        writer.WriteRaw(CmdletHelp.CmdletName);
                        writer.WriteRaw("</maml:name>\r\n");
                        // writer.WriteRaw("		<!--New Syntax Item-->\r\n");
                        if (HelpParameterSet.Parameters != null)
                        {
                            foreach (parametersetParameter HelpParameter in HelpParameterSet.Parameters)
                            {
                                foreach (parameterDecription param in ParamDescription)
                                {
                                    if (param.Name.ToLower() == HelpParameter.Name.ToLower())
                                    {
                                        writer = MainWindow.helpWriter.createSyntaxItem(writer, param, CmdletHelp);
                                        break;
                                    }
                                }
                            }
                        }
                        //End <command:syntaxItem>
                        writer.WriteRaw("		</command:syntaxItem>\r\n");
                    }
                }
                else
                {
                    writer.WriteRaw("		<command:syntaxItem>\r\n");
                    writer.WriteRaw("		</command:syntaxItem>\r\n");
                }


                writer.WriteRaw("	</command:syntax>\r\n");
                //writer.WriteRaw("	</command:syntax>\r\n");

                //Add Parameters section <command:parameters>
                writer.WriteRaw("	<command:parameters>\r\n");
                //writer.WriteComment("Parameters section");

                //Iterate through the parameters section and add parameters Items.


                foreach (parameterDecription parameter in ParamDescription)
                {
                    writer = MainWindow.helpWriter.createParameters(writer, parameter);
                }


                writer.WriteRaw("	</command:parameters>\r\n");


                //Input Object Section
                writer = MainWindow.helpWriter.createInputSection(writer, CmdletHelp);

                //Output Object Section
                writer = MainWindow.helpWriter.createOutputSection(writer, CmdletHelp);


                // Error Section (Static section not used)
                //<command:terminatingErrors />
                //<command:nonTerminatingErrors />
                writer.WriteRaw("	<command:terminatingErrors>\r\n");
                //writer.WriteComment("Terminating errors section");
                writer.WriteRaw("	</command:terminatingErrors>\r\n");
                writer.WriteRaw("	<command:nonTerminatingErrors>\r\n");
                //writer.WriteComment("Non terminating errors section");
                writer.WriteRaw("	</command:nonTerminatingErrors>\r\n");


                //AlertSet  <!-- Notes section  -->
                writer = MainWindow.helpWriter.createAlertSetSection(writer, CmdletHelp);

                //Examples section.
                //Examples header goes here <command:examples>
                writer.WriteRaw("	<command:examples>\r\n");

                //Iterate through all the examples here
                if (CmdletHelp.Examples != null)
                {
                    foreach (example ExampleRecord in CmdletHelp.Examples)
                    {
                        writer = MainWindow.helpWriter.createExampleItemSection(writer, ExampleRecord);
                        //End examples section
                    }
                }
                writer.WriteRaw("	</command:examples>\r\n");


                //Links section
                // <maml:relatedLinks>
                writer.WriteRaw("	<maml:relatedLinks>\r\n");
                //Iterate through the links

                if (CmdletHelp.RelatedLinks != null)
                {
                    foreach (relatedlink RelatedLinkRecord in CmdletHelp.RelatedLinks)
                    {
                        writer = MainWindow.helpWriter.createLinksSection(writer, RelatedLinkRecord);
                    }
                }
                writer.WriteRaw("	</maml:relatedLinks>\r\n");

                //Write the end node for the starting <command:command> node.
                //writer.WriteRaw();
                writer.WriteRaw("</command:command>\r\n");
                //  }

                //Write the help file.

                //  }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "Error writing the XML file", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //FailedToWrite = true;
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Write the Cmdlet Parameter Sets syntax.
        /// </summary>
        /// <param name="CmdletHelp"></param>
        /// <returns></returns>
        public static String WriteSyntax(cmdletDescription CmdletHelp)
        {
            String Syntax = "";

            if (CmdletHelp.ParameterSets != null)
            {
                foreach (parameterSet parSet in CmdletHelp.ParameterSets)
                {
                    Syntax += "    " + CmdletHelp.CmdletName + " ";
                    foreach (parametersetParameter ParameterName in parSet.Parameters)
                    {
                        foreach (parameterDecription param in CmdletHelp.ParameterDecription)
                        {
                            if (param.Name == ParameterName.Name)
                            {
                                if (param.isMandatory && param.Position.ToLower() != "named")
                                {
                                    Syntax += "[-" + param.Name + "] <" + param.ParameterType + "> ";
                                }
                                else if (param.isMandatory && param.Position.ToLower() == "named")
                                {
                                    Syntax += "-" + param.Name + " <" + param.ParameterType + "> ";
                                }
                                else if (!param.isMandatory && param.Position.ToLower() != "named")
                                {
                                    Syntax += "[[-" + param.Name + "] <" + param.ParameterType + ">] ";
                                }
                                else if (!param.isMandatory && param.Position == "named")
                                {
                                    Syntax += "[-" + param.Name + " <" + param.ParameterType + ">] ";
                                }
                            }
                        }
                    }
                    Syntax += "\r\n";
                }
            }
            else
            {
                foreach (parameterDecription param in CmdletHelp.ParameterDecription)
                {
                    if (param.isMandatory && param.Position.ToLower() != "named")
                    {
                        Syntax += "[-" + param.Name + "] <" + param.ParameterType + "> ";
                    }
                    else if (param.isMandatory && param.Position.ToLower() == "named")
                    {
                        Syntax += "-" + param.Name + " <" + param.ParameterType + "> ";
                    }
                    else if (!param.isMandatory && param.Position.ToLower() != "named")
                    {
                        Syntax += "[[-" + param.Name + "] <" + param.ParameterType + ">] ";
                    }
                    else if (!param.isMandatory && param.Position == "named")
                    {
                        Syntax += "[-" + param.Name + " <" + param.ParameterType + ">] ";
                    }
                }
            }

            return(Syntax);
        }