diff --git a/ModuleAnalyzer.sln b/ModuleAnalyzer.sln index 89323cd..572fdcc 100644 --- a/ModuleAnalyzer.sln +++ b/ModuleAnalyzer.sln @@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PsModuleAnalyzer.Core", "So EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PsModuleAnalyzer.DgmlFormatter", "Source\ModuleAnalyzer.DgmlFormatter\PsModuleAnalyzer.DgmlFormatter.csproj", "{B4DFC143-D3FA-4F46-9274-FB09C94F1228}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PsModuleAnaylzer.CSVFormatter", "..\PsModuleAnaylzer.CSV\PsModuleAnaylzer.CSVFormatter.csproj", "{DDF936E4-61F3-4199-A6C6-39A79A09BBD7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +29,10 @@ Global {B4DFC143-D3FA-4F46-9274-FB09C94F1228}.Debug|Any CPU.Build.0 = Debug|Any CPU {B4DFC143-D3FA-4F46-9274-FB09C94F1228}.Release|Any CPU.ActiveCfg = Release|Any CPU {B4DFC143-D3FA-4F46-9274-FB09C94F1228}.Release|Any CPU.Build.0 = Release|Any CPU + {DDF936E4-61F3-4199-A6C6-39A79A09BBD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DDF936E4-61F3-4199-A6C6-39A79A09BBD7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DDF936E4-61F3-4199-A6C6-39A79A09BBD7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DDF936E4-61F3-4199-A6C6-39A79A09BBD7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Source/ModuleAnalyzer.App/Factory/DefaultCommandVisitorFactory.cs b/Source/ModuleAnalyzer.App/Factory/DefaultCommandVisitorFactory.cs index 205fd76..55e0b1d 100644 --- a/Source/ModuleAnalyzer.App/Factory/DefaultCommandVisitorFactory.cs +++ b/Source/ModuleAnalyzer.App/Factory/DefaultCommandVisitorFactory.cs @@ -1,7 +1,6 @@ using PsModuleAnalyzer.App.Visitor; using PsModuleAnalyzer.Core.Factory; using PsModuleAnalyzer.Core.Model; -using PsModuleAnalyzer.Core.Repository; namespace PsModuleAnalyzer.App.Factory { diff --git a/Source/ModuleAnalyzer.App/Output/MermaidOutput.cs b/Source/ModuleAnalyzer.App/Output/MermaidOutput.cs index 83b6525..af0fab1 100644 --- a/Source/ModuleAnalyzer.App/Output/MermaidOutput.cs +++ b/Source/ModuleAnalyzer.App/Output/MermaidOutput.cs @@ -13,9 +13,9 @@ public MermaidOutput(string destinationPath) _destinationPath = destinationPath; } - public void CreateAnalyzerOutupt(List moduleCommandCalls) + public void CreateAnalyzerOutupt(ModuleDefinition moduleDefinition) { - var content = CreateMarkdownContent(moduleCommandCalls); + var content = CreateMarkdownContent(moduleDefinition.ModuleCommandCalls); WriteMarkdownFile(content); } diff --git a/Source/ModuleAnalyzer.App/Program.cs b/Source/ModuleAnalyzer.App/Program.cs index d838bae..8ee8c33 100644 --- a/Source/ModuleAnalyzer.App/Program.cs +++ b/Source/ModuleAnalyzer.App/Program.cs @@ -2,6 +2,7 @@ using PsModuleAnalyzer.App.Output; using PsModuleAnalyzer.Core.Anaylzer; using PsModuleAnalyzer.DgmlFormatter; +using PsModuleAnaylzer.CSV; namespace PsModuleAnalyzer.App { @@ -12,7 +13,9 @@ private static void Main(string[] args) ModuleAnalyzer? analyzer = ModuleAnalyzerBuilder.Create("D:\\Repositories\\Go\\Source\\Go.psd1") .AddCommandVisitor() .AddDgmlFormatter("d:\\module.dgml") - .AddOutputWriter(new MermaidOutput("d:\\module.md")) + .AddCSVFormatter("d:\\module.csv") + .AddCSVFormatter("d:\\module-compact.csv", true) + .AddOutputFormatter(new MermaidOutput("d:\\module.md")) .Build(); analyzer.Analyze(); diff --git a/Source/ModuleAnalyzer.App/PsModuleAnalyzer.App.csproj b/Source/ModuleAnalyzer.App/PsModuleAnalyzer.App.csproj index 2412e14..2c8a3e6 100644 --- a/Source/ModuleAnalyzer.App/PsModuleAnalyzer.App.csproj +++ b/Source/ModuleAnalyzer.App/PsModuleAnalyzer.App.csproj @@ -8,6 +8,7 @@ + diff --git a/Source/ModuleAnalyzer.App/Visitor/DefaultCommandVisitor.cs b/Source/ModuleAnalyzer.App/Visitor/DefaultCommandVisitor.cs index e7acb36..845d979 100644 --- a/Source/ModuleAnalyzer.App/Visitor/DefaultCommandVisitor.cs +++ b/Source/ModuleAnalyzer.App/Visitor/DefaultCommandVisitor.cs @@ -1,5 +1,4 @@ using PsModuleAnalyzer.Core.Model; -using PsModuleAnalyzer.Core.Repository; using PsModuleAnalyzer.Core.Visitor; using System.Management.Automation.Language; @@ -7,20 +6,44 @@ namespace PsModuleAnalyzer.App.Visitor { public class DefaultCommandVisitor : CommandVisitor { - public DefaultCommandVisitor(ModuleCommand moduleCommand, ModuleDefinition moduleRepository) : - base(moduleCommand, moduleRepository) + public DefaultCommandVisitor(ModuleCommand moduleCommand, ModuleDefinition moduleDefinition) : + base(moduleCommand, moduleDefinition) { } - public override AstVisitAction VisitFunctionDefinition(FunctionDefinitionAst functionDefinitionAst) + public override AstVisitAction VisitCommand(CommandAst commandAst) { - return AstVisitAction.SkipChildren; + string? targetCommandName = commandAst.GetCommandName(); + + IModuleCommand? targetCommand = _moduleRepository.GetModuleCommand(targetCommandName); + + if (targetCommand == null) + { + targetCommand = _moduleRepository.AddExternalModuleCommand(targetCommandName); + } + + ModuleCommandCall? moduleCommandCall = new ModuleCommandCall(_moduleCommand, targetCommand, _moduleRepository); + + _moduleRepository.AddModuleCommandCall(moduleCommandCall); + + return AstVisitAction.Continue; } - public override AstVisitAction VisitCommand(CommandAst commandAst) + public override AstVisitAction VisitCommandParameter(CommandParameterAst parameterAst) { - string? targetCommandName = commandAst.GetCommandName(); + var currentCall = _moduleRepository.ModuleCommandCalls.Last(); + var currentParam = _moduleRepository.GetModuleCommandParameter(currentCall.Target.Name, parameterAst.ParameterName); + + if(currentParam != null) + currentCall.Parameters.Add(currentParam); + + return AstVisitAction.Continue; + } + + public override AstVisitAction VisitFunctionDefinition(FunctionDefinitionAst commandAst) + { + string? targetCommandName = commandAst.Name; IModuleCommand? targetCommand = _moduleRepository.GetModuleCommand(targetCommandName); @@ -29,11 +52,19 @@ public override AstVisitAction VisitCommand(CommandAst commandAst) targetCommand = _moduleRepository.AddExternalModuleCommand(targetCommandName); } - ModuleCommandCall? moduleCommandCall = new ModuleCommandCall(_moduleCommand, targetCommand); + ModuleCommandCall? moduleCommandCall = new ModuleCommandCall(_moduleCommand, targetCommand, _moduleRepository); + if(commandAst.Parameters != null) + { + foreach(var cmd in commandAst.Parameters) + { + var cmdParam = new ModuleCommandParameter(_moduleCommand, cmd.Name.ToString(), cmd.StaticType.Name); + moduleCommandCall.Parameters.Add(cmdParam); + } + } _moduleRepository.AddModuleCommandCall(moduleCommandCall); - return AstVisitAction.SkipChildren; + return AstVisitAction.Continue; } } } diff --git a/Source/ModuleAnalyzer.Core/Anaylzer/ModuleAnalyzer.cs b/Source/ModuleAnalyzer.Core/Anaylzer/ModuleAnalyzer.cs index c43da6d..2283ed9 100644 --- a/Source/ModuleAnalyzer.Core/Anaylzer/ModuleAnalyzer.cs +++ b/Source/ModuleAnalyzer.Core/Anaylzer/ModuleAnalyzer.cs @@ -1,7 +1,6 @@ using PsModuleAnalyzer.Core.Factory; using PsModuleAnalyzer.Core.Interfaces; using PsModuleAnalyzer.Core.Model; -using PsModuleAnalyzer.Core.Repository; using PsModuleAnalyzer.Core.Visitor; using System.Management.Automation; using System.Management.Automation.Language; @@ -16,11 +15,7 @@ public class ModuleAnalyzer internal ModuleAnalyzer(string modulePath) { - PSModuleInfo? moduleInfo = LoadModuleFromPath(modulePath); - _moduleDefinition = new ModuleDefinition(moduleInfo.Name, moduleInfo.ModuleBase); - - var commands = CreateModuleCommandList(moduleInfo).ToHashSet(); - _moduleDefinition.AddModuleCommands(commands); + _moduleDefinition = new ModuleDefinition(modulePath); } public void AddOutputFormat(IAnalyzerOutput output) @@ -28,7 +23,7 @@ public void AddOutputFormat(IAnalyzerOutput output) AnalyzerOutputFormatters.Add(output); } - public void SetFactory(CommandVisitorFactory factory) + public void SetCommandVisitorFactory(CommandVisitorFactory factory) { Factory = factory; } @@ -37,64 +32,31 @@ public void Analyze() { foreach (ModuleCommand? command in _moduleDefinition.ModuleCommands) { - ScriptBlockAst? ast = Parser.ParseInput( + ScriptBlockAst ast = Parser.ParseInput( command.Definition, out Token[] tokens, out ParseError[] errors ); + List paramastList = new(); + var newAst = (ScriptBlockAst) ast.Copy(); + if(ast.ParamBlock != null) + { + foreach (var param in ast.ParamBlock.Parameters) + paramastList.Add((ParameterAst)param.Copy()); + } + + FunctionDefinitionAst fast = new FunctionDefinitionAst(newAst.Extent, false, false, command.Name, paramastList, newAst); CommandVisitor? commandVisitor = Factory.Create(command, _moduleDefinition); - ast.Visit(commandVisitor); + fast.Visit(commandVisitor); } - CreateOutput(_moduleDefinition.ModuleCommandCalls); + CreateOutput(); } - private void CreateOutput(List commandCalls) + private void CreateOutput() { - AnalyzerOutputFormatters.ForEach(output => output.CreateAnalyzerOutupt(commandCalls)); - } - - private static PSModuleInfo LoadModuleFromPath(string modulePath) - { - PowerShell? ps = PowerShell.Create(); - ps.AddScript("Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted; Get-ExecutionPolicy"); - ps.Commands.AddScript($"Import-Module {modulePath} -PassThru"); - return ps.Invoke().First(); - } - - private string GetCommandNamespace(string name, string abosoluteCommandPath) - { - return abosoluteCommandPath - .Replace(_moduleDefinition.Path, "") - .Replace($"{name}.ps1", "") - .Trim('\\') - .Replace("\\", "."); - } - - private List CreateModuleCommandList(PSModuleInfo moduleInfo) - { - List? moduleCommandList = new List(); - foreach (KeyValuePair command in moduleInfo.ExportedFunctions) - { - ModuleCommand? moduleCommand = new ModuleCommand(command.Value.Name, command.Value.Definition, GetCommandNamespace(command.Value.Name, command.Value.ScriptBlock.File)); - try - { - foreach (KeyValuePair param in command.Value.Parameters) - { - ModuleCommandParameter? moduleCommandParam = new ModuleCommandParameter(moduleCommand, param.Value.Name, param.Value.ParameterType.Name); - moduleCommand.Parameters.Add(moduleCommandParam); - } - } - catch - { - Console.WriteLine("Param Error"); - } - - - moduleCommandList.Add(moduleCommand); - } - return moduleCommandList; + AnalyzerOutputFormatters.ForEach(output => output.CreateAnalyzerOutupt(_moduleDefinition)); } } } diff --git a/Source/ModuleAnalyzer.Core/Anaylzer/ModuleAnalyzerBuilder.cs b/Source/ModuleAnalyzer.Core/Anaylzer/ModuleAnalyzerBuilder.cs index 8e0229d..d7999fe 100644 --- a/Source/ModuleAnalyzer.Core/Anaylzer/ModuleAnalyzerBuilder.cs +++ b/Source/ModuleAnalyzer.Core/Anaylzer/ModuleAnalyzerBuilder.cs @@ -19,7 +19,7 @@ public static ModuleAnalyzerBuilder Create(string modulePath) return new ModuleAnalyzerBuilder(modulePath); } - public ModuleAnalyzerBuilder AddOutputWriter(IAnalyzerOutput output) + public ModuleAnalyzerBuilder AddOutputFormatter(IAnalyzerOutput output) { _analyzerOutputs.Add(output); return this; @@ -34,7 +34,7 @@ public ModuleAnalyzerBuilder AddOutputWriter(IAnalyzerOutput output) public ModuleAnalyzer Build() { ModuleAnalyzer? analyzer = new ModuleAnalyzer(_modulePath); - analyzer.SetFactory(_factory); + analyzer.SetCommandVisitorFactory(_factory); _analyzerOutputs.ForEach(output => analyzer.AddOutputFormat(output)); return analyzer; diff --git a/Source/ModuleAnalyzer.Core/Factory/CommandVisitorFactory.cs b/Source/ModuleAnalyzer.Core/Factory/CommandVisitorFactory.cs index 945cb2b..86ddacd 100644 --- a/Source/ModuleAnalyzer.Core/Factory/CommandVisitorFactory.cs +++ b/Source/ModuleAnalyzer.Core/Factory/CommandVisitorFactory.cs @@ -1,5 +1,4 @@ using PsModuleAnalyzer.Core.Model; -using PsModuleAnalyzer.Core.Repository; using PsModuleAnalyzer.Core.Visitor; namespace PsModuleAnalyzer.Core.Factory diff --git a/Source/ModuleAnalyzer.Core/Interfaces/IAnalyzerOutput.cs b/Source/ModuleAnalyzer.Core/Interfaces/IAnalyzerOutput.cs index c755f10..589aeb5 100644 --- a/Source/ModuleAnalyzer.Core/Interfaces/IAnalyzerOutput.cs +++ b/Source/ModuleAnalyzer.Core/Interfaces/IAnalyzerOutput.cs @@ -4,6 +4,6 @@ namespace PsModuleAnalyzer.Core.Interfaces { public interface IAnalyzerOutput { - public void CreateAnalyzerOutupt(List commandCalls); + public void CreateAnalyzerOutupt(ModuleDefinition moduleDefinition); } } diff --git a/Source/ModuleAnalyzer.Core/Model/IModuleCommand.cs b/Source/ModuleAnalyzer.Core/Model/IModuleCommand.cs index afdfa45..20b7d22 100644 --- a/Source/ModuleAnalyzer.Core/Model/IModuleCommand.cs +++ b/Source/ModuleAnalyzer.Core/Model/IModuleCommand.cs @@ -6,7 +6,8 @@ public interface IModuleCommand string Namespace { get; } int NumberOfReferencedBy { get; set; } List Parameters { get; } - List ReferencedBy { get; } + List References { get; } + List ReferencedBy { get; } bool IsExternal { get; } Dictionary GetParametersAsDictionary(); diff --git a/Source/ModuleAnalyzer.Core/Model/ModuleCommand.cs b/Source/ModuleAnalyzer.Core/Model/ModuleCommand.cs index 7e3fecc..d23aaa6 100644 --- a/Source/ModuleAnalyzer.Core/Model/ModuleCommand.cs +++ b/Source/ModuleAnalyzer.Core/Model/ModuleCommand.cs @@ -1,22 +1,33 @@ -namespace PsModuleAnalyzer.Core.Model +using System.Linq; + +namespace PsModuleAnalyzer.Core.Model { public class ModuleCommand : IModuleCommand { + private readonly string _commandFile; + public string Name { get; private set; } public string Definition { get; private set; } - public List References { get; private set; } = new(); - public List ReferencedBy { get; private set; } = new(); + public ModuleDefinition Module { get; private set; } + public List References { get => CalculateReferences(); } + public List ReferencedBy { get => CalculateReferencedBy(); } public List Parameters { get; private set; } = new(); public int NumberOfReferencedBy { get; set; } = 0; public bool IsExternal { get; } public string Namespace { get; private set; } - public ModuleCommand(string name, string definition, string @namespace) + public decimal StabilityIndex { get => CalculateStabilityIndex(); } + + + public ModuleCommand(string name, string definition, string commandFile, ModuleDefinition module) { Name = name; Definition = definition; IsExternal = false; - Namespace = @namespace; + Module = module; + _commandFile = commandFile; + + ConfigureNamespace(); } public Dictionary GetParametersAsDictionary() @@ -28,5 +39,35 @@ public Dictionary GetParametersAsDictionary() } return parameters; } + + private List CalculateReferencedBy() + { + return Module.ModuleCommandCalls + .Where(cmd => cmd.Target.Name == Name) + .Select(cmd => cmd.Source) + .ToList(); + } + + private List CalculateReferences() + { + return Module.ModuleCommandCalls + .Where(cmd => cmd.Source.Name == Name) + .Select(cmd => cmd.Source) + .ToList(); + } + + private decimal CalculateStabilityIndex() + { + return Math.Round((decimal) CalculateReferences().Count / (CalculateReferences().Count + CalculateReferencedBy().Count), 3); + } + + private void ConfigureNamespace() + { + Namespace = _commandFile + .Replace(Module.Path, "") + .Replace($"{Name}.ps1", "") + .Trim('\\') + .Replace("\\", "."); + } } } diff --git a/Source/ModuleAnalyzer.Core/Model/ModuleCommandCall.cs b/Source/ModuleAnalyzer.Core/Model/ModuleCommandCall.cs index cd35307..7621a0b 100644 --- a/Source/ModuleAnalyzer.Core/Model/ModuleCommandCall.cs +++ b/Source/ModuleAnalyzer.Core/Model/ModuleCommandCall.cs @@ -1,15 +1,24 @@ -namespace PsModuleAnalyzer.Core.Model +using System.Reflection; + +namespace PsModuleAnalyzer.Core.Model { public class ModuleCommandCall { - public readonly IModuleCommand Target; + private readonly ModuleDefinition _module; public readonly IModuleCommand Source; + public readonly IModuleCommand Target; public readonly List Parameters = new(); + public int References { get => CalculateReferences(); } - public ModuleCommandCall(IModuleCommand source, IModuleCommand target) + public ModuleCommandCall(IModuleCommand source, IModuleCommand target, ModuleDefinition module) { + _module = module; Source = source; Target = target; } + + private int CalculateReferences() + => _module.ModuleCommandCalls + .Count(calls => calls.Source.Name == Source.Name && calls.Target.Name == Target.Name); } } diff --git a/Source/ModuleAnalyzer.Core/Model/ModuleCommandParameter.cs b/Source/ModuleAnalyzer.Core/Model/ModuleCommandParameter.cs index feb16bd..1026218 100644 --- a/Source/ModuleAnalyzer.Core/Model/ModuleCommandParameter.cs +++ b/Source/ModuleAnalyzer.Core/Model/ModuleCommandParameter.cs @@ -5,6 +5,7 @@ public class ModuleCommandParameter public readonly ModuleCommand Command; public readonly string Name; public readonly string Type; + public int References { get => CalculateReferences(); } public ModuleCommandParameter(ModuleCommand command, string name, string type) { @@ -12,5 +13,12 @@ public ModuleCommandParameter(ModuleCommand command, string name, string type) Name = name; Type = type; } + + private int CalculateReferences() + { + return Command.Module.ModuleCommandCalls + .Where(call => call.Target.Name == Command.Name) + .Sum(call => call.Parameters.Count(param => param.Name == Name)); + } } } diff --git a/Source/ModuleAnalyzer.Core/Model/ModuleDefinition.cs b/Source/ModuleAnalyzer.Core/Model/ModuleDefinition.cs index db8fbaf..1ebcc7a 100644 --- a/Source/ModuleAnalyzer.Core/Model/ModuleDefinition.cs +++ b/Source/ModuleAnalyzer.Core/Model/ModuleDefinition.cs @@ -1,20 +1,26 @@ -using PsModuleAnalyzer.Core.Model; +using System.Management.Automation; -namespace PsModuleAnalyzer.Core.Repository +namespace PsModuleAnalyzer.Core.Model { public class ModuleDefinition { + private readonly PSModuleInfo _psModuleInfo; + public readonly string Name; public readonly string Path; - public readonly HashSet ModuleCommands = new(); + public readonly HashSet ModuleCommands; public readonly List ModuleCommandCalls = new(); public readonly List ModuleCommandParameters = new(); public readonly List ModuleExternalCommand = new(); - public ModuleDefinition(string name, string path) + public ModuleDefinition(string modulePath) { - Name = name; - Path = path; + _psModuleInfo = LoadModuleFromPath(modulePath); + + Name = _psModuleInfo.Name; + Path = _psModuleInfo.ModuleBase; + + ModuleCommands = CreateModuleCommandList(_psModuleInfo); } public ModuleCommand? GetModuleCommand(string name) @@ -56,9 +62,21 @@ public ModuleCommandCall AddModuleCommandCall(ModuleCommandCall moduleCommand) return moduleCommand; } - public bool IsModuleCommand(string name) + public ModuleCommandParameter? GetModuleCommandParameter(string commandName, string parameterName) { - return ModuleCommands.FirstOrDefault(command => command.Name == name) != null ? true : false; + var moduleCommand = GetModuleCommand(commandName); + if(moduleCommand != null) + { + return moduleCommand.Parameters.FirstOrDefault(param => param.Name == parameterName); + } + + var externalCommand = GetModuleExternalCommand(commandName); + if(externalCommand != null) + { + return externalCommand.Parameters.FirstOrDefault(param => param.Name == parameterName); + } + + return null; } public ModuleExternalCommand AddModuleExternalCommandCall(string name, IModuleCommand calledBy) @@ -70,7 +88,7 @@ public ModuleExternalCommand AddModuleExternalCommandCall(string name, IModuleCo ModuleExternalCommand.Add(moduleCommand); } - ModuleCommandCalls.Add(new ModuleCommandCall(calledBy, moduleCommand)); + ModuleCommandCalls.Add(new ModuleCommandCall(calledBy, moduleCommand, this)); return moduleCommand; } @@ -79,5 +97,47 @@ private void RefreshTargetCommandReferences(IModuleCommand moduleCommand) moduleCommand.NumberOfReferencedBy = ModuleCommandCalls.Count(c => c.Target.Name == moduleCommand.Name); } + private static PSModuleInfo LoadModuleFromPath(string modulePath) + { + PowerShell? ps = PowerShell.Create(); + ps.AddScript("Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted; Get-ExecutionPolicy"); + ps.Commands.AddScript($"Import-Module {modulePath} -PassThru"); + return ps.Invoke().First(); + } + + private HashSet CreateModuleCommandList(PSModuleInfo moduleInfo) + { + var defaultParams = new List + { + "Debug", "Verbose", "ErrorAction", "WarningAction", "InformationAction", "WarningVariable", "ErrorVariable", "OutVariable", "InformationVariable" ,"OutBuffer","PipelineVariable","WhatIf" + }; + + HashSet? moduleCommandList = new (); + foreach (KeyValuePair function in moduleInfo.ExportedFunctions) + { + var command = function.Value; + ModuleCommand? moduleCommand = new(command.Name, command.Definition, command.ScriptBlock.File, this); + try + { + foreach (KeyValuePair param in command.Parameters) + { + if (defaultParams.Contains(param.Key)) + continue; + + ModuleCommandParameter? moduleCommandParam = new(moduleCommand, param.Value.Name, param.Value.ParameterType.Name); + moduleCommand.Parameters.Add(moduleCommandParam); + } + } + catch + { + Console.WriteLine("Param Error"); + } + + + moduleCommandList.Add(moduleCommand); + } + return moduleCommandList; + } + } } diff --git a/Source/ModuleAnalyzer.Core/Model/ModuleExternalCommand.cs b/Source/ModuleAnalyzer.Core/Model/ModuleExternalCommand.cs index fb0e135..eb0a51f 100644 --- a/Source/ModuleAnalyzer.Core/Model/ModuleExternalCommand.cs +++ b/Source/ModuleAnalyzer.Core/Model/ModuleExternalCommand.cs @@ -3,11 +3,15 @@ public class ModuleExternalCommand : IModuleCommand { public string Name { get; private set; } - public List ReferencedBy { get; private set; } = new(); - public List Parameters { get; private set; } = new(); + public List ReferencedBy { get; } + public List References { get => new(); } + public List Parameters { get => new(); } public int NumberOfReferencedBy { get; set; } = 0; public bool IsExternal { get; } - public string Namespace { get; private set; } = "External"; + public string _commandFile { get; private set; } = "External"; + + public string Namespace { get => ""; } + public ModuleExternalCommand(string name) { diff --git a/Source/ModuleAnalyzer.Core/Visitor/CommandVisitor.cs b/Source/ModuleAnalyzer.Core/Visitor/CommandVisitor.cs index 352dcab..c710472 100644 --- a/Source/ModuleAnalyzer.Core/Visitor/CommandVisitor.cs +++ b/Source/ModuleAnalyzer.Core/Visitor/CommandVisitor.cs @@ -1,5 +1,4 @@ using PsModuleAnalyzer.Core.Model; -using PsModuleAnalyzer.Core.Repository; using System.Management.Automation.Language; namespace PsModuleAnalyzer.Core.Visitor diff --git a/Source/ModuleAnalyzer.DgmlFormatter/DgmlFormatter.cs b/Source/ModuleAnalyzer.DgmlFormatter/DgmlFormatter.cs index d589fe5..b0ebe6e 100644 --- a/Source/ModuleAnalyzer.DgmlFormatter/DgmlFormatter.cs +++ b/Source/ModuleAnalyzer.DgmlFormatter/DgmlFormatter.cs @@ -16,9 +16,9 @@ public DgmlFormatter(string destinationFile) _destinationFile = destinationFile; } - public void CreateAnalyzerOutupt(List commandCalls) + public void CreateAnalyzerOutupt(ModuleDefinition moduleDefinition) { - commandCalls = commandCalls.Where(commands => !commands.Target.IsExternal).ToList(); + var commandCalls = moduleDefinition.ModuleCommandCalls.Where(commands => !commands.Target.IsExternal).ToList(); DgmlBuilder? builder = new DgmlBuilder(new HubNodeAnalysis(), new NodeReferencedAnalysis(), new CategoryColorAnalysis()) { diff --git a/Source/ModuleAnalyzer.DgmlFormatter/DgmlFormatterExtension.cs b/Source/ModuleAnalyzer.DgmlFormatter/DgmlFormatterExtension.cs index dd9d451..8ae0d98 100644 --- a/Source/ModuleAnalyzer.DgmlFormatter/DgmlFormatterExtension.cs +++ b/Source/ModuleAnalyzer.DgmlFormatter/DgmlFormatterExtension.cs @@ -6,7 +6,7 @@ public static class DgmlFormatterExtension { public static ModuleAnalyzerBuilder AddDgmlFormatter(this ModuleAnalyzerBuilder moduleAnalyzerBuilder, string destinationPath) { - moduleAnalyzerBuilder.AddOutputWriter(new DgmlFormatter(destinationPath)); + moduleAnalyzerBuilder.AddOutputFormatter(new DgmlFormatter(destinationPath)); return moduleAnalyzerBuilder; } }