Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSawczyn-AWH committed Jan 16, 2020
1 parent 3200de8 commit 3c71930
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 84 deletions.
33 changes: 33 additions & 0 deletions src/Testing/ParserTest.cmd
@@ -0,0 +1,33 @@
@echo off
setlocal EnableDelayedExpansion

set parser[0]=..\DslPackage\Parsers\net472\EF6Parser.exe
set parser[1]=..\DslPackage\Parsers\net472\EFCore2Parser.exe
set parser[2]=..\DslPackage\Parsers\net472\EFCore3Parser.exe
set parser[3]=..\DslPackage\Parsers\netcoreapp2.1\EFCore2Parser.exe
set parser[4]=..\DslPackage\Parsers\netcoreapp2.1\EFCore3Parser.exe
set parser[5]=..\DslPackage\Parsers\netcoreapp3.1\EF6Parser.exe
set parser[6]=..\DslPackage\Parsers\netcoreapp3.1\EFCore2Parser.exe
set parser[7]=..\DslPackage\Parsers\netcoreapp3.1\EFCore3Parser.exe

set input[0]=.\EF6\EF6NetCore3\bin\Debug\netcoreapp3.1\EF6NetCore3.dll
set input[1]=.\EF6\EF6NetFramework\bin\Debug\EF6NetFramework.dll
set input[2]=.\EF6\EF6NetStandard\bin\Debug\netstandard2.1\EF6NetStandard.dll
set input[3]=.\EFCoreV2\EFCore2NetCore2\bin\Debug\netcoreapp2.2\EFCore2NetCore2.dll
set input[4]=.\EFCoreV2\EFCore2NetCore3\bin\Debug\netcoreapp3.1\EFCore2NetCore3.dll
set input[5]=.\EFCoreV2\EFCore2NetFramework\bin\Debug\EFCore2NetFramework.dll
set input[6]=.\EFCoreV2\EFCore2NetStandard\bin\Debug\netstandard2.1\EFCore2NetStandard.dll
set input[7]=.\EFCoreV3\EFCore3NetCore2\bin\Debug\netcoreapp2.2\EFCore3NetCore2.dll
set input[8]=.\EFCoreV3\EFCore3NetCore3\bin\Debug\netcoreapp3.1\EFCore3NetCore3.dll
set input[9]=.\EFCoreV3\EFCore3NetFramework\bin\Debug\EFCore3NetFramework.dll
set input[10]=.\EFCoreV3\EFCore3NetStandard\bin\Debug\netstandard2.1\EFCore3NetStandard.dll

for %%p in (0,1,2,3,4,5,6,7) do (
for %%i in (0,1,2,3,4,5,6,7,8,9,10) do (
"!parser[%%p]!" "!input[%%i]!" parsertest.txt
echo %ERRORLEVEL% - "!parser[%%p]!" "!input[%%i]!"

REM echo !parser[%%p]!
REM echo !input[%%i]!
)
)
Empty file added src/Testing/parsertest.txt
Empty file.
28 changes: 1 addition & 27 deletions src/Utilities/EFCore2Parser/EFCore2Parser.csproj
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net472;netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1;net472</TargetFrameworks>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>
Expand All @@ -16,10 +16,6 @@
</PropertyGroup>

<ItemGroup>
<None Remove="log4net.config" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' ">
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.6" />
Expand All @@ -30,28 +26,6 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.6" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational.Design" Version="1.1.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.1" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational.Design" Version="1.1.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ParsingModels\ParsingModels.csproj" />
</ItemGroup>
Expand Down
27 changes: 17 additions & 10 deletions src/Utilities/EFCore2Parser/Parser.cs
Expand Up @@ -7,6 +7,8 @@

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;

using Newtonsoft.Json;

using ParsingModels;
Expand Down Expand Up @@ -44,7 +46,7 @@ public Parser(Assembly assembly, string dbContextTypeName = null)
log.Error($"No DBContext found in {assembly.Location}");
throw new ArgumentException("Couldn't find DbContext-derived class in assembly. Is it public?");
}

if (types.Count > 1)
{
log.Error($"Found more than one class derived from DbContext: {string.Join(", ", types.Select(t => t.FullName))}");
Expand Down Expand Up @@ -124,9 +126,9 @@ private List<ModelUnidirectionalAssociation> GetUnidirectionalAssociations(IEnti
if (navigationProperty.ForeignKey != null)
{
List<string> fkPropertyDeclarations = navigationProperty.ForeignKey.Properties
.Where(p => !p.IsShadowProperty())
.Select(p => p.Name)
.ToList();
.Where(p => !p.IsShadowProperty)
.Select(p => p.Name)
.ToList();

association.ForeignKey = fkPropertyDeclarations.Any()
? string.Join(",", fkPropertyDeclarations)
Expand Down Expand Up @@ -157,7 +159,7 @@ private List<ModelBidirectionalAssociation> GetBidirectionalAssociations(IEntity
Type sourceType = navigationProperty.GetSourceType().ClrType.Unwrap();
association.SourceClassName = sourceType.Name;
association.SourceClassNamespace = sourceType.Namespace;

Type targetType = navigationProperty.GetTargetType().ClrType.Unwrap();
association.TargetClassName = targetType.Name;
association.TargetClassNamespace = targetType.Namespace;
Expand All @@ -183,7 +185,7 @@ private List<ModelBidirectionalAssociation> GetBidirectionalAssociations(IEntity
if (navigationProperty.ForeignKey != null)
{
List<string> fkPropertyDeclarations = navigationProperty.ForeignKey.Properties
.Where(p => !p.IsShadowProperty())
.Where(p => !p.IsShadowProperty)
.Select(p => $"{p.DeclaringEntityType.Name}/{p.ClrType.Name}{(p.IsNullable ? "?" : "")} {p.Name}")
.ToList();

Expand Down Expand Up @@ -246,6 +248,9 @@ private ModelClass ProcessEntity(IEntityType entityType, ModelRoot modelRoot)
ModelClass result = new ModelClass();
Type type = entityType.ClrType;

if (type == null)
return null;

result.Name = type.Name;
result.Namespace = type.Namespace;
result.IsAbstract = type.IsAbstract;
Expand All @@ -254,20 +259,20 @@ private ModelClass ProcessEntity(IEntityType entityType, ModelRoot modelRoot)
? null
: type.BaseType.Name;

result.TableName = entityType.GetTableName();
result.TableName = entityType.Relational().TableName;
result.IsDependentType = entityType.IsOwned();
result.CustomAttributes = GetCustomAttributes(type.CustomAttributes);

result.CustomInterfaces = type.GetInterfaces().Any()
? string.Join(",", type.GetInterfaces().Select(t => t.FullName))
: null;

// TODO continue here
result.Properties = entityType.GetDeclaredProperties()
.Where(p => !p.IsShadowProperty())
.Where(p => !p.IsShadowProperty)
.Select(p => ProcessProperty(p, modelRoot))
.Where(x => x != null)
.ToList();

result.UnidirectionalAssociations = GetUnidirectionalAssociations(entityType);
result.BidirectionalAssociations = GetBidirectionalAssociations(entityType);

Expand All @@ -284,7 +289,7 @@ private void ProcessEnum(Type enumType, ModelRoot modelRoot)

if (modelRoot.Enumerations.All(e => e.FullName != result.FullName))
{
result.IsFlags = enumType.GetTypeInfo().GetCustomAttribute(typeof(FlagsAttribute)) is FlagsAttribute ;
result.IsFlags = enumType.GetTypeInfo().GetCustomAttribute(typeof(FlagsAttribute)) is FlagsAttribute;
result.ValueType = Enum.GetUnderlyingType(enumType).Name;

result.CustomAttributes = customAttributes.Length > 2
Expand Down Expand Up @@ -354,4 +359,6 @@ private ModelRoot ProcessRoot()
return result;
}
}


}
16 changes: 9 additions & 7 deletions src/Utilities/EFCore2Parser/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 10 additions & 39 deletions src/Utilities/EFCore3Parser/EFCore3Parser.csproj
Expand Up @@ -4,6 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFrameworks>net472;netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net472|AnyCPU'">
Expand All @@ -14,55 +15,25 @@
<DefineConstants />
</PropertyGroup>

<ItemGroup>
<None Remove="log4net.config" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Diagnostics.Debug" Version="4.3.0" />
<PackageReference Include="System.Net.Primitives" Version="4.3.1" />
<PackageReference Include="System.Runtime.Extensions" Version="4.3.1" />
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
<PackageReference Include="System.Threading" Version="4.3.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational.Design" Version="1.1.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ParsingModels\ParsingModels.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore">
<Version>3.1.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers">
<Version>3.1.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory">
<Version>3.1.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational">
<Version>3.1.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational.Design">
<Version>1.1.6</Version>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer">
<Version>3.1.0</Version>
</PackageReference>
<PackageReference Include="System.IO.FileSystem">
<Version>4.3.0</Version>
</PackageReference>
<PackageReference Include="System.Net.NameResolution">
<Version>4.3.0</Version>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Resource Include="log4net.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="log4net.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion src/Utilities/EFCore3Parser/Parser.cs
Expand Up @@ -262,7 +262,6 @@ private ModelClass ProcessEntity(IEntityType entityType, ModelRoot modelRoot)
? string.Join(",", type.GetInterfaces().Select(t => t.FullName))
: null;

// TODO continue here
result.Properties = entityType.GetDeclaredProperties()
.Where(p => !p.IsShadowProperty())
.Select(p => ProcessProperty(p, modelRoot))
Expand Down

0 comments on commit 3c71930

Please sign in to comment.