/// <summary>
 ///   This is the routine that pastes the Parameter info to the slected cell.
 /// </summary>
 /// <param name="param"> </param>
 /// <param name="copiedparam"> </param>
 public void copyParameterInfo( parameterDecription param, parameterDecription copiedparam )
 {
     param.DefaultValue = copiedparam.DefaultValue;
     param.NewDescription = copiedparam.NewDescription;
     param.Globbing = copiedparam.Globbing;
 }
        /// <summary>
        ///   Write the parameter in the text viewer.
        /// </summary>
        /// <param name="param"> </param>
        /// <returns> </returns>
        public String writeParameter( parameterDecription param )
        {
            String textStream = "";
            textStream = "    -" + param.Name + " <" + param.ParameterType + ">\r\n";
            textStream += "        " + param.NewDescription + "\r\n\r\n";
            textStream += "        Required?                    ";
            if ( param.isMandatory )
            {
                textStream += "true\r\n";
            }
            else
            {
                textStream += "false\r\n";
            }
            textStream += "        Position?                    " + param.Position + "\r\n";
            textStream += "        Default value                " + param.DefaultValue + "\r\n";
            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";
            }
            textStream += "        Accept pipeline input?       " + pipelineInput + "\r\n";
            if ( param.Globbing )
            {
                textStream += "        Accept wildcard characters?  true\r\n\r\n";
            }
            else
            {
                textStream += "        Accept wildcard characters?  false\r\n\r\n";
            }

            return textStream;
        }
Ejemplo n.º 3
0
        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 );
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///   This is the static method which Asim helped me with.
        ///   I get all the Cmdlet Mamal info from here.
        ///   I need to pass the cmdletDescription record before adding it to the CmdletHelps collection.
        /// </summary>
        public static cmdletDescription GetExistingHelpInfo( cmdletDescription CmdletHelp,
            String CmdletName,
            String path)
        {
            //String path1 = @"C:\Windows\System32\WindowsPowerShell\v1.0\en-US\Microsoft.PowerShell.Commands.Management.dll-Help.xml";
            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;
        }
        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 createParameters( XmlWriter writer, parameterDecription parametersDescription )
        {
            try
            {
                if ( !parametersDescription.HelpOnlyParameter )
                {
                    string parametertype = parametersDescription.ParameterType;
                    int LengthName = parametertype.Length;
                    String VariableLength = "false";
                    String strGlobbing = "false";
                    //String cmdletName = "CmdletName"; // TODO add real CmdletName CmdletsList.SelectedValue.ToString();
                    //  foreach (HelpEditor.parameterDecription param in parametersDescription)
                    //  {

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

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

                    String pipelineInput;
                    if ( parametersDescription.VFP ||
                         parametersDescription.VFPBPN )
                    {
                        pipelineInput = "true (";
                        if ( parametersDescription.VFP )
                        {
                            pipelineInput += "ByValue";
                        }
                        if ( parametersDescription.VFPBPN )
                        {
                            if ( pipelineInput.Length > 6 )
                            {
                                pipelineInput += ", ByPropertyName)";
                            }
                            else
                            {
                                pipelineInput += "ByPropertyName)";
                            }
                        }
                        else
                        {
                            pipelineInput += ")";
                        }
                    }
                    else
                    {
                        pipelineInput = "false";
                    }
                    // Parameter Metadata for the Syntax Item section.
                    writer.WriteRaw( "		<command:parameter " );
                    writer.WriteRaw( "required=\"" + parametersDescription.isMandatory.ToString().ToLower() + "\"" );
                    writer.WriteRaw( " variableLength=\"" + VariableLength + "\"" );
                    writer.WriteRaw( " globbing=\"" + strGlobbing + "\"" );
                    writer.WriteRaw( " pipelineInput=\"" + pipelineInput + "\"" );
                    //int position;
                    //if (Parameterecord.Position < 0)
                    //{
                    //    writer.WriteRaw(" position=\"named\">\r\n");
                    //}
                    //else
                    //{
                    // position = (Parameterecord.Position + 1);
                    writer.WriteRaw( " position=\"" + parametersDescription.Position + "\">\r\n" );
                    //  }

                    //Maml parameter name.
                    writer.WriteRaw( "			<maml:name>" );
                    //writer.WriteComment("Parameter Name");
                    writer.WriteRaw( HttpUtility.HtmlEncode( parametersDescription.Name ) );
                    writer.WriteRaw( "</maml:name>\r\n" );

                    //Parameter description

                    writer.WriteRaw( "			<maml:description>\r\n" );
                    //writer.WriteComment("Parameter Description");
                    writer.WriteRaw( "				<maml:para>" );
                    String LocalParamDescription = "";
                    //foreach (HelpEditor.parameterDecription param in parametersDescription)
                    //{
                    //    if (param.Name.ToLower() == Parameterecord.Name.ToLower()) // TODO add real CmdletName && (String) this.CmdletsList.SelectedValue == param.CmdletName)
                    //    {
                    LocalParamDescription = HttpUtility.HtmlEncode( parametersDescription.NewDescription );
                    //    }
                    //}
                    writer.WriteRaw( LocalParamDescription );
                    writer.WriteRaw( "</maml:para>\r\n" );
                    writer.WriteRaw( "			</maml:description>\r\n" );

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

                    //Dev Type
                    writer.WriteRaw( "			<dev:type>\r\n" );
                    writer.WriteRaw( "				<maml:name>" );
                    //writer.WriteComment("Parameter Type");
                    writer.WriteRaw( HttpUtility.HtmlEncode( parametersDescription.ParameterType ) );
                    writer.WriteRaw( "</maml:name>\r\n" ); //maml:name
                    writer.WriteRaw( "				<maml:uri/>\r\n" );
                    //writer.WriteComment("uri");
                    //writer.WriteRaw();//maml:uri
                    writer.WriteRaw( "			</dev:type>\r\n" ); //dev:type

                    //Dev Default Value. //TODO
                    writer.WriteRaw( "			<dev:defaultValue>" );
                    //writer.WriteComment("Default Value");
                    writer.WriteRaw( HttpUtility.HtmlEncode( parametersDescription.DefaultValue ) );
                    writer.WriteRaw( "</dev:defaultValue>\r\n" );

                    //<command:parameter required="true" variableLength="false" globbing="true" pipelineInput="true (ByPropertyName)" position="1">
                    //  <maml:name><!-- Prameter Name --></maml:name>
                    //  <maml:description>
                    //    <maml:para><!-- Parameter Description --></maml:para>

                    //  </maml:description>
                    //  <command:parameterValue required="true" variableLength="false">string[]</command:parameterValue>
                    //  <dev:type>
                    //    <maml:name><!-- Prameter Type --></maml:name>
                    //    <maml:uri/>
                    //  </dev:type>
                    //  <dev:defaultValue><!-- Default Value --></dev:defaultValue>
                    //</command:parameter>

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