Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added shortcuts for AaC reader strategies #95

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions C4InterFlow/Cli/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ namespace C4InterFlow.Cli
{
public class Utils
{
private static readonly Dictionary<string, Type> _readerStrategiesMap = new()
{
{
"csharp",
Type.GetType("C4InterFlow.Automation.Readers.CSharpAaCReaderStrategy,C4InterFlow.Automation")!
},
{
"yaml",
Type.GetType("C4InterFlow.Automation.Readers.YamlAaCReaderStrategy,C4InterFlow.Automation")!
},
{
"json",
Type.GetType("C4InterFlow.Automation.Readers.JObjectAaCReaderStrategy,C4InterFlow.Automation")!
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change JObjectAaCReaderStrategy to JsonAaCReaderStrategy

}
};

public static IEnumerable<string> ResolveStructures(IEnumerable<string> structures)
{
return AaCReaderContext.Strategy.ResolveStructures(structures);
Expand Down Expand Up @@ -65,21 +81,31 @@ public static void WriteLines(List<string> items, string filePath, bool append =

public static void SetArchitectureAsCodeReaderContext(string[] architectureAsCodeInputPaths, string architectureAsCodeReaderStrategyType)
{
Type strategyType = Type.GetType(architectureAsCodeReaderStrategyType);
Type? strategyType = GetAaCReaderStrategyType(architectureAsCodeReaderStrategyType);

if (strategyType == null)
{
throw new ArgumentException($"Cannot load AaC Reader Strategy Type '{architectureAsCodeReaderStrategyType}'");
}

object strategyTypeInstance = Activator.CreateInstance(strategyType);
var strategyInstance = strategyTypeInstance as IAaCReaderStrategy;

if (strategyInstance == null)
if (strategyTypeInstance is not IAaCReaderStrategy strategyInstance)
{
throw new ArgumentException($"'{architectureAsCodeReaderStrategyType}' is not a valid Architecture As Code Reader Strategy type.");
}

AaCReaderContext.SetCurrentStrategy(strategyInstance, architectureAsCodeInputPaths, new Dictionary<string, string>());
}

private static Type? GetAaCReaderStrategyType(string readerStrategyType)
{
if (_readerStrategiesMap.TryGetValue(readerStrategyType.ToLowerInvariant(), out var strategyType))
{
return strategyType;
}

return Type.GetType(readerStrategyType);
}
}
}