/// <summary> /// Loads the <see cref="BoundedContextConfiguration"/> from file and uses it to build the <see cref="BoundedContextConfiguration"/> using the <see cref="TopologyBuilder"/> /// </summary> /// <param name="types">The discovered artifact types from the bounded context's assemblies</param> /// <param name="parsingResults"></param> public Applications.Configuration.Topology Build(Type[] types, ArgumentsParsingResult parsingResults) { var topology = _configurationManager.Load(); var boundedContextTopology = new BoundedContextTopology(topology, parsingResults.UseModules, parsingResults.NamespaceSegmentsToStrip); return(new TopologyBuilder(types, boundedContextTopology, _logger).Build()); }
/// <summary> /// Generates all proxies for all relevant artifacts and writes them as files in their corresponding feature structure /// </summary> public void GenerateProxies(ArtifactsConfiguration artifactsConfiguration, ArgumentsParsingResult parsingResults) { var proxies = new List <Proxy>(); GenerateProxies(artifactsConfiguration, parsingResults, _templateLoader.CommandProxyTemplate, "command", GenerateCommandProxy, ref proxies); GenerateProxies(artifactsConfiguration, parsingResults, _templateLoader.QueryProxyTemplate, "query", GenereateQueryProxy, ref proxies); GenerateProxies(artifactsConfiguration, parsingResults, _templateLoader.ReadModelProxyTemplate, "read model", GenerateReadModelProxy, ref proxies); WriteProxiesToFile(proxies.ToArray()); }
Proxy CreateProxy(Type artifact, string fileContent, ArgumentsParsingResult parsingResults) { var filePath = GenerateFilePath(artifact, parsingResults, artifact.Name); return(new Proxy() { Content = fileContent, FullFilePath = filePath }); }
/// <summary> /// Returns a string that represents the namespace of the given <see cref="Type"/> where the NamespaceToStrip-segments are removed from the namespace /// </summary> /// <param name="type"></param> /// <param name="parsingResults"></param> /// <returns></returns> public static string StripExcludedNamespaceSegments(this Type type, ArgumentsParsingResult parsingResults) { var area = new Area() { Value = type.Namespace.Split(".").First() }; var segmentList = type.Namespace.Split(".").Skip(1).ToList(); if (parsingResults.NamespaceSegmentsToStrip.ContainsKey(area)) { foreach (var segment in parsingResults.NamespaceSegmentsToStrip[area]) { segmentList.Remove(segment); } } return(string.Join(".", segmentList)); }
void GenerateProxies( ArtifactsConfiguration artifactsConfiguration, ArgumentsParsingResult parsingResults, Func <object, string> template, string artifactTypeName, Func <Type, ArtifactsConfiguration, ArgumentsParsingResult, Func <object, string>, Proxy> ProxyGeneratorFunction, ref List <Proxy> proxies) { var artifactType = _artifactTypes.ArtifactTypes.Single(_ => _.TypeName.Equals(artifactTypeName)).Type; var artifacts = _artifacts.Where(_ => artifactType.IsAssignableFrom(_)); foreach (var artifact in artifacts) { var proxy = ProxyGeneratorFunction(artifact, artifactsConfiguration, parsingResults, template); if (proxy != null) { proxies.Add(proxy); } } }
/// <summary> /// Creates the proxies given a list of artifacts and configurations /// </summary> /// <param name="artifacts"></param> /// <param name="parsingResults"></param> /// <param name="artifactsConfiguration"></param> public void CreateProxies(Type[] artifacts, ArgumentsParsingResult parsingResults, ArtifactsConfiguration artifactsConfiguration) { var builder = new ProxiesBuilder(_templateLoader, artifacts, _artifactTypes, _logger); builder.GenerateProxies(artifactsConfiguration, parsingResults); }
Proxy GenerateCommandProxy(Type artifact, ArtifactsConfiguration artifactsConfig, ArgumentsParsingResult parsingResults, Func <object, string> template) { _logger.Trace($"Creating command proxy for {ClrType.FromType(artifact).TypeString}"); var artifactId = GetArtifactId(artifact, artifactsConfig); var handlebarsCommand = new HandlebarsCommand() { CommandName = artifact.Name, ArtifactId = artifactId.Value.ToString() }; var setableProperties = artifact.GetSettableProperties(); if (setableProperties.Any()) { handlebarsCommand.Properties = CreateProxyProperties(setableProperties); } return(CreateProxy(artifact, template(handlebarsCommand), parsingResults)); }
string GenerateFilePath(Type artifact, ArgumentsParsingResult parsingResults, string artifactName) { var @namespace = artifact.StripExcludedNamespaceSegments(parsingResults); return(Path.Join(parsingResults.ProxiesBasePath, @namespace.Replace('.', '/'), $"{artifactName}.js")); }
Proxy GenerateReadModelProxy(Type artifact, ArtifactsConfiguration artifactsConfig, ArgumentsParsingResult parsingResults, Func <object, string> template) { _logger.Trace($"Creating read model proxy for {ClrType.FromType(artifact).TypeString}"); var artifactId = GetArtifactId(artifact, artifactsConfig); var artifactDefinition = GetArtifactDefinition(artifact, artifactsConfig); var handlebarsReadmodel = new HandlebarsReadmodel() { ReadModelName = artifact.Name, ReadModelArtifactId = artifactId.Value.ToString(), ReadModelGeneration = artifactDefinition.Generation.Value.ToString() }; var setableProperties = artifact.GetSettableProperties(); if (setableProperties.Any()) { handlebarsReadmodel.Properties = CreateProxyProperties(setableProperties); } return(CreateProxy(artifact, template(handlebarsReadmodel), parsingResults)); }
Proxy GenereateQueryProxy(Type artifact, ArtifactsConfiguration artifactsConfig, ArgumentsParsingResult parsingResults, Func <object, string> template) { _logger.Trace($"Creating query proxy for {ClrType.FromType(artifact).TypeString}"); var handlebarsQuery = new HandlebarsQuery() { ClrType = artifact.FullName, QueryName = artifact.Name }; var setableProperties = artifact.GetSettableProperties(); if (setableProperties.Any()) { handlebarsQuery.Properties = CreateProxyProperties(setableProperties); } return(CreateProxy(artifact, template(handlebarsQuery), parsingResults)); }