static void ThrowIfDuplicateArtifacts(ArtifactsConfiguration artifacts, IBuildToolLogger logger) { var idMap = new Dictionary <ArtifactId, ClrType>(); bool foundDuplicate = false; foreach (var artifactDefinitionEntry in artifacts.GetAllArtifactDefinitions()) { if (idMap.ContainsKey(artifactDefinitionEntry.Key)) { foundDuplicate = true; var artifactId = artifactDefinitionEntry.Key; var clrType = idMap[artifactId]; logger.Error($"The artifacts '{clrType.TypeString}' and '{artifactDefinitionEntry.Value.Type.TypeString}' has the same ArtifactId: '{artifactId}'"); } else { idMap.Add(artifactDefinitionEntry.Key, artifactDefinitionEntry.Value.Type); } } if (foundDuplicate) { throw new DuplicateArtifact(); } }
/// <summary> /// Instantiates an instance of <see cref="ProxiesBuilder"/> /// </summary> /// <param name="templateLoader"></param> /// <param name="artifacts">The discovered types of artifacts in the Bounded Context's assemblies</param> /// <param name="artifactTypes"></param> /// <param name="logger"></param> public ProxiesBuilder(TemplateLoader templateLoader, Type[] artifacts, DolittleArtifactTypes artifactTypes, IBuildToolLogger logger) { _templateLoader = templateLoader; _artifacts = artifacts; _artifactTypes = artifactTypes; _logger = logger; }
/// <summary> /// Instantiates an instance of <see cref="ArtifactsConfigurationBuilder"/> /// </summary> /// <param name="artifacts">The discovered types of artifacts in the Bounded Context's assemblies</param> /// <param name="currentArtifactsConfiguration">The current <see cref="ArtifactsConfiguration"/> that will be used as a base for building a valid updated configuration that is returned from Build</param> /// <param name="artifactTypes">A list of <see cref="ArtifactType"/> which represents the different artifact types</param> /// <param name="logger"></param> public ArtifactsConfigurationBuilder(Type[] artifacts, ArtifactsConfiguration currentArtifactsConfiguration, DolittleArtifactTypes artifactTypes, IBuildToolLogger logger) { _artifacts = artifacts; _logger = logger; _artifactTypes = artifactTypes; _currentArtifactsConfiguration = currentArtifactsConfiguration; }
/// <summary> /// Instantiates and instance of <see cref="ArtifactsDiscoverer"/> /// </summary> /// <param name="assemblyContext"></param> /// <param name="artifactTypes"></param> /// <param name="logger"></param> public ArtifactsDiscoverer(IAssemblyContext assemblyContext, DolittleArtifactTypes artifactTypes, IBuildToolLogger logger) { _assemblyContext = assemblyContext; _artifactTypes = artifactTypes.ArtifactTypes; _logger = logger; Artifacts = DiscoverArtifacts(); }
/// <summary> /// Instantiates and instance of <see cref="EventProcessorDiscoverer"/> /// </summary> /// <param name="assemblyContext"></param> /// <param name="logger"></param> public EventProcessorDiscoverer(IAssemblyContext assemblyContext, IBuildToolLogger logger) { _assemblyContext = assemblyContext; _logger = logger; }
/// <summary> /// Initializes an instance of <see cref="ArtifactsConfigurationHandler"/> /// </summary> /// <param name="configurationManager"></param> /// <param name="artifactTypes">A list of <see cref="ArtifactType"/> which represents the different artifact types</param> /// <param name="logger"></param> public ArtifactsConfigurationHandler(IArtifactsConfigurationManager configurationManager, DolittleArtifactTypes artifactTypes, IBuildToolLogger logger) { _configurationManager = configurationManager; _artifactTypes = artifactTypes; _logger = logger; }
static void ThrowIfDuplicateId(Applications.Configuration.Topology topology, bool useModules, IBuildToolLogger logger) { var idMap = new Dictionary <Guid, string>(); bool hasDuplicateId = false; if (useModules) { foreach (var module in topology.Modules) { if (idMap.ContainsKey(module.Key)) { hasDuplicateId = true; var name = idMap[module.Key]; logger.Error( $"Duplicate id found in bounded-context topology.\n" + $"The id: '{module.Key.Value}' is already occupied by the Module/Feature: '{name}' "); } else { idMap.Add(module.Key, module.Value.Name); } ThrowIfDuplicateId(module.Value.Features, ref idMap, ref hasDuplicateId, logger); } } else { ThrowIfDuplicateId(topology.Features, ref idMap, ref hasDuplicateId, logger); } if (hasDuplicateId) { throw new InvalidTopology("Bounded context topology has one or more Features/Modules with the same Id"); } }
/// <summary> /// Validates the <see cref="Applications.Configuration.Topology"/> /// </summary> public static void ValidateTopology(this Applications.Configuration.Topology topology, bool useModules, IBuildToolLogger logger) { ThrowIfDuplicateId(topology, useModules, logger); }
static void ThrowIfDuplicateId(IDictionary <Feature, FeatureDefinition> features, ref Dictionary <Guid, string> idMap, ref bool hasDuplicateId, IBuildToolLogger logger) { foreach (var feature in features) { if (idMap.ContainsKey(feature.Key)) { hasDuplicateId = true; var name = idMap[feature.Key]; logger.Error( $"Duplicate id found in bounded-context topology.\n" + $"The id: '{feature.Key.Value}' is already occupied by the Module/Feature: '{name}' "); } else { idMap.Add(feature.Key, feature.Value.Name); } ThrowIfDuplicateId(feature.Value.SubFeatures, ref idMap, ref hasDuplicateId, logger); } }
/// <summary> /// Instantiates an instance of <see cref="TopologyBuilder"/> /// </summary> /// <param name="artifacts">The discovered types of artifacts in the Bounded Context's assemblies</param> /// <param name="boundedContextTopology">The <see cref="BoundedContextConfiguration"/> that will be modified, validated and returned from Build</param> /// <param name="logger"></param> public TopologyBuilder(Type[] artifacts, BoundedContextTopology boundedContextTopology, IBuildToolLogger logger) { _artifactTypes = artifacts; _logger = logger; _configuration = boundedContextTopology; }
/// <summary> /// Validates the <see cref="ArtifactsConfiguration"/> based on the bounded context's topology and the discoved artifact types in the assemblies of the bounded context /// </summary> public static void ValidateArtifacts(this ArtifactsConfiguration artifacts, BoundedContextTopology boundedContextTopology, Type[] types, IBuildToolLogger logger) { ThrowIfDuplicateArtifacts(artifacts, logger); WarnIfFeatureMissingFromTopology(artifacts, boundedContextTopology, logger); WarnIfArtifactNoLongerInStructure(artifacts, types, logger); }
static void WarnIfArtifactNoLongerInStructure(ArtifactsConfiguration artifacts, IEnumerable <Type> types, IBuildToolLogger logger) { var artifactDefinitions = new Dictionary <ArtifactId, ArtifactDefinition>(); foreach (var artifactDefinitionEntry in artifacts.GetAllArtifactDefinitions()) { if (!types.Contains(artifactDefinitionEntry.Value.Type.GetActualType())) { artifactDefinitions.Add(artifactDefinitionEntry.Key, artifactDefinitionEntry.Value); } } if (artifactDefinitions.Any()) { logger.Warning("There are artifacts that are not found in the Bounded Context's artifacts file:"); logger.Warning("Artifacts:"); foreach (var artifactDefinitionEntry in artifactDefinitions) { logger.Warning($"\tArtifact: '{artifactDefinitionEntry.Key.Value}' - '{artifactDefinitionEntry.Value.Type.TypeString} @{artifactDefinitionEntry.Value.Generation.Value}'"); } throw new ArtifactNoLongerInStructure(); } }
static void WarnIfFeatureMissingFromTopology(ArtifactsConfiguration artifacts, BoundedContextTopology boundedContextTopology, IBuildToolLogger logger) { Dictionary <Feature, FeatureName> featureMap = boundedContextTopology.RetrieveAllFeatureIds(); foreach (var artifact in artifacts) { if (!featureMap.ContainsKey(artifact.Key)) { logger.Warning($"Found artifacts under a Feature that does not exist in the topology. Feature: '{artifact.Key}':"); logger.Warning("Artifacts:"); var artifactDefinitions = artifacts.GetAllArtifactDefinitions(artifact.Key); foreach (var definitionEntry in artifactDefinitions) { logger.Warning($"\tArtifact: '{definitionEntry.Key.Value}' - '{definitionEntry.Value.Type.TypeString} @{definitionEntry.Value.Generation.Value}'"); } } } }
/// <summary> /// Instantiates an instance of <see cref="TopologyConfigurationHandler"/> /// </summary> /// <param name="configurationManager"></param> /// <param name="logger"></param> public TopologyConfigurationHandler(ITopologyConfigurationManager configurationManager, IBuildToolLogger logger) { _configurationManager = configurationManager; _logger = logger; }