public XmlWriter createAlertSetSection( XmlWriter writer, cmdletDescription result )
        {
            try
            {
                //Start AlertSet section
                writer.WriteRaw( "	<maml:alertSet>\r\n" );
                //writer.WriteComment("Notes Secion");
                writer.WriteRaw( "		<maml:title></maml:title>\r\n" );
                writer.WriteRaw( "		<maml:alert>\r\n" );
                writer.WriteRaw( "			<maml:para>" );
                //writer.WriteComment("Note Details");
                writer.WriteRaw( HttpUtility.HtmlEncode( result.Note ) );
                writer.WriteRaw( "</maml:para>\r\n" );
                writer.WriteRaw( "		</maml:alert>\r\n" );

                //End AlertSet section
                writer.WriteRaw( "	</maml:alertSet>\r\n" );

                //<maml:alertSet>
                //  <maml:title></maml:title>
                //  <maml:alert>
                //    <maml:para>
                //      <!-- Note details-->
                //    </maml:para>
                //  </maml:alert>
                //  <maml:alert>
                //    <maml:para></maml:para>
                //  </maml:alert>
                //</maml:alertSet>
            }
            catch ( Exception ex )
            {
                MessageBox.Show( ex.Message, "Error writing the XML File.", MessageBoxButtons.OK, MessageBoxIcon.Warning );
            }

            return writer;
        }
        /// <summary>
        ///   This routine exports the XML file for one Cmdlet at a time.
        /// </summary>
        /// <param name="sender"> </param>
        /// <param name="e"> </param>
        public void ExportXml_Click( object sender, RoutedEventArgs e )
        {
            var CmdletHelp = new cmdletDescription();

            try
            {
                if ( NavigationControl1.CmdletTreeView.Items.Count > 0 )
                {
                    //Check where the selection is made and find the parent cmdlet name.
                    if ( NavigationControl1.CmdletTreeView.SelectedValue != null )
                    {
                        var SelectedNode = (TreeViewItem) NavigationControl1.CmdletTreeView.SelectedItem;
                        var SelectedValue = (String) SelectedNode.Header;
                        switch ( SelectedValue )
                        {
                            case "Examples":
                                SelectedNode = (TreeViewItem) SelectedNode.Parent;
                                CmdletHelp = (cmdletDescription) SelectedNode.DataContext;
                                break;
                            case "Parameters":
                                SelectedNode = (TreeViewItem) SelectedNode.Parent;
                                CmdletHelp = (cmdletDescription) SelectedNode.DataContext;

                                break;
                            case "Related Links":
                                SelectedNode = (TreeViewItem) SelectedNode.Parent;
                                CmdletHelp = (cmdletDescription) SelectedNode.DataContext;
                                break;
                            case "Decription":
                                SelectedNode = (TreeViewItem) SelectedNode.Parent;
                                CmdletHelp = (cmdletDescription) SelectedNode.DataContext;
                                ;
                                break;
                            default:
                                CmdletHelp = CheckTheType();
                                break;
                        }
                    }
                }
                if ( CmdletHelp.CmdletName != null )
                {
                    XmlWriter writer = null;
                    var settings = new XmlWriterSettings();
                    settings.Indent = true;
                    settings.IndentChars = ( "    " );
                    settings.NewLineHandling = NewLineHandling.None;

                    settings.ConformanceLevel = ConformanceLevel.Document;

                    try
                    {
                        // Configure open file dialog box
                        var dlg = new SaveFileDialog();
                        //OpenFileDialog dlg = new OpenFileDialog();
                        var SelectedSnapin = new List<SnapinView>();
                        SelectedSnapin = (List<SnapinView>) MainWindow.MainGrid1.PsSnapinList.SelectedItem;

                        dlg.FileName = CmdletHelp.CmdletName + "-Help"; // Default file name
                        dlg.DefaultExt = ".xml"; // Default file extension
                        dlg.Filter = "PowerShell Help Xml files (.xml)|*.xml"; // Filter files by extension

                        // Show open file dialog box
                        DialogResult? result = dlg.ShowDialog();

                        // Process open file dialog box results
                        if ( result.Value ==
                             DialogResult.OK )
                        {
                            // Open document
                            MainWindow.HelpFilePath = dlg.FileName;
                            MainWindow.OldHelpFileExist = true;
                        }
                    }
                    catch ( Exception ex )
                    {
                        MessageBox.Show( ex.Message,
                                         "Error loading the help file.",
                                         MessageBoxButtons.OK,
                                         MessageBoxIcon.Warning );
                    }

                    if ( MainWindow.OldHelpFileExist )
                    {
                        writer = XmlWriter.Create( MainWindow.HelpFilePath, settings );
                        SaveHelpFileBody( writer, CmdletHelp );
                        writer.Flush();
                        writer.Close();
                        MessageBox.Show( MainWindow.HelpFilePath + "\n\nFile saved.",
                                         "File saved",
                                         MessageBoxButtons.OK,
                                         MessageBoxIcon.Information );
                    }
                }
                else
                {
                    MessageBox.Show( "Cannot save contents of the selected node.\nNo file has been saved.",
                                     "No file has been saved.",
                                     MessageBoxButtons.OK,
                                     MessageBoxIcon.Warning );
                }
            }
            catch ( Exception ex )
            {
                MessageBox.Show( ex.Message, "Application error.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
            }
        }
        /// <summary>
        ///   Create the text viewer of the selected Cmdlet.
        ///   This is a simple function to help me create a txt view
        ///   of the get-help functionality on the cmdlet.
        /// </summary>
        /// <param name="sender"> </param>
        /// <param name="e"> </param>
        public void ExportTextFile_Click( object sender, RoutedEventArgs e )
        {
            var CmdletHelp = new cmdletDescription();

            try
            {
                if ( NavigationControl1.CmdletTreeView.Items.Count > 0 )
                {
                    if ( NavigationControl1.CmdletTreeView.SelectedValue != null )
                    {
                        var SelectedNode = (TreeViewItem) NavigationControl1.CmdletTreeView.SelectedItem;
                        var SelectedValue = (String) SelectedNode.Header;
                        switch ( SelectedValue )
                        {
                            case "Examples":
                                SelectedNode = (TreeViewItem) SelectedNode.Parent;
                                CmdletHelp = (cmdletDescription) SelectedNode.DataContext;
                                break;
                            case "Parameters":
                                SelectedNode = (TreeViewItem) SelectedNode.Parent;
                                CmdletHelp = (cmdletDescription) SelectedNode.DataContext;
                                break;
                            case "Related Links":
                                SelectedNode = (TreeViewItem) SelectedNode.Parent;
                                CmdletHelp = (cmdletDescription) SelectedNode.DataContext;
                                break;
                            case "Decription":
                                SelectedNode = (TreeViewItem) SelectedNode.Parent;
                                CmdletHelp = (cmdletDescription) SelectedNode.DataContext;
                                ;
                                break;
                            default:
                                CmdletHelp = CheckTheType();
                                break;
                        }
                    }
                }
                if ( CmdletHelp.CmdletName != null )
                {
                    String textStream = "";

                    try
                    {
                        textStream += "NAME\r\n" + CmdletHelp.CmdletName + "\r\n\r\n";
                        textStream += "SYNOPSIS\r\n" + CmdletHelp.ShortDescription + "\r\n\r\n";
                        textStream += "SYNTAX\r\n";
                        textStream += writeSyntax( CmdletHelp ) + "\r\n";
                        textStream += "DETAILED DESCRIPTION\r\n" + CmdletHelp.LongDescription + "\r\n\r\n";
                        textStream += "PARAMETERS\r\n";
                        String paramStream = "";
                        foreach ( parameterDecription param in CmdletHelp.ParameterDecription )
                        {
                            paramStream = writeParameter( param );
                            textStream += paramStream;
                        }
                        textStream += "INPUT TYPE\r\n" + CmdletHelp.InputType + "\r\n\r\n";
                        textStream += "INPUT TYPE DESCRIPTION\r\n" + CmdletHelp.InputDesc + "\r\n\r\n";
                        textStream += "RETURN TYPE\r\n" + CmdletHelp.OutputType + "\r\n\r\n";
                        textStream += "RETURN TYPE DESCRIPTION\r\n" + CmdletHelp.OutputDesc + "\r\n\r\n";
                        textStream += "NOTES\r\n" + CmdletHelp.Note + "\r\n\r\n";
                        textStream += "EXAMPLES\r\n\r\n";
                        if ( CmdletHelp.Examples != null )
                        {
                            foreach ( example examp in CmdletHelp.Examples )
                            {
                                String exampleStream = writeExample( examp );
                                textStream += exampleStream;
                            }
                        }
                        textStream += "RELATED LINKS\r\n";
                        if ( CmdletHelp.RelatedLinks != null )
                        {
                            foreach ( relatedlink link in CmdletHelp.RelatedLinks )
                            {
                                textStream += "    " + link.LinkText + "\r\n";
                            }
                        }

                        var SaveDialog = new SaveFileDialog();
                        SaveDialog.DefaultExt = "txt";
                        SaveDialog.FileName = CmdletHelp.CmdletName;
                        SaveDialog.Filter = "Text Files (*.txt)|*.txt";
                        SaveDialog.Title = CmdletHelp.CmdletName;
                        DialogResult result = SaveDialog.ShowDialog();

                        if ( result == DialogResult.OK )
                        {
                            string FileName = SaveDialog.FileName;

                            using ( var sw = new StreamWriter( FileName ) )
                            {
                                // Add some text to the file.
                                //sw.AutoFlush;
                                sw.Write( textStream );
                                sw.Close();

                                // Loading the CS fileName Created in Notepad.
                                var newProcess = new Process();
                                newProcess.StartInfo.FileName = "notepad.exe";
                                newProcess.StartInfo.Arguments = FileName;
                                newProcess.Start();
                            }
                        }
                    }
                    catch ( Exception ex )
                    {
                        MessageBox.Show( ex.Message,
                                         "Error loading the help file.",
                                         MessageBoxButtons.OK,
                                         MessageBoxIcon.Warning );
                    }
                }
                else
                {
                    MessageBox.Show( "No valid cmdlet name has been selected.\nPlease select the correct Cmdlet name.",
                                     "Not a valid selection.",
                                     MessageBoxButtons.OK,
                                     MessageBoxIcon.Warning );
                }
            }
            catch ( Exception ex )
            {
                MessageBox.Show( ex.Message, "Application error.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
            }
        }
        /// <summary>
        ///   Check the type of the selected item on the tree view.
        ///   This is needed to determine different functionality such
        ///   as copy and paste. It lets me know which type of node on the tree
        ///   is slected.
        /// </summary>
        /// <returns> </returns>
        public cmdletDescription CheckTheType()
        {
            var CmdletHelp = new cmdletDescription();
            var SelectedNode = (TreeViewItem) NavigationControl1.CmdletTreeView.SelectedItem;

            if ( SelectedNode != null )
            {
                if ( SelectedNode.DataContext != null )
                {
                    if ( SelectedNode.DataContext is parameterDecription )
                    {
                        SelectedNode = (TreeViewItem) SelectedNode.Parent;
                        SelectedNode = (TreeViewItem) SelectedNode.Parent;
                        CmdletHelp = (cmdletDescription) SelectedNode.DataContext;
                    }
                    else if ( SelectedNode.DataContext is example )
                    {
                        SelectedNode = (TreeViewItem) SelectedNode.Parent;
                        SelectedNode = (TreeViewItem) SelectedNode.Parent;
                        CmdletHelp = (cmdletDescription) SelectedNode.DataContext;
                    }
                    else if ( SelectedNode.DataContext is relatedlink )
                    {
                        SelectedNode = (TreeViewItem) SelectedNode.Parent;
                        SelectedNode = (TreeViewItem) SelectedNode.Parent;
                        CmdletHelp = (cmdletDescription) SelectedNode.DataContext;
                    }
                    else if ( SelectedNode.DataContext is cmdletDescription )
                    {
                        CmdletHelp = (cmdletDescription) SelectedNode.DataContext;
                    }
                }
            }
            return CmdletHelp;
        }
        /// <summary>
        ///   Write the Cmdlet Parameter Sets syntax.
        /// </summary>
        /// <param name="CmdletHelp"> </param>
        /// <returns> </returns>
        public 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;
        }
        /// <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 )
            {
                MessageBox.Show( ex.Message, "Error writing the XML file", MessageBoxButtons.OK, MessageBoxIcon.Warning );
                //FailedToWrite = true;
                if ( writer != null )
                {
                    writer.Close();
                }
            }
        }
        public static void LoadPsNapin()
        {
            String PsSnapinModuleName;
            String PsSnapinName;
            // Make sure the correct PsSNapin is selected before executing this routine.
            if ( MainWindow.selectedModule == null
                    /*(this.MainGrid1.PsSnapinList.Items.Count == 0) || (this.MainGrid1.PsSnapinList.SelectedItems.Count == 0)*/ )
            {
                System.Windows.MessageBox.Show( "Select a PsSnapin before opening a help file.",
                                                "PsSnapin Not Selected",
                                                MessageBoxButton.OK,
                                                MessageBoxImage.Warning );
            }
            else
            {
                var myview = new ModuleObject();
                myview = MainWindow.selectedModule;
                //myview = (List<SnapinView>)MainGrid.PsSnapinList.SelectedItem;
                //Name of the Assembly
                PsSnapinModuleName = myview.Name;
                //Name of the Snapin
                PsSnapinName = myview.Name;
                //Load the proper UI grid and make the rest not visible.
                MainWindow.NavControl.CmdletTreeView.Items.Clear();
                MainWindow.PsSnapinNode = new TreeViewItem();
                MainWindow.CmdletsHelps = new Collection<cmdletDescription>();
                MainWindow.HeaderControl1.___Button__Save_File.Visibility = Visibility.Visible;
                MainWindow.HeaderControl1.___Button__SaveHelpFileAs.Visibility = Visibility.Visible;
                MainWindow.DescriptionControl1.Visibility = Visibility.Hidden;
                MainWindow.NavControl.NavigationGrid.Visibility = Visibility.Visible;
                MainWindow.ParametersControl1.Visibility = Visibility.Hidden;
                MainWindow.MainGrid1.Visibility = Visibility.Hidden;
                MainWindow.EmptyParameterControl1.Visibility = Visibility.Hidden;
                MainWindow.ExamplesControl1.Visibility = Visibility.Hidden;
                MainWindow.RelatedLinks1.Visibility = Visibility.Hidden;
                MainWindow.HeaderControl1.StartOverButton.Visibility = Visibility.Visible;
                //this.NavigationSplitter.Visibility = Visibility.Visible;
                //Not sure I still need this...
                MainWindow.HeaderControl1.StartOverButton.Width = 136;

                try
                {
                    //initialize the XMLHelper class
                    // this is needed to write the MAML file.
                    var xmlHelper = new XMLReaderHelper();

                    //Create a default RunspaceConfiguration
                    RunspaceConfiguration config = RunspaceConfiguration.Create();

                    //Add GetProcPSSnapIn01 to config.
                    PSSnapInException warning;
                    //Add non PowerShell code PS Snapins to the list.
                    //PowerShell's ones are loaded later.

                    // Add the AspenCmdlets snapin
                    //config.AddPSSnapIn("AspenCmdletManagement", out warning);

                    // Create a runspace.
                    // (Note that no PSHost instance is supplied in the CreateRunspace call
                    // so the default PSHost implementation is used.)
                    Runspace myRunSpace = RunspaceFactory.CreateRunspace( config );
                    myRunSpace.Open();

                    // Create a pipeline with get-comand -pssnapin the seleceted PsSnapin

                    //this.PsSnapinNameLabel.Content = "Loaded PsSnapin: " + PsSnapinName;
                    String MyInvokationScript = null;
                    if ( myview.ModuleType.ToLower() == "manifest" )
                    {
                        MyInvokationScript = "import-module -name " + PsSnapinName + "; " + "get-command -Module " +
                                             PsSnapinName;
                    }
                    else
                    {
                        // If this is a PowerShell Snapin, do not add it. We already have it.
                        if ( PsSnapinName != "Microsoft.PowerShell.Core" &&
                             PsSnapinName != "Microsoft.PowerShell.Host" &&
                             PsSnapinName != "Microsoft.PowerShell.Management" &&
                             PsSnapinName != "Microsoft.PowerShell.Security" &&
                             PsSnapinName != "Microsoft.PowerShell.Utility" &&
                             PsSnapinName != "Microsoft.WSMan.Management" )
                                // PsSnapinName != "AspenCmdletManagement")
                        {
                            config.AddPSSnapIn( PsSnapinName, out warning );

                            if ( warning != null )
                            {
                                // A warning is not expected, but if one is detected
                                // write the warning and return.
                                Console.Write( warning.Message );
                                return;
                            }
                        }
                        MyInvokationScript = "get-command -pssnapin " + PsSnapinName;
                    }

                    Pipeline pipeLine = myRunSpace.CreatePipeline( MyInvokationScript );

                    //PsCmdlets is the collection of all the CmdletInfo objects returned by GetCommand.
                    MainWindow.results = pipeLine.Invoke();
                    if ( MainWindow.results.Count == 0 )
                    {
                        return;
                    }

                    // Iterate through all the Cmdlets and populate the cmdletDescription help object (CmdletsHelps).

                    // Give the header of the tree view the name of the Snapin.
                    MainWindow.PsSnapinNode.Header = PsSnapinName;

                    // Objects read from the Spec data base.
                    var PSSpecParameterInfo = new Collection<PSObject>();
                    var PSSpecParameterSetEntries = new Collection<PSObject>();
                    var PSSpecCmdletInfo = new Collection<PSObject>();

                    //if we are in the online mode get the cmdlet names for the selected project.
                    //if (ProjectName != null && ProjectName != "")
                    //{
                    //    MyInvokationScript = "get-cmdlet -ProjectName \"" + ProjectName + "\"";
                    //    pipeLine = myRunSpace.CreatePipeline(MyInvokationScript);
                    //    PSSpecCmdletInfo = pipeLine.Invoke();

                    //    // Initialize a SpecCmdlet info record.
                    //    SpecCmdlet = new Microsoft.Aspen.CmdletManagement.AspenCmdlet();

                    //    // Get all the parameters in the project. This improves the db access performance.
                    //    MyInvokationScript = "Get-CmdletParameter -ProjectName \"" + ProjectName + "\"";
                    //    pipeLine = myRunSpace.CreatePipeline(MyInvokationScript);
                    //    PSSpecParameterInfo = pipeLine.Invoke();

                    //    // Get all the parameter set entries at once. This improves the db access performance.
                    //    MyInvokationScript = "Get-CmdletParameterSetEntry -ProjectName \"" + ProjectName + "\"";
                    //    pipeLine = myRunSpace.CreatePipeline(MyInvokationScript);
                    //    PSSpecParameterSetEntries = pipeLine.Invoke();
                    //}
                    //else
                    //{
                    // If this is offline, change the lable text note Original info rather then spec info
                    MainWindow.DescriptionControl1.OldInputTypeDescLable.Content = "Original Input Type Description";
                    MainWindow.DescriptionControl1.OldInputTypeLable.Content = "Original Input Type";
                    MainWindow.DescriptionControl1.ShortDescriptionLable_Copy1.Content = "Original Short Description";
                    MainWindow.DescriptionControl1.DetailedDescriptionLable_Copy.Content =
                            "Original Detailed Description";
                    MainWindow.DescriptionControl1.OldInputTypeDescLable.Content = "Original Input Type Description";
                    MainWindow.DescriptionControl1.OldOutputTypeLable.Content = "Original Return Type";
                    MainWindow.DescriptionControl1.OldOutputTypeDescLable.Content = "Original Return Type Description";
                    MainWindow.DescriptionControl1.OldNotesDescriptionLable.Content = "Original Notes";
                    MainWindow.ExamplesControl1.ExampleDescriptionLabel_Copy.Content = "Original Example Description";
                    MainWindow.RelatedLinks1.OldRelatedLinkLabel.Content = "Original Related Link";
                    MainWindow.ParametersControl1.OldParameterDescLable.Content = "Original Parameter Description";
                    MainWindow.ParametersControl1.OldGlobbingCheckBox.Content = "Original Globbing";
                    MainWindow.ParametersControl1.DefaultValueLable_Copy.Content = "Original Default Value";
                    //}

                    // iterate through the cmdlets info from code.
                    // foreach cmdlet in code update the tree.
                    // when you are done. do the remaining ones in help only or in spec only.
                    foreach ( PSObject psCmdletInfo in MainWindow.results )
                    {
                        //Get the CmdletHelp data from get-Command
                        var CmdletHelp = new cmdletDescription();

                        // this contain all the parameters in the cmdlet.
                        var parameterDescriptions = new Collection<parameterDecription>();

                        // CmdleHelp holds all info on the psCmdldetInfo in the foreach loop.
                        CmdletHelp.CmdletName = (String) psCmdletInfo.Members["Name"].Value;
                        if ( psCmdletInfo.Members["Verb"] == null )
                        {
                            String[] verbNoum = CmdletHelp.CmdletName.Split( '-' );
                            CmdletHelp.Verb = verbNoum[0];
                            CmdletHelp.Noun = verbNoum[1];
                        }
                        else
                        {
                            CmdletHelp.Verb = (String) psCmdletInfo.Members["Verb"].Value;
                            CmdletHelp.Noun = (String) psCmdletInfo.Members["Noun"].Value;
                        }

                        // SpecCmdlet = new Microsoft.Aspen.CmdletManagement.AspenCmdlet();

                        // If we are in the online mode, get the spec info for the code cmdlet we are working against.
                        //if (ProjectName != null && ProjectName != "")
                        //{
                        //    foreach (PSObject PSSpecCmdlet in PSSpecCmdletInfo)
                        //    {
                        //        //Fine the matching spec cmdlet record.
                        //        String SpecCmdletName = (String)PSSpecCmdlet.Members["Name"].Value;
                        //        if (SpecCmdletName == CmdletHelp.CmdletName)
                        //        {
                        //            //This is the cmdlet we want
                        //            SpecCmdlet = (Microsoft.Aspen.CmdletManagement.AspenCmdlet)PSSpecCmdlet.ImmediateBaseObject;
                        //        }
                        //    }
                        //}

                        // find the proper Spec Parameters and the spec parameter entries.
                        // I cannot initialize these collection in the if statement.
                        //Collection<Microsoft.Aspen.CmdletManagement.AspenCmdletParameter> SpecParameters = new Collection<Microsoft.Aspen.CmdletManagement.AspenCmdletParameter>();
                        //Collection<Microsoft.Aspen.CmdletManagement.AspenCmdletParameterSetEntry> SpecParameterSetEntries = new Collection<Microsoft.Aspen.CmdletManagement.AspenCmdletParameterSetEntry>();

                        //// If this is an online mode...
                        //if (ProjectName != null && ProjectName != "")
                        //{
                        //    //Retrieve the parameter info for the specific cmdlet
                        //    foreach (PSObject PSSpecParamInfo in PSSpecParameterInfo)
                        //    {
                        //        // Get the Spec Parameter and make sure it belongs to our cmdlet.
                        //        Microsoft.Aspen.CmdletManagement.AspenCmdletParameter SpecParameter = (Microsoft.Aspen.CmdletManagement.AspenCmdletParameter) PSSpecParamInfo.ImmediateBaseObject;
                        //        if (SpecParameter.CmdletName == SpecCmdlet.Name)
                        //        {
                        //            SpecParameters.Add(SpecParameter);
                        //        }
                        //    }

                        //    // Do the same for Parameter Set entries.
                        //    foreach (PSObject PSSpecParameterSetEntry in PSSpecParameterSetEntries)
                        //    {
                        //        Microsoft.Aspen.CmdletManagement.AspenCmdletParameterSetEntry SpecParameterSetEntry = (Microsoft.Aspen.CmdletManagement.AspenCmdletParameterSetEntry)PSSpecParameterSetEntry.ImmediateBaseObject;
                        //        if (SpecParameterSetEntry.CmdletName == SpecCmdlet.Name)
                        //        {
                        //            SpecParameterSetEntries.Add(SpecParameterSetEntry);
                        //        }
                        //    }

                        //}

                        // Set the spec info in the Old record. In the online mode Old mean spec
                        // In the offline mode, Old means Original (coming from the help file)
                        //CmdletHelp.OldShortDescription = SpecCmdlet.ShortDescription;
                        //CmdletHelp.OldLongDescription = SpecCmdlet.LongDescription;
                        //CmdletHelp.OldOutputType = SpecCmdlet.OutputObject;
                        //CmdletHelp.OldOutputDesc = SpecCmdlet.OutputObjectDescription;
                        //CmdletHelp.OldNote = SpecCmdlet.Notes;
                        //ParameterSets;
                        ReadOnlyCollection<CommandParameterSetInfo> ParameterSets = null;
                        try
                        {
                            ParameterSets =
                                    (ReadOnlyCollection<CommandParameterSetInfo>)
                                    psCmdletInfo.Members["ParameterSets"].Value;
                        }
                        catch ( Exception ex )
                        {
                            System.Windows.MessageBox.Show( CmdletHelp.CmdletName + ": " + ex.Message,
                                                            CmdletHelp.CmdletName + " failed to load the parametersets!" );
                            if ( CmdletHelp.ParameterSets == null )
                            {
                                var _ParameterSets = new Collection<parameterSet>();
                                CmdletHelp.ParameterSets = _ParameterSets;
                            }
                            //continue;
                        }
                        if ( ParameterSets != null )
                        {
                            //Iterate through all the ParameterSets and get the parameter records.
                            foreach ( CommandParameterSetInfo ParameterSet in ParameterSets )
                            {
                                var helpParameterSet = new parameterSet();
                                var parameterSetParameters = new Collection<parametersetParameter>();

                                helpParameterSet.Name = ParameterSet.Name;

                                //Get the parameters in each parameter set and disregard the common ones.
                                //Also remove duplicates within the parameter sets.
                                ReadOnlyCollection<CommandParameterInfo> Parameters = ParameterSet.Parameters;
                                var testParameters = new Collection<parametersetParameter>();
                                foreach ( CommandParameterInfo Parameter in Parameters )
                                {
                                    var ParametersetParameter = new parametersetParameter();
                                    var ParameterDescriptionInstance = new parameterDecription();

                                    String ParameterName = Parameter.Name;
                                    string ParameterNameLower = ParameterName.ToLower();
                                    //Skip the Ubiquiteous parameters.
                                    if ( ParameterNameLower != "verbose" && ParameterNameLower != "debug"
                                         && ParameterNameLower != "erroraction" && ParameterNameLower != "errorvariable"
                                         && ParameterNameLower != "outvariable" && ParameterNameLower != "outbuffer"
                                         && ParameterNameLower != "warningvariable" &&
                                         ParameterNameLower != "warningaction"
                                            )
                                    {
                                        var parSetParameter = new parametersetParameter();

                                        parSetParameter.Name = ParameterName;
                                        //Microsoft.Aspen.CmdletManagement.AspenCmdletParameter SpecParam = new Microsoft.Aspen.CmdletManagement.AspenCmdletParameter();
                                        //Microsoft.Aspen.CmdletManagement.AspenCmdletParameterSetEntry SpecParamEntry = new Microsoft.Aspen.CmdletManagement.AspenCmdletParameterSetEntry();

                                        ////find the matching parameter from the spec data base.
                                        //// We do not care about exact match. This is the 90% case if not all the metadata
                                        //// are identical, we do not care. we take the last hit.
                                        //foreach ( Microsoft.Aspen.CmdletManagement.AspenCmdletParameter specparam in SpecParameters)
                                        //{
                                        //    if (specparam.Name == ParameterName)
                                        //    {
                                        //        //This is the one we want.
                                        //        SpecParam = specparam;
                                        //    }
                                        //}

                                        // Do the same for the paramter set entry. Not all the metadata are available in the
                                        // paramerter entry. I need to find the matching parameter set entry as well.
                                        // Here I also do a last match as well.
                                        //foreach (Microsoft.Aspen.CmdletManagement.AspenCmdletParameterSetEntry parmentry in SpecParameterSetEntries)
                                        //{
                                        //    if (parmentry.ParameterName == ParameterName)
                                        //    {
                                        //        SpecParamEntry = parmentry;
                                        //    }

                                        //}

                                        testParameters.Add( parSetParameter );
                                        //Start building the Help ParameterSet Object.
                                        Boolean ParameterExist = false;
                                        ParameterDescriptionInstance.MismatchInfo = false;
                                        ParametersetParameter.Name = ParameterName;
                                        ParameterDescriptionInstance.Name = ParameterName;
                                        ParameterDescriptionInstance.VFRA = Parameter.ValueFromRemainingArguments;
                                        //if (SpecParamEntry.ValueFromRemainingArguments != null)
                                        //{
                                        //    ParameterDescriptionInstance.SpecVFRA = (bool)SpecParamEntry.ValueFromRemainingArguments;
                                        //}

                                        if ( ParameterDescriptionInstance.VFRA !=
                                             ParameterDescriptionInstance.SpecVFRA )
                                        {
                                            ParameterDescriptionInstance.MismatchInfo = true;
                                        }

                                        ParameterDescriptionInstance.VFP = Parameter.ValueFromPipeline;
                                        //if (SpecParamEntry.ValueFromPipeline != null)
                                        //{
                                        //    ParameterDescriptionInstance.SpecVFP = (bool)SpecParamEntry.ValueFromPipeline;
                                        //}

                                        if ( ParameterDescriptionInstance.VFP !=
                                             ParameterDescriptionInstance.SpecVFP )
                                        {
                                            ParameterDescriptionInstance.MismatchInfo = true;
                                        }

                                        ParameterDescriptionInstance.VFPBPN = Parameter.ValueFromPipelineByPropertyName;
                                        //if (SpecParamEntry.ValueFromPipelineByPropertyName != null)
                                        //{
                                        //    ParameterDescriptionInstance.SpecVFPBPN = (bool)SpecParamEntry.ValueFromPipelineByPropertyName;
                                        //}

                                        if ( ParameterDescriptionInstance.VFPBPN !=
                                             ParameterDescriptionInstance.SpecVFPBPN )
                                        {
                                            ParameterDescriptionInstance.MismatchInfo = true;
                                        }

                                        ParameterDescriptionInstance.isMandatory = Parameter.IsMandatory;
                                        //if (SpecParamEntry.Mandatory != null)
                                        //{
                                        //    ParameterDescriptionInstance.SpecisMandatory = (bool)SpecParamEntry.Mandatory;
                                        //}

                                        if ( ParameterDescriptionInstance.isMandatory !=
                                             ParameterDescriptionInstance.SpecisMandatory )
                                        {
                                            ParameterDescriptionInstance.MismatchInfo = true;
                                        }

                                        ParameterDescriptionInstance.isDynamic = Parameter.IsDynamic;
                                        //if (SpecParam.Dynamic != null)
                                        //{
                                        //    ParameterDescriptionInstance.SpecisDynamic = (bool)SpecParam.Dynamic;
                                        //}

                                        if ( ParameterDescriptionInstance.isDynamic !=
                                             ParameterDescriptionInstance.SpecisDynamic )
                                        {
                                            ParameterDescriptionInstance.MismatchInfo = true;
                                        }

                                        String[] test = Parameter.ParameterType.ToString().Split( '.' );
                                        int length = test.Length;
                                        ParameterDescriptionInstance.ParameterType = test[length - 1];
                                        length = ParameterDescriptionInstance.ParameterType.Length;
                                        if ( ParameterDescriptionInstance.ParameterType[length - 1] == ']' &&
                                             ParameterDescriptionInstance.ParameterType[length - 2] != '[' )
                                        {
                                            ParameterDescriptionInstance.ParameterType =
                                                    ParameterDescriptionInstance.ParameterType.TrimEnd( ']' );
                                        }
                                        //ParameterDescriptionInstance.ParameterType = Parameter.ParameterType.Name;

                                        //if (SpecParam.Type != null)
                                        //{
                                        //    test = (String[])SpecParam.Type.ToString().Split('.');
                                        //    length = test.Length;
                                        //    ParameterDescriptionInstance.SpecParameterType = test[length - 1];
                                        //}

                                        if ( ParameterDescriptionInstance.ParameterType !=
                                             ParameterDescriptionInstance.SpecParameterType )
                                        {
                                            ParameterDescriptionInstance.MismatchInfo = true;
                                        }

                                        //If the parameter is not positioned call it named else give it the
                                        //position and convert it to String
                                        //if (SpecParamEntry.Position != null)
                                        //{
                                        //    ParameterDescriptionInstance.SpecPosition = (int)SpecParamEntry.Position;
                                        //}
                                        if ( Parameter.Position < 0 )
                                        {
                                            ParameterDescriptionInstance.Position = "named";
                                        }
                                        else
                                        {
                                            // for some reason in the Help documentation the writers like posinal value to start
                                            // wit one. This is why we increment the numbet by one. Any code/MAML comparer tool need to
                                            // make a note of this.
                                            ParameterDescriptionInstance.Position =
                                                    ( Parameter.Position + 1 ).ToString();
                                        }

                                        //ParameterDescriptionInstance.OldDescription = SpecParam.Description;

                                        //if (SpecParam.AllowGlobbing != null)
                                        //{
                                        //    ParameterDescriptionInstance.OldGlobbing = (bool)SpecParam.AllowGlobbing;
                                        //}

                                        if ( ParameterDescriptionInstance.Globbing !=
                                             ParameterDescriptionInstance.OldGlobbing )
                                        {
                                            ParameterDescriptionInstance.MismatchInfo = true;
                                        }

                                        //Collect the Attributes on the parameters and build them.
                                        // these are not consumed anywhere except as an FYI to the writer.
                                        // We do not store this data in the MAML.
                                        var Attributes = new Collection<parameterAttribute>();
                                        foreach ( Attribute ParameterAttribute in Parameter.Attributes )
                                        {
                                            try
                                            {
                                                var paramAttribute = new parameterAttribute();
                                                paramAttribute.Attribute = ParameterAttribute.ToString();
                                                Attributes.Add( paramAttribute );
                                            }
                                            catch ( Exception ex )
                                            {
                                                System.Windows.MessageBox.Show( ex.Message,
                                                                                "Error loading the parameter attributes.",
                                                                                MessageBoxButton.OK,
                                                                                MessageBoxImage.Warning );
                                            }
                                        }
                                        ParameterDescriptionInstance.Attributes = Attributes;

                                        //Collect the Aliases on the parameter and build the Aliases record.
                                        // Again, this is not used in MAML. Just as an FYI to the writer.
                                        var Aliases = new Collection<parameterAlias>();
                                        foreach ( String ParameterAlias in Parameter.Aliases )
                                        {
                                            var paramAlias = new parameterAlias();
                                            paramAlias.Alias = ParameterAlias;
                                            Aliases.Add( paramAlias );
                                        }
                                        ParameterDescriptionInstance.Aliases = Aliases;

                                        //only add non duplicate parameters to the Parm description record
                                        //for this cmdlet.
                                        foreach ( parameterDecription param in parameterDescriptions )
                                        {
                                            if ( param.Name ==
                                                 ParameterDescriptionInstance.Name )
                                            {
                                                ParameterExist = true;
                                            }
                                        }
                                        if ( !ParameterExist )
                                        {
                                            parameterDescriptions.Add( ParameterDescriptionInstance );
                                        }
                                    }
                                }
                                if ( testParameters != null )
                                {
                                    helpParameterSet.Parameters = testParameters;
                                }

                                // Initialize the record if there were no parameters in this cmdlet.
                                if ( CmdletHelp.ParameterSets == null )
                                {
                                    var _ParameterSets = new Collection<parameterSet>();
                                    CmdletHelp.ParameterSets = _ParameterSets;
                                }
                                CmdletHelp.ParameterSets.Add( helpParameterSet ); // = tempParSet;
                            }
                        }

                        //Update the global CmdletHelp record with info from code
                        //before we read the UA info from the help file if one exists.
                        //We only rely on code for the Cmdlet Help metadata.
                        CmdletHelp.ParameterDecription = parameterDescriptions;

                        //if a help file is loaded, then read its contents and add it to
                        //the CmdletHelp record.
                        if ( MainWindow.OldHelpFileExist )
                        {
                            CmdletHelp = XMLReaderHelper.GetExistingHelpInfo( CmdletHelp,
                                                                              CmdletHelp.CmdletName,
                                                                              MainWindow.HelpFilePath );
                        }

                        //Start building the Cmdlet navigation tree
                        var Node = new TreeViewItem();
                        // The header is the display text for this node.
                        Node.Header = CmdletHelp.CmdletName;

                        // Check if detailed description and Short description have text, then consider
                        // this record is complete. This is based on the speced behavior.
                        // Make the text green and not bold.
                        if ( ( CmdletHelp.LongDescription != null || CmdletHelp.LongDescription != "" ) &&
                             ( CmdletHelp.ShortDescription != null || CmdletHelp.ShortDescription != "" ) )
                        {
                            Node.Foreground = Brushes.Green;
                        }

                        // This boolean flag is used to annotate that there is a mismatch in the parameter metadata
                        // between spec and code in the online mode.
                        Boolean paramMistmatch = false;

                        var ParameterNode = new TreeViewItem();
                        var ExamplesNode = new TreeViewItem();
                        var LinksNode = new TreeViewItem();

                        // Add the Parameters record to the tree.
                        // Start with the assumption that the parameter is complete.
                        ParameterNode.Foreground = Brushes.Green;
                        foreach ( parameterDecription nodeparameterDesc in CmdletHelp.ParameterDecription )
                        {
                            var paramItem = new TreeViewItem();
                            paramItem.Header = ( nodeparameterDesc.Name );
                            paramItem.DataContext = nodeparameterDesc;

                            // If the parameter item under the Parameters node has description then
                            // mark it in green otherwise mark it in black to indicate the contents are not complete.
                            if ( ( nodeparameterDesc.NewDescription == null || nodeparameterDesc.NewDescription == "" ) )
                            {
                                paramItem.Foreground = Brushes.Black;
                                ParameterNode.Foreground = Brushes.Black;
                            }
                            else
                            {
                                paramItem.Foreground = Brushes.Green;
                            }

                            // if this is a parameter that only exist in the help MAML file and not
                            // in code, then mark it in bold red
                            if ( nodeparameterDesc.HelpOnlyParameter )
                            {
                                paramItem.Foreground = Brushes.Red;
                                paramItem.FontWeight = FontWeights.Bold;
                                // Set this ObsoleteInfo flag to true to indicate that
                                // we do have onsolete info in the tree.
                                // We use this flag later to warn the user that saving the MAML file
                                // will cause them to loose this info.
                                MainWindow.ObsoleteInfo = true;
                                Node.Foreground = Brushes.Red;
                            }

                            // If we are in the online mode we check if there were mismatch info reported and we mark them red.
                            if ( MainWindow.ProjectName != null &&
                                 MainWindow.ProjectName != "" )
                            {
                                if ( nodeparameterDesc.MismatchInfo )
                                {
                                    if ( ( paramItem.Header ).ToString().ToLower() != "whatif" &&
                                         ( paramItem.Header ).ToString().ToLower() != "confirm" )
                                    {
                                        paramItem.Foreground = Brushes.Red;
                                        paramItem.FontWeight = FontWeights.Normal;
                                        // This falg is set to mark the parent Parameters node red as well.
                                        paramMistmatch = true;
                                    }
                                }
                            }
                            ParameterNode.Items.Add( paramItem );
                        }

                        ParameterNode.Header = "Parameters";
                        ParameterNode.DataContext = CmdletHelp.ParameterDecription;

                        // Mark the Parameters node red in cas of Mismatch
                        if ( paramMistmatch )
                        {
                            ParameterNode.Foreground = Brushes.Red;
                            ParameterNode.FontWeight = FontWeights.Normal;
                        }

                        ExamplesNode.Header = "Examples";
                        ExamplesNode.DataContext = new Collection<example>();
                        // We use this to keep track of the spec example especially when the user is
                        // trying to create a new Help example, he should have access to the spec examples.
                        //ExamplesNode.Resources.Add("SpecExample", SpecCmdlet.SpecExamples);

                        // Do this if we do have example contents for this cmdlet
                        if ( CmdletHelp.Examples != null )
                        {
                            if ( CmdletHelp.Examples.Count > 0 )
                            {
                                // if we have contents then the mother examples node need to be green
                                ExamplesNode.Foreground = Brushes.Green;
                                ExamplesNode.DataContext = CmdletHelp.Examples;

                                foreach ( example examp in CmdletHelp.Examples )
                                {
                                    // add the spec example to every example record in the online mode.
                                    // this is redundant. we could use the parent Spec example record and add it.
                                    // this code was here before the Examples.Resources section was intrduced above.
                                    // I will leave it for now.
                                    //if (ProjectName != null && ProjectName != "")
                                    //{
                                    //    examp.OldExampleDescription = SpecCmdlet.SpecExamples;
                                    //}

                                    var exmpNode = new TreeViewItem();
                                    exmpNode.DataContext = examp;
                                    // if we do have text in the cmd and description section, then
                                    // mark that example record green otherwise black
                                    if ( examp.ExampleCmd != null && examp.ExampleCmd != "" &&
                                         examp.ExampleDescription != null &&
                                         examp.ExampleDescription != "" )
                                    {
                                        exmpNode.Foreground = Brushes.Green;
                                    }
                                    else
                                    {
                                        exmpNode.Foreground = Brushes.Black;
                                        ExamplesNode.Foreground = Brushes.Black;
                                    }
                                    exmpNode.Header = examp.ExampleName;
                                    ExamplesNode.Items.Add( exmpNode );
                                }
                            }
                            else // if we have no examples mark the Examples node Black.
                            {
                                ExamplesNode.Foreground = Brushes.Black;
                            }
                        }
                        else
                        {
                            ExamplesNode.Foreground = Brushes.Black;
                        }

                        // We do the same thing in Related Links as we did with examples.
                        // very similar logic
                        LinksNode.Header = "Related Links";
                        LinksNode.DataContext = new Collection<relatedlink>();
                        // LinksNode.Resources.Add("SpecLinks", SpecCmdlet.RelatedTo);
                        if ( CmdletHelp.RelatedLinks != null )
                        {
                            LinksNode.Foreground = Brushes.Black;
                            if ( CmdletHelp.RelatedLinks.Count > 0 )
                            {
                                LinksNode.Foreground = Brushes.Green;
                                LinksNode.DataContext = CmdletHelp.RelatedLinks;
                                foreach ( relatedlink Link in CmdletHelp.RelatedLinks )
                                {
                                    //if (ProjectName != null && ProjectName != "")
                                    //{
                                    //    Link.OldLinkText = SpecCmdlet.RelatedTo;
                                    //}
                                    var linkNode = new TreeViewItem();
                                    linkNode.DataContext = Link;
                                    linkNode.Header = Link.LinkText;
                                    linkNode.Foreground = Brushes.Green;
                                    LinksNode.Items.Add( linkNode );
                                }
                            }
                            else
                            {
                                LinksNode.Foreground = Brushes.Black;
                            }
                        }
                        else
                        {
                            LinksNode.Foreground = Brushes.Black;
                        }

                        // Add the sub nodes to the cmdlet record node.
                        Node.Items.Add( ParameterNode );
                        Node.Items.Add( ExamplesNode );
                        Node.Items.Add( LinksNode );

                        // If there is no mismatch anywher mark the cmdlet green otherwise
                        // Red if errors or black if incomplete.
                        if ( ExamplesNode.Foreground != Brushes.Green ||
                             LinksNode.Foreground != Brushes.Green ||
                             ParameterNode.Foreground != Brushes.Green ||
                             Node.Foreground != Brushes.Green )
                        {
                            if ( paramMistmatch )
                            {
                                Node.Foreground = Brushes.Red;
                            }
                            else
                            {
                                Node.Foreground = Brushes.Black;
                            }
                        }

                        // Fill the cmdlet node with the data structure
                        // we built above.
                        Node.Header = CmdletHelp.CmdletName;
                        Node.DataContext = CmdletHelp;

                        MainWindow.PsSnapinNode.Items.Add( Node );
                        MainWindow.CmdletsHelps.Add( CmdletHelp );
                    }

                    // If we loaded an existing help file, load all the cmdlets which are only in the
                    // help document and not in code. These are the obsolete help content. We need thi in the event a
                    // cmdlet was renamed.
                    if ( MainWindow.HelpFilePath != "" )
                    {
                        XMLReaderHelper.GetHelpInfoNotInCode( MainWindow.CmdletsHelps, MainWindow.HelpFilePath );
                    }

                    MainWindow.NavControl.Visibility = Visibility.Visible;
                    MainWindow.DescriptionControl1.Visibility = Visibility.Visible;
                    MainWindow.MainGrid1.Visibility = Visibility.Collapsed;

                    //Make sure the first Cmdlet in the list is expaneded.
                    MainWindow.NavControl.CmdletTreeView.Items.Add( MainWindow.PsSnapinNode );
                    var firstTreeViewItem = (TreeViewItem) MainWindow.NavControl.CmdletTreeView.Items[0];
                    firstTreeViewItem.IsExpanded = true;
                    firstTreeViewItem = (TreeViewItem) firstTreeViewItem.Items[0];
                    firstTreeViewItem.IsSelected = true;
                    firstTreeViewItem.IsExpanded = true;
                    //Close the Runspace handle.
                    myRunSpace.Close();
                }
                catch ( Exception ex )
                {
                    MessageBox.Show( ex.Message,
                                     "Cmdlet Help Editor: Serious Error. Restart the program.",
                                     MessageBoxButtons.OK,
                                     MessageBoxIcon.Warning );
                }
            }
        }
        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";
            var doc = new XmlDocument();
            doc.Load( path );

            var 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)
            {
                var 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
                    var Node = new TreeViewItem();

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

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

                    var ParameterNode = new TreeViewItem();
                    var ExamplesNode = new TreeViewItem();
                    var LinksNode = new TreeViewItem();
                    //add the Parameters record to the tree
                    if ( CmdletHelp.ParameterDecription != null )
                    {
                        foreach ( parameterDecription nodeparameterDesc in CmdletHelp.ParameterDecription )
                        {
                            var 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 )
                        {
                            var 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 )
                        {
                            var 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;
        }
        /// <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";
            var doc = new XmlDocument();
            doc.Load( path );

            var 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;
                    var CmdletExamples = new Collection<example>();
                    foreach ( XmlNode exampleNode in exampleNodes )
                    {
                        var 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;

                    var RelatedLinks = new Collection<relatedlink>();
                    XmlNodeList NodeLinks = commandNode.SelectNodes( "maml:relatedLinks/maml:navigationLink", ns );
                    int LinkCount = 0;
                    foreach ( XmlNode linkNode in NodeLinks )
                    {
                        var 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.
                            var 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;
        }
        //private String XMLEncode(String encodedString)
        //{
        //    encodedString = encodedString.Replace("<", "&lt;");
        //    encodedString = encodedString.Replace("<", "&lt;");
        //    encodedString = encodedString.Replace("<", "&lt;");
        //    encodedString = encodedString.Replace("<", "&lt;");
        //    encodedString = encodedString.Replace("<", "&lt;");
        //    encodedString = encodedString.Replace("<", "&lt;");
        //}
        public XmlWriter writeCmdletDetails( XmlWriter writer, cmdletDescription result )
        {
            //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");
            //String OutString = result.Members["Verb"].Value + "\n";
            //OutString += result.Members["Noun"].Value + "\n";
            //Write <commnd:details>
            //  foreach (cmdletDescription result in CmdletsHelps)
            //{
            try
            {
                writer.WriteRaw( "<!--Generated by Help Cmdlet Editor-->\r\n" );
                writer.WriteRaw( "	<command:details>\r\n" );
                writer.WriteRaw( "		<command:name>" );

                //Write cmdletName
                writer.WriteRaw( HttpUtility.HtmlEncode( result.CmdletName ) );
                writer.WriteRaw( "</command:name>\r\n" );

                //Short Description
                writer.WriteRaw( "		<maml:description>\r\n" );
                writer.WriteRaw( "			<maml:para>" );
                writer.WriteRaw( HttpUtility.HtmlEncode( result.ShortDescription ) );
                writer.WriteRaw( "</maml:para>\r\n" );
                writer.WriteRaw( "		</maml:description>\r\n" );
                // writer.WriteRaw("\r\n    <maml:copyright>\r\n        <maml:para></maml:para>\r\n    </maml:copyright>\r\n");
                //Write CopyRight info:
                writer.WriteRaw( "		<maml:copyright>\r\n" );
                writer.WriteRaw( "           <maml:para />\r\n" );
                writer.WriteRaw( "		<!--Add copy right info here.-->\r\n" );
                //writer.WriteRaw();
                writer.WriteRaw( "		</maml:copyright>\r\n" );

                //Write Noun and Verb
                writer.WriteRaw( "		<command:verb>" );
                writer.WriteRaw( HttpUtility.HtmlEncode( result.Verb ) );
                writer.WriteRaw( "</command:verb>\r\n" );
                writer.WriteRaw( "		<command:noun>" );
                writer.WriteRaw( HttpUtility.HtmlEncode( result.Noun ) );
                writer.WriteRaw( "</command:noun>\r\n" );

                //Add Dev version
                writer.WriteRaw( "		<!--Add Dev version info here.-->\r\n" );
                writer.WriteRaw( "		<dev:version />\r\n" );
                //writer.WriteRaw();

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

                //Add Cmdlet detailed description
                writer.WriteRaw( "	<maml:description>\r\n" );
                writer.WriteRaw( "	<!--This is the Description section-->\r\n" );
                writer.WriteRaw( "		<maml:para>" );
                writer.WriteRaw( HttpUtility.HtmlEncode( result.LongDescription ) );
                writer.WriteRaw( "</maml:para>\r\n" );
                writer.WriteRaw( "	</maml:description>\r\n" );
            }
            catch ( Exception ex )
            {
                MessageBox.Show( ex.Message, "Error writing the XML File.", MessageBoxButtons.OK, MessageBoxIcon.Warning );
            }

            // writer.WriteRaw();

            // }
            return writer;
        }
        public XmlWriter createSyntaxItem( XmlWriter writer, parameterDecription param, cmdletDescription Cmdlet )
        {
            try
            {
                // foreach (PSObject result in results)
                // {
                // String LocalParamDescription = "";
                Boolean Globbing = param.Globbing;
                String cmdletName = Cmdlet.CmdletName; // TODO add real CmdletName CmdletsList.SelectedValue.ToString();
                //foreach (HelpEditor.parameterDecription param in parametersDescription)
                //{

                //    if ((param.Name.ToLower() == Parameterecord.Name.ToLower()) && (cmdletName == param.CmdletName))
                //    {
                //        LocalParamDescription = param.NewDescription;
                //        Globbing = param.Globbing;
                //        break;
                //    }
                //}

                // Parameter Metadata for the Syntax Item section.
                writer.WriteRaw( "			<command:parameter " );
                writer.WriteRaw( "required = \"" + param.isMandatory.ToString().ToLower() + "\"" );
                //Do variable length verification
                String parametertype = param.ParameterType;
                int LengthName = parametertype.Length;
                String VariableLength = "false";

                if ( LengthName > 2 )
                {
                    if ( parametertype[LengthName - 1] == ']' &&
                         parametertype[LengthName - 2] == '[' )
                    {
                        VariableLength = "true";
                    }
                }

                writer.WriteRaw( " variableLength = \"" + VariableLength + "\"" );
                // TODO add code for globbing here.
                String strGlobbing = "false";
                if ( Globbing )
                {
                    strGlobbing = "true";
                }
                writer.WriteRaw( " globbing = \"" + strGlobbing + "\"" );

                String pipelineInput;
                if ( param.VFP ||
                     param.VFPBPN )
                {
                    pipelineInput = "true (";
                    if ( param.VFP )
                    {
                        pipelineInput += "ByValue";
                    }
                    if ( param.VFPBPN )
                    {
                        if ( pipelineInput.Length > 6 )
                        {
                            pipelineInput += ", ByPropertyName)";
                        }
                        else
                        {
                            pipelineInput += "ByPropertyName)";
                        }
                    }
                    else
                    {
                        pipelineInput += ")";
                    }
                }
                else
                {
                    pipelineInput = "false";
                }
                writer.WriteRaw( " pipelineInput = \"" + pipelineInput + "\"" );

                //Positional?
                // int position;
                // if (param.Position < 0)
                // {
                //    writer.WriteRaw(" position = \"named\">");
                // }
                // else
                // {
                //     position = (Parameterecord.Position + 1);
                writer.WriteRaw( " position = \"" + param.Position + "\" >\r\n" );
                // }

                //Maml parameter name.
                //  writer.WriteRaw("				<!--Parameter Name-->\r\n");
                writer.WriteRaw( "				<maml:name>" );

                writer.WriteRaw( HttpUtility.HtmlEncode( param.Name ) );
                writer.WriteRaw( "</maml:name>\r\n" );

                //Parameter description

                //  writer.WriteRaw("maml", "para", "http://schemas.microsoft.com/maml/2004/10");
                writer.WriteRaw( "				<maml:description>\r\n" );
                // writer.WriteRaw("				<!--Parameter Description->\r\n");
                //Get the description from the struc.
                writer.WriteRaw( "					<maml:para>" );

                writer.WriteRaw( HttpUtility.HtmlEncode( param.NewDescription ) );
                writer.WriteRaw( "</maml:para>\r\n" );
                writer.WriteRaw( "				</maml:description>\r\n" );

                string paramValueRequired = "true";
                if ( param.ParameterType.ToLower() != "switchparameter" )
                {
                    //Additional parameter Values
                    if ( param.ParameterType.ToLower() == "boolean" )
                    {
                        paramValueRequired = "false";
                    }
                    //Additional parameter Values
                    writer.WriteRaw( "			<command:parameterValue " );
                    writer.WriteRaw( "required=\"" + paramValueRequired + "\"" );
                    writer.WriteRaw( " variableLength = \"" + VariableLength + "\" >" );
                    writer.WriteRaw( HttpUtility.HtmlEncode( param.ParameterType ) );
                    writer.WriteRaw( "</command:parameterValue>\r\n" );
                }

                //End <command:prameter>
                writer.WriteRaw( "			</command:parameter>\r\n" );
            }
            catch ( Exception ex )
            {
                MessageBox.Show( ex.Message, "Error writing the XML File.", MessageBoxButtons.OK, MessageBoxIcon.Warning );
            }

            //}
            return writer;
        }
        public XmlWriter createOutputSection( XmlWriter writer, cmdletDescription result )
        {
            try
            {
                //Input Types Section
                writer.WriteRaw( "	<command:returnValues>\r\n" );
                writer.WriteRaw( "		<command:returnValue>\r\n" );
                writer.WriteRaw( "			<dev:type>\r\n" );

                //Input Type
                writer.WriteRaw( "				<maml:name>" );
                //writer.WriteComment("Output Type");
                writer.WriteRaw( HttpUtility.HtmlEncode( result.OutputType ) );
                writer.WriteRaw( "</maml:name>\r\n" );

                //Input Uri
                writer.WriteRaw( "				<maml:uri />\r\n" );
                //writer.WriteComment("Uri section not used");
                //writer.WriteRaw();

                //Input Type
                writer.WriteRaw( "				<maml:description>\r\n" );
                //writer.WriteComment("Output type description");
                writer.WriteRaw( "					<maml:para>" );
                writer.WriteRaw( HttpUtility.HtmlEncode( result.OutputDesc ) );
                writer.WriteRaw( "</maml:para>\r\n" );
                writer.WriteRaw( "				</maml:description>\r\n" );

                //End dev:type
                writer.WriteRaw( "			</dev:type>\r\n" );

                //End command:inputType
                writer.WriteRaw( "			<maml:description></maml:description>\r\n" );

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

                //End command:inputTypes section
                writer.WriteRaw( "	</command:returnValues>\r\n" );

                //<command:returnValues>
                //  <command:returnValue>
                //    <dev:type>
                //      <maml:name><!-- Output Type --></maml:name>
                //      <maml:uri />
                //      <maml:description>
                //        <maml:para>
                //          <!-- Output type description  -->

                //        </maml:para>
                //      </maml:description>
                //    </dev:type>
                //    <maml:description></maml:description>
                //  </command:returnValue>
                //</command:returnValues>
            }
            catch ( Exception ex )
            {
                MessageBox.Show( ex.Message, "Error writing the XML File.", MessageBoxButtons.OK, MessageBoxIcon.Warning );
            }

            return writer;
        }