Skip to content

Commit a6a75fb

Browse files
committed
Update Odata and EntityFramework actions
1 parent 0a3ed9a commit a6a75fb

File tree

51 files changed

+299
-64
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+299
-64
lines changed

Angular/KY.Generator.Angular.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Authors>KY-Programming</Authors>
66
<Company>KY-Programming</Company>
77
<Product>KY.Generator</Product>
8-
<Version>2.2.0-rc.10</Version>
8+
<Version>2.2.0</Version>
99
<Copyright>2019 - KY-Programming</Copyright>
1010
<Description>Angular Module for KY-Generator</Description>
1111
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>

AspDotNet/KY.Generator.AspDotNet.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<Company>KY-Programming</Company>
66
<Authors>KY-Programming</Authors>
7-
<Version>2.2.0-rc.10</Version>
7+
<Version>2.2.0</Version>
88
<Product>KY.Generator</Product>
99
<Description>ASP.net Module for KY-Generator</Description>
1010
<Copyright>2019 - KY-Programming</Copyright>

AspDotNet/Writers/AspDotNetEntityControllerWriter.cs

+11-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,17 @@ public void Write(AspDotNetWriteConfiguration configuration, List<ITransferObjec
3838

3939
if (controllerConfiguration.Get != null)
4040
{
41-
// TODO: Implement filters
42-
controller.AddMethod("Get", Code.Generic("IEnumerable", modelType))
43-
.WithAttribute("HttpGet", Code.String(controllerConfiguration.Get.Name ?? "[action]"))
44-
.Code.AddLine(Code.Return(Code.This().Field(repositoryField).Method("Get")));
41+
controller.AddUsing("System.Linq");
42+
MethodTemplate method = controller.AddMethod("Get", Code.Generic("IEnumerable", modelType))
43+
.WithAttribute("HttpGet", Code.String(controllerConfiguration.Get.Name ?? "[action]"));
44+
DeclareTemplate queryable = Code.Declare(Code.Generic("IQueryable", modelType), "queryable", Code.This().Field(repositoryField).Method("Get"));
45+
method.Code.AddLine(queryable);
46+
foreach (PropertyTransferObject property in entity.Model.Properties)
47+
{
48+
ParameterTemplate parameter = method.AddParameter(property.Type.ToTemplate(), property.Name, Code.Local("default")).FormatName(configuration.Language, configuration.FormatNames);
49+
method.Code.AddLine(Code.If(Code.Local(parameter).NotEquals().Local("default"), x => x.Code.AddLine(Code.Local(queryable).Assign(Code.Local(queryable).Method("Where", Code.Lambda("x", Code.Local("x").Property(property.Name).Equals().Local(parameter)))).Close())));
50+
}
51+
method.Code.AddLine(Code.Return(Code.Local(queryable)));
4552
}
4653
if (controllerConfiguration.Post != null)
4754
{

CLI.Core.Minimal/nuget.nuspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>KY.Generator.CLI.Core.Minimal</id>
5-
<version>2.2.0-rc.10</version>
5+
<version>2.2.0</version>
66
<title>KY.Generator.CLI.Core.Minimal</title>
77
<authors>KY-Programming</authors>
88
<owners>KY-Programming</owners>

CLI.Core.Standalone/nuget.nuspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>KY.Generator.CLI.Core.Standalone</id>
5-
<version>2.2.0-rc.10</version>
5+
<version>2.2.0</version>
66
<title>KY.Generator.CLI.Core.Standalone</title>
77
<authors>KY-Programming</authors>
88
<owners>KY-Programming</owners>

CLI.Core/nuget.nuspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>KY.Generator.CLI.Core</id>
5-
<version>2.2.0-rc.10</version>
5+
<version>2.2.0</version>
66
<title>KY.Generator.CLI.Core</title>
77
<authors>KY-Programming</authors>
88
<owners>KY-Programming</owners>

CLI.Minimal/nuget.nuspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>KY.Generator.CLI.Minimal</id>
5-
<version>2.2.0-rc.10</version>
5+
<version>2.2.0</version>
66
<title>KY.Generator.CLI.Full</title>
77
<authors>KY-Programming</authors>
88
<owners>KY-Programming</owners>

CLI.Standalone/nuget.nuspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>KY.Generator.CLI.Standalone</id>
5-
<version>2.2.0-rc.10</version>
5+
<version>2.2.0</version>
66
<title>KY.Generator.CLI</title>
77
<authors>KY-Programming</authors>
88
<owners>KY-Programming</owners>

CLI/nuget.nuspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>KY.Generator.CLI</id>
5-
<version>2.2.0-rc.10</version>
5+
<version>2.2.0</version>
66
<title>KY.Generator.CLI</title>
77
<authors>KY-Programming</authors>
88
<owners>KY-Programming</owners>

Core.Tests/Models/TestConfiguration.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using KY.Generator.Configurations;
1+
using System.Collections.Generic;
2+
using KY.Generator.Configurations;
23
using KY.Generator.Languages;
34

45
namespace KY.Generator.Core.Tests.Models
@@ -10,6 +11,7 @@ internal class TestConfiguration : IModelConfiguration
1011
public string RelativePath { get; set; }
1112
public bool AddHeader { get; set; }
1213
public bool SkipNamespace { get; set; }
14+
public List<string> Usings { get; }
1315
public bool FieldsToProperties { get; set; }
1416
public bool PropertiesToFields { get; set; }
1517
public bool FormatNames { get; set; }
@@ -18,6 +20,7 @@ internal class TestConfiguration : IModelConfiguration
1820
public TestConfiguration()
1921
{
2022
this.Language = new TestLanguage();
23+
this.Usings = new List<string>();
2124
}
2225
}
2326
}
+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace KY.Generator.Configurations
1+
using System.Collections.Generic;
2+
3+
namespace KY.Generator.Configurations
24
{
35
public interface IModelConfiguration : IFormattableConfiguration
46
{
@@ -7,5 +9,6 @@ public interface IModelConfiguration : IFormattableConfiguration
79
string RelativePath { get; }
810
bool AddHeader { get; }
911
bool SkipNamespace { get; }
12+
List<string> Usings { get; }
1013
}
1114
}

Core/Configurations/ModelWriteConfiguration.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using KY.Generator.Configuration;
1+
using System.Collections.Generic;
2+
using KY.Generator.Configuration;
23

34
namespace KY.Generator.Configurations
45
{
@@ -8,8 +9,14 @@ public class ModelWriteConfiguration : ConfigurationBase, IModelConfiguration
89
public string Namespace { get; set; }
910
public string RelativePath { get; set; }
1011
public bool SkipNamespace { get; set; }
12+
public List<string> Usings { get; set; }
1113
public bool FieldsToProperties { get; set; }
1214
public bool PropertiesToFields { get; set; }
1315
public bool FormatNames { get; set; }
16+
17+
public ModelWriteConfiguration()
18+
{
19+
this.Usings = new List<string>();
20+
}
1421
}
1522
}

Core/KY.Generator.Core.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Company>KY-Programming</Company>
66
<Authors>KY-Programming</Authors>
77
<Product>KY.Generator</Product>
8-
<Version>2.2.0-rc.10</Version>
8+
<Version>2.2.0</Version>
99
<Description>Core elements for KY-Generator</Description>
1010
<Copyright>2019 - KY-Programming</Copyright>
1111
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>

Core/Templates/Extensions/ChainedCodeFragmentExtension.cs

+20
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,26 @@ public static LocalVariableTemplate Local(this ChainedCodeFragment template, str
138138
{
139139
return new LocalVariableTemplate(name).Chain(template);
140140
}
141+
142+
public static LocalVariableTemplate Local(this ChainedCodeFragment template, FieldTemplate type)
143+
{
144+
return new LocalVariableTemplate(type.Name).Chain(template);
145+
}
146+
147+
public static LocalVariableTemplate Local(this ChainedCodeFragment template, PropertyTemplate type)
148+
{
149+
return new LocalVariableTemplate(type.Name).Chain(template);
150+
}
151+
152+
public static LocalVariableTemplate Local(this ChainedCodeFragment template, DeclareTemplate type)
153+
{
154+
return new LocalVariableTemplate(type.Name).Chain(template);
155+
}
156+
157+
public static LocalVariableTemplate Local(this ChainedCodeFragment template, ParameterTemplate type)
158+
{
159+
return new LocalVariableTemplate(type.Name).Chain(template);
160+
}
141161

142162
public static ThisTemplate This(this ChainedCodeFragment template)
143163
{

Core/Transfer/Writers/ModelWriter.cs

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ protected virtual ClassTemplate WriteClass(IModelConfiguration configuration, Mo
105105
{
106106
this.AddUsing(model.BasedOn, classTemplate, configuration.Language);
107107
}
108+
configuration.Usings?.ForEach(x => classTemplate.AddUsing(x, null, null));
108109

109110
classTemplate.IsInterface = model.IsInterface;
110111
classTemplate.IsAbstract = model.IsAbstract;

Core/Writers/PropertyWriter.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public class PropertyWriter : ITemplateWriter
1010
public virtual void Write(ICodeFragment fragment, IOutputCache output)
1111
{
1212
PropertyTemplate template = (PropertyTemplate)fragment;
13-
PropertyTemplate previousProperty = output.LastFragments.OfType<PropertyTemplate>().Skip(1).FirstOrDefault();
14-
if (previousProperty?.Attributes.Count > 0)
13+
PropertyTemplate previousProperty = output.LastFragments.TakeWhile(x => !(x is ClassTemplate)).OfType<PropertyTemplate>().Skip(1).FirstOrDefault();
14+
if (previousProperty?.Attributes.Count > 0 || previousProperty != null && template.Attributes.Count > 0)
1515
{
1616
output.BreakLine();
1717
}

Csharp/KY.Generator.CSharp.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Authors>KY-Programming</Authors>
66
<Company>KY-Programming</Company>
77
<Product>KY.Generator</Product>
8-
<Version>2.2.0-rc.10</Version>
8+
<Version>2.2.0</Version>
99
<Description>C# Module for KY-Generator</Description>
1010
<Copyright>2019 - KY-Programming</Copyright>
1111
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>

Csharp/Writers/AttributeWriter.cs

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Collections.Generic;
2-
using System.Linq;
32
using KY.Generator.Languages;
43
using KY.Generator.Output;
54
using KY.Generator.Templates;
@@ -19,10 +18,6 @@ public AttributeWriter(BaseLanguage language)
1918
public virtual void Write(ICodeFragment fragment, IOutputCache output)
2019
{
2120
AttributeTemplate template = (AttributeTemplate)fragment;
22-
if (output.LastFragments.Skip(3/*self, attached property, type*/).FirstOrDefault() is PropertyTemplate)
23-
{
24-
output.BreakLine();
25-
}
2621
output.Add("[")
2722
.Add(template.Name);
2823
if (template.HasValue || template.Properties.Count > 0)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Collections.Generic;
2+
3+
namespace KY.Generator.EntityFramework.Configurations
4+
{
5+
internal class EntityFrameworkDataContextConfiguration
6+
{
7+
public string RelativePath { get; set; }
8+
public string Names { get; set; }
9+
public string Namespace { get; set; }
10+
public bool SuppressConstructor { get; set; }
11+
public bool SuppressLoadTypeConfig { get; set; }
12+
public List<string> Usings { get; set; }
13+
public int CommandTimeout { get; set; } = 300;
14+
public List<EntityFrameworkStoredProcedure> StoredProcedures { get; set; }
15+
16+
public EntityFrameworkDataContextConfiguration()
17+
{
18+
this.StoredProcedures = new List<EntityFrameworkStoredProcedure>();
19+
20+
}
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace KY.Generator.EntityFramework.Configurations
2+
{
3+
public class EntityFrameworkStoredProcedure
4+
{
5+
public string Name { get; }
6+
7+
public EntityFrameworkStoredProcedure(string name)
8+
{
9+
this.Name = name;
10+
}
11+
}
12+
}

EntityFramework/Configurations/EntityFrameworkWriteConfiguration.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ internal class EntityFrameworkWriteConfiguration : ConfigurationBase
1212
public List<EntityFrameworkWriteRepositoryConfiguration> Repositories { get; set; }
1313
public virtual bool IsCore => false;
1414
public List<string> Usings { get; set; }
15-
public int CommandTimeout { get; set; } = 300;
15+
//public List<IFluentLanguageElement> Fluent { get; private set; }
16+
public EntityFrameworkDataContextConfiguration DataContext { get; set; }
1617

1718
public EntityFrameworkWriteConfiguration()
1819
{
1920
this.Language = CsharpLanguage.Instance;
2021
this.Repositories = new List<EntityFrameworkWriteRepositoryConfiguration>();
2122
this.Usings= new List<string>();
23+
//this.Fluent = new List<IFluentLanguageElement>();
24+
this.DataContext = new EntityFrameworkDataContextConfiguration();
2225
}
2326
}
2427
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace KY.Generator.EntityFramework.Configurations.Fluent
2+
{
3+
public class FluentIgnore : IFluentLanguageElement
4+
{
5+
public string Property { get; }
6+
7+
public FluentIgnore(string property)
8+
{
9+
this.Property = property;
10+
}
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace KY.Generator.EntityFramework.Configurations.Fluent
2+
{
3+
public class FluentStoredProcedure : IFluentLanguageElement
4+
{
5+
public string Name { get; }
6+
public FluentStoredProcedureAction Action { get; }
7+
8+
public FluentStoredProcedure(string name, FluentStoredProcedureAction action)
9+
{
10+
this.Name = name;
11+
this.Action = action;
12+
}
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace KY.Generator.EntityFramework.Configurations.Fluent
2+
{
3+
public enum FluentStoredProcedureAction
4+
{
5+
Insert,
6+
Delete,
7+
Update
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
namespace KY.Generator.EntityFramework.Configurations.Fluent
2+
{
3+
public interface IFluentLanguageElement { }
4+
}

EntityFramework/KY.Generator.EntityFramework.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Authors>KY-Programming</Authors>
66
<Company>KY-Programming</Company>
77
<Product>KY.Generator</Product>
8-
<Version>2.2.0-rc.10</Version>
8+
<Version>2.2.0</Version>
99
<Copyright>2019 - KY-Programming</Copyright>
1010
<Description>EntityFramework Module for KY-Generator</Description>
1111
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>

EntityFramework/Writers/EntityFrameworkDataContextWriter.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ public void Write(EntityFrameworkWriteConfiguration configuration, List<ITransfe
4444
if (configuration.IsCore)
4545
{
4646
constructor.WithBaseConstructor(Code.Static(Code.Type("SqlServerDbContextOptionsExtensions")).Method("UseSqlServer", Code.New(Code.Type("DbContextOptionsBuilder")), Code.NullCoalescing(Code.Local(connectionString), Code.Local(defaultConnectionProperty))).Property("Options"))
47-
.Code.AddLine(Code.This().Property("Database").Method("SetCommandTimeout", Code.Number(configuration.CommandTimeout)).Close());
47+
.Code.AddLine(Code.This().Property("Database").Method("SetCommandTimeout", Code.Number(configuration.DataContext.CommandTimeout)).Close());
4848
}
4949
else
5050
{
5151
constructor.WithBaseConstructor(Code.NullCoalescing(Code.Local("connectionString"), Code.Local(defaultConnectionProperty)))
52-
.Code.AddLine(Code.This().Property("Database").Property("CommandTimeout").Assign(Code.Number(configuration.CommandTimeout)).Close());
52+
.Code.AddLine(Code.This().Property("Database").Property("CommandTimeout").Assign(Code.Number(configuration.DataContext.CommandTimeout)).Close());
5353
}
5454

5555
MethodTemplate createMethod = dataContext.AddMethod("OnModelCreating", Code.Void()).Protected().Override();

Json.Tests/Properties/Resources.Designer.cs

-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)