Beispiel #1
0
        private static void SearchProj(string projfile)
        {
            // Called from the DoSearch method

            Tallies = new CmdletMetrics();
            xd = XDocument.Load(File.OpenRead(projfile));
            IEnumerable<XElement> commands = xd.Root.Descendants(nsCMD + "command");
            int cc = commands.Count();
            Tallies.CmdletCount = cc;
            ProjectCmdlets.Clear();

            FileInfo fi = new FileInfo(projfile);
            saveDir = fi.DirectoryName;
            projName = Path.GetFileNameWithoutExtension(fi.FullName);
            try
            {
                foreach (XElement cmd in commands)
                {
                    CmdletData ProjCmds = new CmdletData();
                    ProjCmds.Project = projName;
                    GatherData(ProjCmds, cmd);
                    ProjectCmdlets.Add(ProjCmds);
                }

                PowerShell psConvCSV = PowerShell.Create();
                psConvCSV.AddCommand("ConvertTo-Csv");
                psConvCSV.AddParameter("NoTypeInformation");

                string srchOpt = string.Empty;
                if (matchcase == true && wholeword == true)
                {
                    PrepSearchData(true, true);
                    srchOpt = "MatchCase & WholeWord";
                }
                else if (matchcase == true && wholeword == false)
                {
                    PrepSearchData(true, false);
                    srchOpt = "MatchCase";
                }
                else if (matchcase == false && wholeword == true)
                {
                    PrepSearchData(false, true);
                    srchOpt = "WholeWord";
                }
                if (matchcase == false && wholeword == false)
                {
                    PrepSearchData(false, false);
                    srchOpt = "None";
                }

                string csvPath = Path.Combine(saveDir, "CJ_SearchResults.csv");
                if (Tallies.SearchHit > 0)
                {
                    IEnumerable<string> csvStrings = (IEnumerable<string>)psConvCSV.Invoke<string>(SearchResultList);

                    curSearchHits = Tallies.SearchHit;
                    WriteReport(csvPath, csvStrings, "SearchResults");
                }

            }
            catch (UnauthorizedAccessException UAEx)
            {
                 Console.WriteLine("{0}\nDo you have any of the XML files open? (SearchProj)",UAEx.Message);
            }
            catch (ArgumentNullException NullEx)
            {
                Console.WriteLine(NullEx.Message);
            }
        }
Beispiel #2
0
        private static void DoReports(string projfile)
        {
            string curRptRunning = string.Empty;

            try
            {
                // Called from the StartJob method.
                // Process XML file and initialize the CmdletData class.
                // Uses the psConvCSV.Invoke method for output to a spreadsheet.

                xd = XDocument.Load(File.OpenRead(projfile));
                IEnumerable<XElement> commands = xd.Root.Descendants(nsCMD + "command");
                Tallies.CmdletCount = commands.Count();
                ProjectCmdlets.Clear();

                foreach (XElement cmd in commands)
                {
                    CmdletData ProjCmds = new CmdletData();
                    GatherData(ProjCmds, cmd);
                    ProjCmds.Project = projName;
                    ProjectCmdlets.Add(ProjCmds);
                }

                string cvspath = string.Empty;
                PowerShell psConvCSV = PowerShell.Create();
                psConvCSV.AddCommand("ConvertTo-Csv");
                psConvCSV.AddParameter("NoTypeInformation");

                PrepDescrData();
                curRptRunning = "Descriptions Report";
                string csvPath = Path.Combine(saveDir, "CJ_Descriptions.csv");
                if (allProjsFinished)
                {
                    if (DescrList.Count > 0)
                    {
                        IEnumerable<string> csvStrings = (IEnumerable<string>)psConvCSV.Invoke<string>(DescrList);
                        WriteReport(csvPath, csvStrings, "CmdletDescrData");
                    }
                }

                PrepParamData();
                curRptRunning = "Parameters Report";
                csvPath = Path.Combine(saveDir, "CJ_Parameters.csv");
                if (allProjsFinished)
                {
                    if (ParamsList.Count > 0)
                    {
                        IEnumerable<string> csvStrings = (IEnumerable<string>)psConvCSV.Invoke<string>(ParamsList);
                        WriteReport(csvPath, csvStrings, "CmdletParamData");
                    }
                }

                PrepExampleData();
                curRptRunning = "Examples Report";
                csvPath = Path.Combine(saveDir, "CJ_Examples.csv");
                if (allProjsFinished)
                {
                    {
                        IEnumerable<string> csvStrings = (IEnumerable<string>)psConvCSV.Invoke<string>(ExampleList);
                        WriteReport(csvPath, csvStrings, "CmdletExampleData");
                    }
                }

                PrepSummaryData();
                curRptRunning = "Summary Report";
                csvPath = Path.Combine(saveDir, "CJ_Summary.csv");
                if (allProjsFinished)
                {
                    if (TalliesList.Count > 0)
                    {
                        IEnumerable<string> csvStrings = (IEnumerable<string>)psConvCSV.Invoke<string>(SummaryList);
                        WriteReport(csvPath, csvStrings, "Summary");
                    }
                }

                PrepInputOutputData();
                curRptRunning = "InOut Report";
                csvPath = Path.Combine(saveDir, "CJ_InOut.csv");
                if (allProjsFinished)
                {
                    IEnumerable<string> csvStrings = (IEnumerable<string>)psConvCSV.Invoke<string>(InOutList);
                    WriteReport(csvPath, csvStrings, "CmdletInputOutputData");
                }

                PrepLinkData();
                curRptRunning = "Links Report";
                csvPath = Path.Combine(saveDir, "CJ_Links.csv");
                if (allProjsFinished)
                {
                    IEnumerable<string> csvStrings = (IEnumerable<string>)psConvCSV.Invoke<string>(LinksList);
                    WriteReport(csvPath, csvStrings, "CmdletLinkData");
                }

            }
            catch (FileNotFoundException FNFEx)
            {
                string msg = FNFEx.Message + " " + FNFEx.StackTrace;
                CreateWarning(projName, "N/A", "N/A", "Method", "DoProcess", "FileNotFoundException - " + msg, "Internal");
                Console.WriteLine("{0} not found.", projfile);
            }
            catch (NullReferenceException NullEx)
            {
                string msg = NullEx.StackTrace;
                CreateWarning(projName, "N/A", "N/A", "Method", "DoProcess", "NullReferenceException - " + msg, "Internal");
            }
            catch (IOException IOEx)
            {
                string msg = IOEx.Message + " " + IOEx.StackTrace;
                CreateWarning(projName, "N/A", "N/A", "Method", "DoProcess", "IOException - " + msg, "Internal");
            }
            catch (ParameterBindingException)
            {
                Console.WriteLine("\n{0} - {1}", projName, "Cannot generate the " + curRptRunning + " and perhaps other reports. See the Warnings report on elements. Please try again on a new project XML file.\n");
                CreateWarning(projName, "N/A", "N/A", "N/A", "Report failure", "Try again on a new project XML file.", "Element");
            }
        }
Beispiel #3
0
        private static CmdletData GatherData(CmdletData ProjCmds, XElement cmd)
        {
            // This is the method that parses the XML files,
            // called from the DoReports and SearchProj methods.
            // Populates objects with element values from the XML file.

            string name = string.Empty;
            string verb = string.Empty;
            string noun = string.Empty;
            string category = string.Empty;

            string itemToAdd = String.Empty;

            try
            {
                // Get Synopsis and Description
                name = cmd.Element(nsCMD + "details").Element(nsCMD + "name").Value.ToString();
                string synopsis = cmd.Element(nsCMD + "details").Element(nsMML + "description").Value.ToString();
                string description = cmd.Element(nsMML + "description").Value.ToString();
                category = "Gather Data - Synopsis";

                ProjCmds.Name = name;
                ProjCmds.Synopsis = synopsis;
                ProjCmds.Description = description;

                SplitVerb(name, out verb, out noun);

                // note missing
                if (synopsis == string.Empty)
                {
                    CreateWarning(projName, verb, noun, "Synopsis", "Synopsis - missing", "need to write", "QA");
                    Tallies.NoSynopsis++;
                }
                else
                {
                    QAVerbStart(synopsis, verb, noun, "Synopsis", "");
                }
                category = "Gather Data - Descr";
                if (description == string.Empty)
                {
                    CreateWarning(projName, verb, noun, "Description", "Description - missing", "need to write", "QA");
                    Tallies.NoDescription++;
                }
                else
                {
                    // note starts correctly
                    QADescrStart(description, name, verb, noun);
                }

                // Get Parameters
                IEnumerable<XElement> CmdParams = cmd.Element(nsCMD + "parameters").Elements(nsCMD + "parameter");

                // temp dictionaries to use to set CmdletData (ProjCmds object)
                Dictionary<string, string> CmdletParams = new Dictionary<string, string>();
                Dictionary<string, string> CmdletParamsTypes = new Dictionary<string, string>();

                category = "GatherData - Params";
                string pName = string.Empty;
                string pDescr = string.Empty;
                string pType = string.Empty;

                foreach (XElement xp in CmdParams)
                {
                    if (xp.Element(nsMML + "name").IsEmpty || string.IsNullOrWhiteSpace(xp.Element(nsMML + "name").Value))
                    {
                        CreateWarning(projName, verb, noun, "Parameter", "No content", "Empty Element", "Element");
                    }
                    else
                    {
                        pName = xp.Element(nsMML + "name").Value.ToString();
                        pDescr = xp.Element(nsMML + "description").Value.ToString();
                        pType = xp.Element(nsDEV + "type").Element(nsMML + "name").Value.ToString();
                        if (pType == "" || pType == null)
                        {
                            pType = "Unknown";
                            CreateWarning(projName, verb, noun, "Parameter", "Unknown data type", pName, "Element");
                        }
                        bool missingPDescr = false;

                        //note missing
                        if (pDescr == string.Empty)
                        {
                            Tallies.NoParameter++;
                            missingPDescr = true;
                            CreateWarning(projName, verb, noun, "Parameter", "Param descr - missing", pName, "QA");
                        }
                        else
                        {
                            if (!missingPDescr)
                            {
                                // note verb QA
                                QAVerbStart(pDescr, verb, noun, "Parameter", pName);
                            }
                        }

                        try
                        {
                            itemToAdd = pName;
                            CmdletParams.Add(pName, pDescr);

                            // Hack:
                            // For unique keys for the CmdetParamTypes dictionary,
                            // prepend with the cmdlet name and a dot.

                            string pNameT = name + "." + pName;
                            itemToAdd = pNameT;
                            CmdletParamsTypes.Add(pNameT, pType);
                        }

                        catch (NullReferenceException nullEx)
                        {
                            string msg = nullEx.StackTrace;
                            CreateWarning(projName, verb, noun, "Parameter", pType, "NullRefrenceException - " + msg, "Internal");

                        }
                        catch (ArgumentNullException argNullEx)
                        {
                            string msg = argNullEx.Message + " " + argNullEx.StackTrace;
                            CreateWarning(projName, verb, noun, "Paramter", pType, "ArgumentNullExcpeiton - " + msg, "Internal");
                        }

                        catch (ArgumentException argEx)
                        {
                            string msg = argEx.Message + " " + argEx.StackTrace;
                            CreateWarning(projName, verb, noun, "Parameter", pType, "ArgumentException - " + msg, "Internal");
                        }
                    }
                }
                ProjCmds.Params = CmdletParams;
                ProjCmds.ParamTypes = CmdletParamsTypes;

                // Get inputTypes and outputTypes (Return Values)

                IEnumerable<XElement> CmdInputTypes = cmd.Element(nsCMD + "inputTypes").Elements(nsCMD + "inputType");
                IEnumerable<XElement> CmdOutputTypes = cmd.Element(nsCMD + "returnValues").Elements(nsCMD + "returnValue");

                // Temp dictionaries to set ProjCmds properties
                Dictionary<string, string> inputTD = new Dictionary<string, string>();
                Dictionary<string, string> inputTU = new Dictionary<string, string>();
                Dictionary<string, string> outputTD = new Dictionary<string, string>();
                Dictionary<string, string> outputTU = new Dictionary<string, string>();

                foreach (XElement xp in CmdInputTypes)
                {
                    string inT = string.Empty;
                    string inD = string.Empty;
                    string inU = string.Empty;

                    if (xp.Element(nsDEV + "type").Element(nsMML + "name").IsEmpty || string.IsNullOrWhiteSpace(xp.Element(nsDEV + "type").Element(nsMML + "name").Value))
                    {
                        CreateWarning(projName, verb, noun, "Input Type Name", "No content", "Empty Element", "Element");
                        Tallies.NoInputObj++;
                    }
                    else
                    {
                        inT = xp.Element(nsDEV + "type").Element(nsMML + "name").Value.ToString();
                    }
                    if (xp.Element(nsDEV + "type").Element(nsMML + "uri").IsEmpty || string.IsNullOrWhiteSpace(xp.Element(nsDEV + "type").Element(nsMML + "uri").Value))
                    {
                        CreateWarning(projName, verb, noun, "Input Type URI", "No content", "Empty Element", "Element");
                        Tallies.NoInputObjURI++;
                    }
                    else
                    {
                        inU = xp.Element(nsDEV + "type").Element(nsMML + "uri").Value.ToString();
                    }
                    if (xp.Element(nsMML + "description").IsEmpty || string.IsNullOrWhiteSpace(xp.Element(nsMML + "description").Value))
                    {
                        CreateWarning(projName, verb, noun, "Input Type Description", "No content", "Empty Element", "Element");
                        Tallies.NoInputObjDescr++;
                    }
                    else
                    {
                        inD = xp.Element(nsMML + "description").Value.ToString();

                    }

                    itemToAdd = inT;
                    inputTD.Add(inT, inD);
                    inputTU.Add(inT, inU);

                }

                foreach (XElement xp in CmdOutputTypes)
                {

                    string outT = string.Empty;
                    string outD = string.Empty;
                    string outU = string.Empty;

                    if (xp.Element(nsDEV + "type").Element(nsMML + "name").IsEmpty || string.IsNullOrWhiteSpace(xp.Element(nsDEV + "type").Element(nsMML + "name").Value))
                    {
                        CreateWarning(projName, verb, noun, "Output Type Name", "No content", "Empty Element", "Element");
                        Tallies.NoOutputObj++;
                    }
                    else
                    {
                        outT = xp.Element(nsDEV + "type").Element(nsMML + "name").Value.ToString();
                    }
                    if (xp.Element(nsDEV + "type").Element(nsMML + "uri").IsEmpty || string.IsNullOrWhiteSpace(xp.Element(nsDEV + "type").Element(nsMML + "uri").Value))
                    {
                        CreateWarning(projName, verb, noun, "Output Type URI", "No content", "Empty Element", "Element");
                        Tallies.NoOutputObjURI++;
                    }
                    else
                    {
                        outU = xp.Element(nsDEV + "type").Element(nsMML + "uri").Value.ToString();

                    }
                    if (xp.Element(nsMML + "description").IsEmpty || string.IsNullOrWhiteSpace(xp.Element(nsMML + "description").Value))
                    {
                        CreateWarning(projName, verb, noun, "Output Type Description", "No content", "Empty Element", "Element");
                        Tallies.NoOutputObjDescr++;
                    }
                    else
                    {
                        outD = xp.Element(nsMML + "description").Value.ToString();

                    }

                    itemToAdd = outT;
                    outputTD.Add(outT, outD);
                    outputTU.Add(outT, outU);
                }
                ProjCmds.InputTDescr = inputTD;
                ProjCmds.InputTUri = inputTU;
                ProjCmds.OutputTDescr = outputTD;
                ProjCmds.OutputTUri = outputTU;

                // Get Examples

                bool hasExCode = false;

                IEnumerable<XElement> CmdExamples = cmd.Element(nsCMD + "examples").Elements(nsCMD + "example");
                Dictionary<string, string> CmdletExampleCodes = new Dictionary<string, string>();
                Dictionary<string, string> CmdletExampleDescriptions = new Dictionary<string, string>();
                int exnum = 1;
                category = "GatherData - Examples";
                foreach (XElement xe in CmdExamples)
                {

                    string eTitle = string.Empty;
                    string eCode = string.Empty;
                    string eDescr = string.Empty;

                    if (xe.Element(nsMML + "title").IsEmpty || string.IsNullOrWhiteSpace(xe.Element(nsMML + "title").Value))
                    {
                        // missing title
                        string guid = Guid.NewGuid().ToString();
                        string g = guid.Substring(0, guid.IndexOf("-"));
                        eTitle = "Missing example title - " + g;
                        CreateWarning(projName, verb, noun, "Example", "missing title", "Example " + exnum.ToString(), "Element");
                    }
                    else
                    {
                        eTitle = xe.Element(nsMML + "title").Value.ToString();
                    }

                    IEnumerable<XElement> elems = xe.Elements();
                    List<string> elemList = new List<string>();
                    foreach (XElement el in elems)
                    {
                        itemToAdd = el.Name.ToString();
                        elemList.Add(itemToAdd);
                    }

                    if (elemList.Contains("{http://schemas.microsoft.com/maml/dev/2004/10}code"))
                    {

                        if (xe.Element(nsDEV + "code").IsEmpty || string.IsNullOrWhiteSpace(xe.Element(nsDEV + "code").Value))
                        {
                            CreateWarning(projName, verb, noun, "Example", "empty code block", "Example " + exnum.ToString(), "Element");
                        }
                        else
                        {
                            eCode = xe.Element(nsDEV + "code").Value.ToString();
                            // code only has a prompt 'PS C:\>'
                            if (eCode.Length < 11)
                            {
                                CreateWarning(projName, verb, noun, "Example", "Code - only has a prompt", "Example " + exnum.ToString() + ": " + eCode, "QA");
                                Tallies.CodeIssue++;

                            }
                            else
                            {
                                QASniffCode(projName, eCode, verb, noun, exnum);
                                hasExCode = true;
                            }
                        }

                    }
                    else
                    {
                        // This else block may be outdated in terms of current schema
                        CreateWarning(projName, verb, noun, "Example", "schema", "commandline elements", "Internal");

                        foreach (XElement xecl in xe.Element(nsCMD + "commandLines").Elements(nsCMD + "commandLine"))
                        {
                            foreach (XElement xeclt in xecl.Elements("commandText"))
                            {
                                if (xeclt.IsEmpty || string.IsNullOrWhiteSpace(xeclt.Value))
                                {
                                    CreateWarning(projName, verb, noun, "Example", "schema", "commandline elements", "Internal");
                                }
                                else
                                {
                                    CreateWarning(projName, verb, noun, "Example", "schema", eCode, "Internal");
                                    eCode = xeclt.Value.ToString();
                                    QASniffCode(projName, eCode, verb, noun, exnum);
                                    hasExCode = true;
                                }
                            }
                        }
                    }
                    if (xe.Element(nsDEV + "remarks").IsEmpty || string.IsNullOrWhiteSpace(xe.Element(nsDEV + "remarks").Value))
                    {
                        CreateWarning(projName, verb, noun, "Example", "missing description", "Example " + exnum.ToString(), "QA");
                    }
                    else
                    {
                        eDescr = xe.Element(nsDEV + "remarks").Value.ToString();
                        if (eDescr.Substring(0, 1) == " ")
                        {
                            CreateWarning(projName, verb, noun, "Example", "Description - starts with a space", eDescr.Substring(0, 20) + " ...", "QA");
                        }
                    }

                    try
                    {
                        itemToAdd = eTitle;
                        CmdletExampleCodes.Add(eTitle, eCode);
                    }
                    catch (ArgumentException)
                    {
                        CreateWarning(projName, verb, noun, "Method", category, "ArgumentException" + itemToAdd, "Internal");
                    }
                    try
                    {
                        itemToAdd = eTitle;
                        CmdletExampleDescriptions.Add(eTitle, eDescr);
                    }
                    catch (ArgumentException)
                    {
                        CreateWarning(projName, verb, noun, "Method", category, "ArgumentException - " + itemToAdd, "Internal");
                    }
                    exnum++;
                }
                ProjCmds.ExampleCodes = CmdletExampleCodes;
                ProjCmds.ExampleDescriptions = CmdletExampleDescriptions;

                if (CmdExamples.Count() == 0 || hasExCode == false)
                {
                    CreateWarning(projName, verb, noun, "Example", "Example - missing", "need to write", "QA");
                    Tallies.NoExample++;
                }

                // Get Links
                Dictionary<string, string> CmdletLinks = new Dictionary<string, string>();

                if (!cmd.Element(nsMML + "relatedLinks").HasElements)
                {
                    itemToAdd = "*** no links in " + verb + "-" + noun + " topic ****";
                    CmdletLinks.Add(itemToAdd, string.Empty);
                    CreateWarning(projName, verb, noun, "Link", "Empty node", "Add at least one link", "Element");

               }

                else
                {
                    IEnumerable<XElement> linkNodes = cmd.Element(nsMML + "relatedLinks").Elements(nsMML + "navigationLink");
                    string lTxt = string.Empty;
                    string lUri = string.Empty;
                    category = "GatherData - Links";

                    foreach (XElement xl in linkNodes)
                    {
                        if (xl.HasElements)
                        {

                            if (!xl.Element(nsMML + "linkText").IsEmpty || string.IsNullOrWhiteSpace(xl.Element(nsMML + "linkText").Value))
                            {
                                lTxt = xl.Element(nsMML + "linkText").Value.ToString();

                                if (lTxt == ProjCmds.Name)
                                {
                                    CreateWarning(projName, verb, noun, "Link", "Links - topic links to itself", "need to delete", "QA");
                                    Tallies.LinkIssue++;
                                }
                            }
                            if (lTxt == string.Empty)
                            {
                                CreateWarning(projName, verb, noun, "Link", "link text", "empty value", "Element");
                                Tallies.LinkIssue++;
                            }

                            lUri = xl.Element(nsMML + "uri").Value.ToString();
                            try
                            {
                                QASniffURI(projName, lUri, verb, noun);
                                itemToAdd = lTxt;
                                CmdletLinks.Add(lTxt, lUri);
                            }

                            catch (ArgumentException)
                            {
                                CreateWarning(projName, verb, noun, "Link", "Links - duplicate link in topic", lTxt, "QA");
                                Tallies.LinkIssue++;
                            }
                            bool hasFWLink = false;
                            foreach (KeyValuePair<string, string> kvp in CmdletLinks)
                            {
                                if (kvp.Value.ToLower().Contains("linkid"))
                                {
                                    hasFWLink = true;
                                }
                            }
                            if (hasFWLink == false)
                            {
                                // add empty row to report if no FWLink
                                itemToAdd = "Need Online Version link for " + verb + "-" + noun;
                                if (!CmdletLinks.Keys.Contains<string>(itemToAdd))
                                    CmdletLinks.Add(itemToAdd, string.Empty);

                                CreateWarning(projName, verb, noun, "Link", "Links - missing FWLink", "need to create", "QA");
                                Tallies.NoFWLink++;
                            }
                        }
                    }
                }

                ProjCmds.Links = CmdletLinks;

            }

            catch (NullReferenceException NullEx)
            {
                string msg = NullEx.StackTrace;
                CreateWarning(projName, verb, noun, "Method", category, "NullReferenceException - " + msg, "Internal");
            }

            catch (ArgumentException)
            {
                CreateWarning(projName, verb, noun, "Method", category, "ArgumentException - " + itemToAdd, "Internal");
            }

            return ProjCmds;
        }