예제 #1
0
        public void LoadModules()
        {
            PowerShell ps = PowerShell.Create();
            ps.AddCommand( "get-module" ).AddParameter( "listavailable" );
            Collection<PSObject> modules = ps.Invoke();

            // ObservableCollection<ModuleObject> availableModules = new ObservableCollection<ModuleObject>();

            foreach ( PSObject PsSnapin in modules )
            {
                var module = new ModuleObject();
                module.Name = (String) PsSnapin.Members["Name"].Value;
                module.Version = PsSnapin.Members["version"].Value.ToString();
                module.Descrition = (String) PsSnapin.Members["Description"].Value;
                module.ModuleType = PsSnapin.Members["ModuleType"].Value.ToString();
                myModules.Add( module );
                PsSnapinList.Items.Add( module );
            }
        }
예제 #2
0
        /// <summary>
        ///   This routine loads a PsSnapin and prompts for a
        ///   Help file to load.
        ///   We do not do any validation to ensure the help file 
        ///   matches the snapin and we do not report errors.
        /// </summary>
        /// <param name="sender"> </param>
        /// <param name="e"> </param>
        public void BrowseHelpFile_Click( object sender, RoutedEventArgs e )
        {
            if ( MainWindow.MainGrid1.PsSnapinList.SelectedItems.Count > 0 &&
                 MainWindow.MainGrid1.PsSnapinList.Items.Count > 0 )
            {
                try
                {
                    if ( MainWindow.CmdletsHelps.Count > 0 )
                    {
                        DialogResult result =
                                MessageBox.Show( "This action deletes unsaved help file text.\n\nContinue?",
                                                 "Open Help File",
                                                 MessageBoxButtons.YesNo,
                                                 MessageBoxIcon.Warning );

                        if ( result == DialogResult.Yes )
                        {
                            // Configure open file dialog box
                            var dlg = new OpenFileDialog();
                            var myview = new ModuleObject();
                            myview = (ModuleObject) MainWindow.MainGrid1.PsSnapinList.SelectedItem;
                            MainWindow.PsSnapinName = myview.Name;
                            MainWindow.PsSnapinModuleName = myview.Name;
                            dlg.FileName = MainWindow.PsSnapinModuleName + "-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? FODresult = dlg.ShowDialog();

                            // Process open file dialog box results
                            if ( FODresult.Value ==
                                 DialogResult.OK )
                            {
                                // Open document
                                MainWindow.HelpFilePath = dlg.FileName;
                                MainWindow.OldHelpFileExist = true;

                                LoadPsNapin();
                            }
                        }
                    }
                    else
                    {
                        // Configure open file dialog box
                        var dlg = new OpenFileDialog();
                        var myview = new ModuleObject();
                        myview = (ModuleObject) MainWindow.MainGrid1.PsSnapinList.SelectedItem;
                        MainWindow.PsSnapinName = myview.Name;
                        MainWindow.PsSnapinModuleName = myview.Name;
                        dlg.FileName = MainWindow.PsSnapinModuleName + "-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? FODresult = dlg.ShowDialog();

                        // Process open file dialog box results
                        if ( FODresult.Value ==
                             DialogResult.OK )
                        {
                            // Open document
                            MainWindow.HelpFilePath = dlg.FileName;
                            MainWindow.OldHelpFileExist = true;

                            LoadPsNapin();
                        }
                    }
                }
                catch ( Exception ex )
                {
                    MessageBox.Show( ex.Message,
                                     "Error loading the help file.",
                                     MessageBoxButtons.OK,
                                     MessageBoxIcon.Warning );
                }
            }
            else
            {
                System.Windows.MessageBox.Show( "Select a PsSnapin before opening a help file.",
                                                "PsSnapin Not Selected",
                                                MessageBoxButton.OK,
                                                MessageBoxImage.Warning );
            }
        }
예제 #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 );
                }
            }
        }