diff --git a/src/GUI/RevEng.Core/Functions/SqlServerFunctionScaffolder.cs b/src/GUI/RevEng.Core/Functions/SqlServerFunctionScaffolder.cs index 0e7fc6724..3fbca5b9d 100644 --- a/src/GUI/RevEng.Core/Functions/SqlServerFunctionScaffolder.cs +++ b/src/GUI/RevEng.Core/Functions/SqlServerFunctionScaffolder.cs @@ -148,5 +148,10 @@ private void GenerateFunctionStub(Routine function, RoutineModel model) _sb.AppendLine("}"); } } + + protected override string WriteDbContextInterface(ModuleScaffolderOptions scaffolderOptions, RoutineModel model) + { + return null; + } } } diff --git a/src/GUI/RevEng.Core/Procedures/SqlServerStoredProcedureScaffolder.cs b/src/GUI/RevEng.Core/Procedures/SqlServerStoredProcedureScaffolder.cs index d8e16ecb8..8c69589df 100644 --- a/src/GUI/RevEng.Core/Procedures/SqlServerStoredProcedureScaffolder.cs +++ b/src/GUI/RevEng.Core/Procedures/SqlServerStoredProcedureScaffolder.cs @@ -69,38 +69,7 @@ protected override string WriteDbContext(ModuleScaffolderOptions scaffolderOptio _sb.AppendLine(PathHelper.Header); - var usings = new List() - { - "using Microsoft.EntityFrameworkCore", - "using Microsoft.Data.SqlClient", - "using System", - "using System.Collections.Generic", - "using System.Data", - "using System.Threading", - "using System.Threading.Tasks", - $"using {scaffolderOptions.ModelNamespace}", - }; - - if (model.Routines.Any(r => r.SupportsMultipleResultSet)) - { - usings.AddRange(new List() - { - "using Dapper", - "using Microsoft.EntityFrameworkCore.Storage", - "using System.Linq", - }); - } - - if (model.Routines.SelectMany(r => r.Parameters).Any(p => p.ClrType() == typeof(Geometry))) - { - usings.AddRange(new List() - { - "using NetTopologySuite.Geometries", - }); - - } - - usings.Sort(); + var usings = CreateUsings(scaffolderOptions, model); foreach (var statement in usings) { @@ -156,19 +125,6 @@ protected override string WriteDbContext(ModuleScaffolderOptions scaffolderOptio _sb.AppendLine("}"); _sb.AppendLine(); - _sb.AppendLine($"public interface I{scaffolderOptions.ContextName}Procedures"); - _sb.AppendLine("{"); - using (_sb.Indent()) - { - foreach (var procedure in model.Routines) - { - GenerateProcedure(procedure, model, true); - _sb.AppendLine(";"); - } - } - _sb.AppendLine("}"); - _sb.AppendLine(); - _sb.AppendLine($"public partial class {scaffolderOptions.ContextName}Procedures : I{scaffolderOptions.ContextName}Procedures"); _sb.AppendLine("{"); @@ -205,6 +161,90 @@ protected override string WriteDbContext(ModuleScaffolderOptions scaffolderOptio return _sb.ToString(); } + protected override string WriteDbContextInterface(ModuleScaffolderOptions scaffolderOptions, RoutineModel model) + { + if (scaffolderOptions is null) + { + throw new ArgumentNullException(nameof(scaffolderOptions)); + } + + if (model is null) + { + throw new ArgumentNullException(nameof(model)); + } + + _sb = new IndentedStringBuilder(); + + _sb.AppendLine(PathHelper.Header); + + var usings = CreateUsings(scaffolderOptions, model); + + foreach (var statement in usings) + { + _sb.AppendLine($"{statement};"); + } + + _sb.AppendLine(); + _sb.AppendLine($"namespace {scaffolderOptions.ContextNamespace}"); + _sb.AppendLine("{"); + + using (_sb.Indent()) + { + _sb.AppendLine($"public interface I{scaffolderOptions.ContextName}Procedures"); + _sb.AppendLine("{"); + using (_sb.Indent()) + { + foreach (var procedure in model.Routines) + { + GenerateProcedure(procedure, model, true); + _sb.AppendLine(";"); + } + } + _sb.AppendLine("}"); + } + + _sb.AppendLine("}"); + + return _sb.ToString(); + } + + private static List CreateUsings(ModuleScaffolderOptions scaffolderOptions, RoutineModel model) + { + var usings = new List() + { + "using Microsoft.EntityFrameworkCore", + "using Microsoft.Data.SqlClient", + "using System", + "using System.Collections.Generic", + "using System.Data", + "using System.Threading", + "using System.Threading.Tasks", + $"using {scaffolderOptions.ModelNamespace}", + }; + + if (model.Routines.Any(r => r.SupportsMultipleResultSet)) + { + usings.AddRange(new List() + { + "using Dapper", + "using Microsoft.EntityFrameworkCore.Storage", + "using System.Linq", + }); + } + + if (model.Routines.SelectMany(r => r.Parameters).Any(p => p.ClrType() == typeof(Geometry))) + { + usings.AddRange(new List() + { + "using NetTopologySuite.Geometries", + }); + + } + + usings.Sort(); + return usings; + } + private void GenerateDapperSupport() { _sb.AppendLine(); diff --git a/src/GUI/RevEng.Core/Routines/SqlServerRoutineScaffolder.cs b/src/GUI/RevEng.Core/Routines/SqlServerRoutineScaffolder.cs index ba71ec337..666daa723 100644 --- a/src/GUI/RevEng.Core/Routines/SqlServerRoutineScaffolder.cs +++ b/src/GUI/RevEng.Core/Routines/SqlServerRoutineScaffolder.cs @@ -97,6 +97,17 @@ public ScaffoldedModel ScaffoldModel(RoutineModel model, ModuleScaffolderOptions }); } } + + var dbContextInterface = WriteDbContextInterface(scaffolderOptions, model); + + if (!string.IsNullOrEmpty(dbContextInterface)) + { + result.AdditionalFiles.Add(new ScaffoldedFile + { + Code = dbContextInterface, + Path = Path.GetFullPath(Path.Combine(scaffolderOptions.ContextDir, $"I{scaffolderOptions.ContextName}Procedures.cs")), + }); + } var dbContext = WriteDbContext(scaffolderOptions, model); @@ -111,6 +122,8 @@ public ScaffoldedModel ScaffoldModel(RoutineModel model, ModuleScaffolderOptions protected abstract string WriteDbContext(ModuleScaffolderOptions scaffolderOptions, RoutineModel model); + protected abstract string WriteDbContextInterface(ModuleScaffolderOptions scaffolderOptions, RoutineModel model); + private string WriteResultClass(List resultElements, ModuleScaffolderOptions options, string name) { var @namespace = options.ModelNamespace; diff --git a/src/GUI/lib/efreveng.exe.zip b/src/GUI/lib/efreveng.exe.zip index 292a042ba..985e66188 100644 Binary files a/src/GUI/lib/efreveng.exe.zip and b/src/GUI/lib/efreveng.exe.zip differ diff --git a/src/GUI/lib/efreveng50.exe.zip b/src/GUI/lib/efreveng50.exe.zip index 9fea3e3ee..8f3306e83 100644 Binary files a/src/GUI/lib/efreveng50.exe.zip and b/src/GUI/lib/efreveng50.exe.zip differ diff --git a/src/GUI/lib/efreveng60.exe.zip b/src/GUI/lib/efreveng60.exe.zip index 685f747ba..27ba39f66 100644 Binary files a/src/GUI/lib/efreveng60.exe.zip and b/src/GUI/lib/efreveng60.exe.zip differ