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");
            }
        }
Example #2
0
        void ThrowIfLoadedTopologyIsInvalid(bool useModules, Applications.Configuration.Topology topology)
        {
            if (useModules)
            {
                if (HasFeatures(topology))
                {
                    throw new InvalidTopology("Topology cannot have root level Features when DolittleUseModules is true");
                }

                if (topology.Modules == null)
                {
                    throw new InvalidTopology("Topology must define a Modules list when DolittleUseModules is true");
                }
            }
            else
            {
                if (topology.Features == null)
                {
                    throw new InvalidTopology("Topology must define a Feature list when DolittleUseModules is false");
                }

                if (HasModules(topology))
                {
                    throw new InvalidTopology("Topology cannot have Modules when DolittleUseModules is false");
                }
            }
        }
        /// <summary>
        /// Loads the current <see cref="ArtifactsConfiguration"/> from file and uses it to build the updated <see cref="ArtifactsConfiguration"/> using the <see cref="ArtifactsConfigurationBuilder"/>
        /// </summary>
        /// <param name="types">The discovered artifact types from the bounded context's assemblies</param>
        /// <param name="topology">The <see cref="Applications.Configuration.Topology"/> that's used for building the <see cref="ArtifactsConfiguration"/></param>
        /// <param name="parsingResults"></param>
        public ArtifactsConfiguration Build(Type[] types, Applications.Configuration.Topology topology, ArgumentsParsingResult parsingResults)
        {
            var artifactsConfiguration = _configurationManager.Load();
            var boundedContextTopology = new BoundedContextTopology(topology, parsingResults.UseModules, parsingResults.NamespaceSegmentsToStrip);

            return(new ArtifactsConfigurationBuilder(types, artifactsConfiguration, _artifactTypes, _logger).Build(boundedContextTopology));
        }
Example #4
0
        /// <inheritdoc/>
        public void Save(Applications.Configuration.Topology configuration)
        {
            var path = GetPath();
            var json = _serializer.ToJson(configuration, _serializationOptions);

            File.WriteAllText(path, json);
        }
Example #5
0
        /// <summary>
        /// Loads the current <see cref="ArtifactsConfiguration"/> from file and uses it to build the updated <see cref="ArtifactsConfiguration"/> using the <see cref="ArtifactsConfigurationBuilder"/>.
        /// </summary>
        /// <param name="types">The discovered artifact types from the bounded context's assemblies.</param>
        /// <param name="topology">The <see cref="Applications.Configuration.Topology"/> that's used for building the <see cref="ArtifactsConfiguration"/>.</param>
        /// <param name="configuration">Current <see cref="BuildTaskConfiguration"/>.</param>
        /// <returns>The built <see cref="ArtifactsConfiguration"/>.</returns>
        public ArtifactsConfiguration Build(IEnumerable <Type> types, Applications.Configuration.Topology topology, BuildTaskConfiguration configuration)
        {
            var artifactsConfiguration = _configurationManager.Load();
            var boundedContextTopology = new BoundedContextTopology(topology, configuration.UseModules, configuration.NamespaceSegmentsToStrip);

            return(new ArtifactsConfigurationBuilder(types, artifactsConfiguration, _artifactTypes, _buildMessages).Build(boundedContextTopology));
        }
 /// <summary>
 /// Instantiates an instance of <see cref="BoundedContextTopology"/>
 /// </summary>
 /// <param name="topology"></param>
 /// <param name="useModules"></param>
 /// <param name="namespaceSegmentsToStrip"></param>
 public BoundedContextTopology(Applications.Configuration.Topology topology, bool useModules, IDictionary <Area, IEnumerable <string> > namespaceSegmentsToStrip)
 {
     Topology   = topology;
     UseModules = useModules;
     NamespaceSegmentsToStrip = namespaceSegmentsToStrip;
 }
 /// <summary>
 /// Validates the <see cref="Applications.Configuration.Topology"/>.
 /// </summary>
 /// <param name="topology"><see cref="Applications.Configuration.Topology"/> to validate.</param>
 /// <param name="useModules">true if we're using modules, false if not.</param>
 /// <param name="buildMessages"><see cref="IBuildMessages"/> for outputting build messages.</param>
 public static void ValidateTopology(this Applications.Configuration.Topology topology, bool useModules, IBuildMessages buildMessages)
 {
     ThrowIfDuplicateId(topology, useModules, buildMessages);
 }
Example #8
0
 static bool HasModules(Applications.Configuration.Topology topology) =>
 topology.Modules != null && topology.Modules.Any();
Example #9
0
 static bool HasFeatures(Applications.Configuration.Topology topology) =>
 topology.Features != null && topology.Features.Any();
 internal void Save(Applications.Configuration.Topology topology)
 {
     _configurationManager.Save(topology);
 }
 /// <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 bool HasModules(Applications.Configuration.Topology topology) => topology.Modules?.Any() == true;
 static bool HasFeatures(Applications.Configuration.Topology topology) => topology.Features?.Any() == true;