private static void StartJob(string path) { // Called from Main when a path is provided to run reports fi = new FileInfo(path); string ext = string.Empty; ext = Path.GetExtension(fi.FullName); string lastjob = string.Empty; if (ext == string.Empty) { if (Directory.Exists(fi.FullName)) { saveDir = fi.FullName; DirectoryInfo di = new DirectoryInfo(fi.FullName); IEnumerable<string> projfiles = Directory.EnumerateFiles(di.FullName, "*.xml", SearchOption.AllDirectories); JobList = new List<string>(projfiles); ValidateJobList(); int c = JobList.Count; lastjob = JobList[c - 1]; } } else { JobList = new List<string>(); saveDir = fi.DirectoryName; projName = Path.GetFileNameWithoutExtension(fi.FullName); JobList.Add(fi.FullName); ValidateJobList(); lastjob = fi.FullName; } foreach (string proj in JobList) { Tallies = new CmdletMetrics(); projName = Path.GetFileNameWithoutExtension(proj); Tallies.CmdletProject = projName; if (lastjob == proj) { allProjsFinished = true; } DoReports(proj); } WriteWarnings(); }
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); } }