diff --git a/TopModel.Core/ModelStore.cs b/TopModel.Core/ModelStore.cs index 8cad763c..32eaabc0 100644 --- a/TopModel.Core/ModelStore.cs +++ b/TopModel.Core/ModelStore.cs @@ -190,12 +190,12 @@ public void TryApplyUpdates() referenceErrors.AddRange(GetGlobalErrors()); - foreach (var modelWatcher in _modelWatchers) + Parallel.ForEach(_modelWatchers, modelWatcher => { modelWatcher.OnErrors(affectedFiles .Select(file => (file, errors: referenceErrors.Where(e => e.File == file && !_config.NoWarn.Contains(e.ModelErrorType)))) .ToDictionary(i => i.file, i => i.errors)); - } + }); foreach (var error in referenceErrors.Where(e => e.IsError)) { @@ -219,10 +219,10 @@ public void TryApplyUpdates() _logger.LogInformation("Modèle chargé avec succès."); } - foreach (var modelWatcher in _modelWatchers) + Parallel.ForEach(_modelWatchers, modelWatcher => { modelWatcher.OnFilesChanged(sortedFiles, _storeConfig); - } + }); var generatedFiles = _modelWatchers.Where(m => m.GeneratedFiles != null).SelectMany(m => m.GeneratedFiles!); if (generatedFiles.Any() && !DisableLockfile) diff --git a/TopModel.Generator.Core/ClassGeneratorBase.cs b/TopModel.Generator.Core/ClassGeneratorBase.cs index 03604846..f52111aa 100644 --- a/TopModel.Generator.Core/ClassGeneratorBase.cs +++ b/TopModel.Generator.Core/ClassGeneratorBase.cs @@ -27,17 +27,12 @@ protected virtual bool FilterClass(Class classe) protected override void HandleFiles(IEnumerable files) { - foreach (var file in files) - { - foreach (var classe in file.Classes.Where(FilterClass)) - { - foreach (var (tag, fileName) in Config.Tags.Intersect(classe.Tags) - .Select(tag => (tag, fileName: GetFileName(classe, tag))) - .DistinctBy(t => t.fileName)) - { - HandleClass(fileName, classe, tag); - } - } - } + Parallel.ForEach(files, file => + Parallel.ForEach(file.Classes.Where(FilterClass), classe => + Parallel.ForEach( + Config.Tags.Intersect(classe.Tags) + .Select(tag => (tag, fileName: GetFileName(classe, tag))) + .DistinctBy(t => t.fileName), + l => HandleClass(l.fileName, classe, l.tag)))); } } \ No newline at end of file diff --git a/TopModel.Generator.Core/ClassGroupGeneratorBase.cs b/TopModel.Generator.Core/ClassGroupGeneratorBase.cs index dd780e8e..0c7a2cf0 100644 --- a/TopModel.Generator.Core/ClassGroupGeneratorBase.cs +++ b/TopModel.Generator.Core/ClassGroupGeneratorBase.cs @@ -24,13 +24,16 @@ public ClassGroupGeneratorBase(ILogger> logger) protected override void HandleFiles(IEnumerable files) { - foreach (var file in Classes - .SelectMany(classe => Config.Tags.Intersect(classe.Tags) - .SelectMany(tag => GetFileNames(classe, tag) - .Select(f => (key: (f.FileType, f.FileName), tag, classe)))) - .GroupBy(f => f.key)) - { - HandleFile(file.Key.FileType, file.Key.FileName, file.First().tag, file.Select(f => f.classe).Distinct()); - } + Parallel.ForEach( + Classes + .SelectMany(classe => Config.Tags.Intersect(classe.Tags) + .SelectMany(tag => GetFileNames(classe, tag) + .Select(f => (key: (f.FileType, f.FileName), tag, classe)))) + .GroupBy(f => f.key), + file => HandleFile( + file.Key.FileType, + file.Key.FileName, + file.First().tag, + file.Select(f => f.classe).Distinct())); } } \ No newline at end of file diff --git a/TopModel.Generator.Core/EndpointsGeneratorBase.cs b/TopModel.Generator.Core/EndpointsGeneratorBase.cs index 9189eb9d..fc50652f 100644 --- a/TopModel.Generator.Core/EndpointsGeneratorBase.cs +++ b/TopModel.Generator.Core/EndpointsGeneratorBase.cs @@ -30,22 +30,24 @@ protected virtual bool FilterTag(string tag) protected override void HandleFiles(IEnumerable files) { - foreach (var file in Files.Values - .SelectMany(file => Config.Tags.Intersect(file.AllTags.Where(FilterTag)) - .Select(tag => (tag, file, filePath: GetFilePath(file, tag)))) - .GroupBy(file => file.filePath)) - { - var endpoints = file - .SelectMany(f => f.file.Endpoints) - .Where(e => e.Tags.Intersect(file.Select(f => f.tag)).Any()) - .Distinct() - .OrderBy(e => e.Name, StringComparer.Ordinal) - .ToList(); - - if (endpoints.Any()) + Parallel.ForEach( + Files.Values + .SelectMany(file => Config.Tags.Intersect(file.AllTags.Where(FilterTag)) + .Select(tag => (tag, file, filePath: GetFilePath(file, tag)))) + .GroupBy(file => file.filePath), + file => { - HandleFile(file.Key, file.First().file.Options.Endpoints.FileName, file.First().tag, endpoints); - } - } + var endpoints = file + .SelectMany(f => f.file.Endpoints) + .Where(e => e.Tags.Intersect(file.Select(f => f.tag)).Any()) + .Distinct() + .OrderBy(e => e.Name, StringComparer.Ordinal) + .ToList(); + + if (endpoints.Any()) + { + HandleFile(file.Key, file.First().file.Options.Endpoints.FileName, file.First().tag, endpoints); + } + }); } } \ No newline at end of file diff --git a/TopModel.Generator.Core/MapperGeneratorBase.cs b/TopModel.Generator.Core/MapperGeneratorBase.cs index f3c9b300..99cd9376 100644 --- a/TopModel.Generator.Core/MapperGeneratorBase.cs +++ b/TopModel.Generator.Core/MapperGeneratorBase.cs @@ -61,12 +61,12 @@ protected override void HandleFiles(IEnumerable files) .ToArray(), Tags: f.Select(m => m.Tag))); - foreach (var fileName in fromMappers.Keys.Concat(toMappers.Keys).Distinct()) + Parallel.ForEach(fromMappers.Keys.Concat(toMappers.Keys).Distinct(), fileName => { var (fileFromMappers, fromTags) = fromMappers.ContainsKey(fileName) ? fromMappers[fileName] : (Array.Empty<(Class, FromMapper)>(), Array.Empty()); var (fileToMappers, toTags) = toMappers.ContainsKey(fileName) ? toMappers[fileName] : (Mappers: Array.Empty<(Class, ClassMappings)>(), Tags: Array.Empty()); HandleFile(fileName, fromTags.Concat(toTags).First(), fileFromMappers, fileToMappers); - } + }); } protected virtual bool IsPersistent(Class classe) diff --git a/TopModel.Generator.Core/TranslationGeneratorBase.cs b/TopModel.Generator.Core/TranslationGeneratorBase.cs index c0fe44d7..ca1fa52f 100644 --- a/TopModel.Generator.Core/TranslationGeneratorBase.cs +++ b/TopModel.Generator.Core/TranslationGeneratorBase.cs @@ -50,42 +50,47 @@ protected override void HandleFiles(IEnumerable files) { var modules = new List<(string MainFilePath, string ModuleFilePath, string ModuleName)>(); - foreach (var resources in Classes - .SelectMany(classe => Config.Tags.Intersect(classe.Tags) - .SelectMany(tag => classe.Properties.OfType() - .SelectMany(p => GetResourceFileNames(p, tag) - .Select(f => (key: (MainFilePath: GetMainResourceFilePath(tag, f.Lang), ModuleFilePath: f.FilePath, f.Lang), p))))) - .GroupBy(f => f.key)) - { - var properties = resources.Select(r => r.p.ResourceProperty).Distinct(); - HandleResourceFile(resources.Key.ModuleFilePath, resources.Key.Lang, properties); - - if (resources.Key.MainFilePath != null) + Parallel.ForEach( + Classes + .SelectMany(classe => Config.Tags.Intersect(classe.Tags) + .SelectMany(tag => classe.Properties.OfType() + .SelectMany(p => GetResourceFileNames(p, tag) + .Select(f => (key: (MainFilePath: GetMainResourceFilePath(tag, f.Lang), ModuleFilePath: f.FilePath, f.Lang), p))))) + .GroupBy(f => f.key), + resources => { - modules.Add((resources.Key.MainFilePath, resources.Key.ModuleFilePath, properties.First().Parent.Namespace.RootModule)); - } - } - - foreach (var resources in Classes - .SelectMany(classe => Config.Tags.Intersect(classe.Tags) - .SelectMany(tag => classe.Properties.OfType() - .SelectMany(p => GetCommentResourceFileNames(p, tag) - .Select(f => (key: (MainFilePath: GetMainResourceFilePath(tag, f.Lang), ModuleFilePath: f.FilePath, f.Lang), p))))) - .GroupBy(f => f.key)) - { - var properties = resources.Select(r => r.p.CommentResourceProperty).Distinct(); - HandleCommentResourceFile(resources.Key.ModuleFilePath, resources.Key.Lang, properties); - - if (resources.Key.MainFilePath != null) + var properties = resources.Select(r => r.p.ResourceProperty).Distinct(); + HandleResourceFile(resources.Key.ModuleFilePath, resources.Key.Lang, properties); + + if (resources.Key.MainFilePath != null) + { + modules.Add((resources.Key.MainFilePath, resources.Key.ModuleFilePath, properties.First().Parent.Namespace.RootModule)); + } + }); + + Parallel.ForEach( + Classes + .SelectMany(classe => Config.Tags.Intersect(classe.Tags) + .SelectMany(tag => classe.Properties.OfType() + .SelectMany(p => GetCommentResourceFileNames(p, tag) + .Select(f => (key: (MainFilePath: GetMainResourceFilePath(tag, f.Lang), ModuleFilePath: f.FilePath, f.Lang), p))))) + .GroupBy(f => f.key), + resources => { - modules.Add((resources.Key.MainFilePath, resources.Key.ModuleFilePath, $"{properties.First().Parent.Namespace.RootModule}Comments")); - } - } - - foreach (var g in modules.GroupBy(m => m.MainFilePath)) - { - HandleMainResourceFile(g.Key, g.Select(l => (l.ModuleFilePath, l.ModuleName)).OrderBy(m => m.ModuleFilePath)); - } + var properties = resources.Select(r => r.p.CommentResourceProperty).Distinct(); + HandleCommentResourceFile(resources.Key.ModuleFilePath, resources.Key.Lang, properties); + + if (resources.Key.MainFilePath != null) + { + modules.Add((resources.Key.MainFilePath, resources.Key.ModuleFilePath, $"{properties.First().Parent.Namespace.RootModule}Comments")); + } + }); + + Parallel.ForEach( + modules.GroupBy(m => m.MainFilePath), + g => HandleMainResourceFile( + g.Key, + g.Select(l => (l.ModuleFilePath, l.ModuleName)).OrderBy(m => m.ModuleFilePath))); } protected virtual void HandleMainResourceFile(string mainFilePath, IEnumerable<(string ModuleFilePath, string ModuleName)> modules)