diff --git a/.gitignore b/.gitignore index d0518a7..e0939da 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ build.out/ # eof src/.idea +*.nupkg diff --git a/src/Our.ModelsBuilder/Building/CodeCompilationsArgs.cs b/src/Our.ModelsBuilder/Building/CodeCompilationsArgs.cs new file mode 100644 index 0000000..21d8fdd --- /dev/null +++ b/src/Our.ModelsBuilder/Building/CodeCompilationsArgs.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using Microsoft.CodeAnalysis.CSharp; + +namespace Our.ModelsBuilder.Building +{ + public class CodeCompilationsArgs : EventArgs + { + public LanguageVersion OptionsLanguageVersion { get; } + + public CodeCompilationsArgs(LanguageVersion optionsLanguageVersion, Dictionary dictionary) + { + OptionsLanguageVersion = optionsLanguageVersion; + } + } +} \ No newline at end of file diff --git a/src/Our.ModelsBuilder/Building/CodeGenerationArgs.cs b/src/Our.ModelsBuilder/Building/CodeGenerationArgs.cs new file mode 100644 index 0000000..2ca22ea --- /dev/null +++ b/src/Our.ModelsBuilder/Building/CodeGenerationArgs.cs @@ -0,0 +1,17 @@ +using System; +using Our.ModelsBuilder.Options; + +namespace Our.ModelsBuilder.Building +{ + public class CodeGenerationArgs : EventArgs + { + public ICodeFactory CodeFactory; + public ModelsBuilderOptions Options; + + public CodeGenerationArgs(ICodeFactory codeFactory, ModelsBuilderOptions options) + { + CodeFactory = codeFactory; + Options = options; + } + } +} \ No newline at end of file diff --git a/src/Our.ModelsBuilder/Building/Generator.cs b/src/Our.ModelsBuilder/Building/Generator.cs index 879ef50..6229671 100644 --- a/src/Our.ModelsBuilder/Building/Generator.cs +++ b/src/Our.ModelsBuilder/Building/Generator.cs @@ -11,13 +11,22 @@ public class Generator { private readonly ICodeFactory _codeFactory; private readonly ModelsBuilderOptions _options; - + public static EventHandler CustomActionOnGeneration; + protected virtual void OnGeneration(CodeGenerationArgs e) + { + CustomActionOnGeneration?.Invoke(this, e); + } + public static EventHandler CustomActionOnCompiliation; + protected virtual void OnCompiliation(CodeCompilationsArgs e) + { + CustomActionOnCompiliation?.Invoke(this, e); + } public Generator(ICodeFactory codeFactory, ModelsBuilderOptions options) { _codeFactory = codeFactory; _options = options; } - + public void GenerateModels(string modelsDirectory, string modelsNamespace, string bin) { if (!Directory.Exists(modelsDirectory)) @@ -35,7 +44,7 @@ public void GenerateModels(string modelsDirectory, string modelsNamespace, strin var filename = Path.Combine(modelsDirectory, name + ".generated.cs"); File.WriteAllText(filename, code); }); - + OnGeneration(new CodeGenerationArgs(_codeFactory,_options)); // the idea was to calculate the current hash and to add it as an extra file to the compilation, // in order to be able to detect whether a DLL is consistent with an environment - however the // environment *might not* contain the local partial files, and thus it could be impossible to @@ -46,17 +55,19 @@ public void GenerateModels(string modelsDirectory, string modelsNamespace, strin [assembly:ModelsBuilderAssembly(SourceHash = ""{currentHash}"")] "; */ - + if (bin != null) { // build foreach (var file in Directory.GetFiles(modelsDirectory, "*.generated.cs")) files[file] = File.ReadAllText(file); var compiler = new Compiler(_options.LanguageVersion); + OnCompiliation(new CodeCompilationsArgs(_options.LanguageVersion, files)); // FIXME what is the name of the DLL as soon as we accept several namespaces = an option? compiler.Compile(codeModel.AssemblyName, files, bin); + } - + OutOfDateModelsStatus.Clear(); } diff --git a/src/Our.ModelsBuilder/Our.ModelsBuilder.csproj b/src/Our.ModelsBuilder/Our.ModelsBuilder.csproj index 3801a81..4dec7f2 100644 --- a/src/Our.ModelsBuilder/Our.ModelsBuilder.csproj +++ b/src/Our.ModelsBuilder/Our.ModelsBuilder.csproj @@ -48,6 +48,8 @@ Properties\SolutionInfo.cs + + diff --git a/src/Our.ModelsBuilder/ReferencedAssemblies.cs b/src/Our.ModelsBuilder/ReferencedAssemblies.cs index 05fda0c..0fd5495 100644 --- a/src/Our.ModelsBuilder/ReferencedAssemblies.cs +++ b/src/Our.ModelsBuilder/ReferencedAssemblies.cs @@ -9,7 +9,7 @@ namespace Our.ModelsBuilder { - internal static class ReferencedAssemblies + public sealed class ReferencedAssemblies { private static readonly Lazy> LazyLocations; private static readonly Lazy> LazyReferences;