Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/EAVFW/EAVFramework into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
pksorensen committed Aug 25, 2024
2 parents 8c29629 + 9ba934a commit 954619f
Show file tree
Hide file tree
Showing 10 changed files with 4,707 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -528,13 +528,13 @@ public static IResourceBuilder<EAVFWModelProjectResource> FromBackup(this IResou
public static IResourceBuilder<EAVFWModelProjectResource> PublishTo(
this IResourceBuilder<EAVFWModelProjectResource> builder,
IResourceBuilder<SqlServerDatabaseResource> target,
string administratorEmail, Guid initialAdministratorUserId, string Username, string schema = "dbo"
string administratorEmail, Guid initialAdministratorUserId, string Username, string schema = "dbo", string systemUsersTableName = "SystemUsers"
)
{
builder.ApplicationBuilder.Services.TryAddLifecycleHook<PublishEAVFWProjectLifecycleHook>();
builder.WithAnnotation(new TargetDatabaseResourceAnnotation(target.Resource.Name, target.Resource)
{
InitialEmail = administratorEmail, InitialIdentity = initialAdministratorUserId, Schema = schema, InitialUsername = Username, UserPrincipalName = Username.Replace(" ","")
InitialEmail = administratorEmail, InitialIdentity = initialAdministratorUserId, SystemUsersTableName = systemUsersTableName, Schema = schema, InitialUsername = Username, UserPrincipalName = Username.Replace(" ","")
}, ResourceAnnotationMutationBehavior.Replace);
return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ private static async Task DoMigrationAsync(string modelProjectPath, TargetDataba
var variablegenerator = new SQLClientParameterGenerator();
var migrator = new SQLMigrationGenerator(variablegenerator, new ManifestPermissionGenerator(variablegenerator));

var sqls = await migrator.GenerateSQL(Path.GetDirectoryName(modelProjectPath), true, "SystemUsers",
var sqls = await migrator.GenerateSQL(Path.GetDirectoryName(modelProjectPath), true, targetDatabaseResourceAnnotation.SystemUsersTableName ?? "SystemUsers",
o =>
{
o.UseNetTopologySuite();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public record TargetDatabaseResourceAnnotation(string TargetDatabaseResourceName
public string InitialEmail { get; set; }
public string UserPrincipalName { get; set; }
public string InitialUsername { get; set; }
public string SystemUsersTableName{get;set;} = "SystemUsers";
public string InitialSystemSecurityGroupId { get; set; } = "1b714972-8d0a-4feb-b166-08d93c6ae328";
}
public record CreateSigninUrlAnnotation(IResource Target, IResource Project) : IResourceAnnotation
Expand Down
44 changes: 25 additions & 19 deletions src/Shared/V2/DynamicPropertyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,30 +131,36 @@ public void AddInterfaceOverrides()
{
foreach (var interfaceType in interfaceTypes)
{

{
var base_get = TypeBuilder.DefineMethod($"get_{LogicalName}",
MethodAttributes.Virtual | MethodAttributes.Private | MethodAttributes.Final | MethodAttributes.SpecialName | MethodAttributes.NewSlot | MethodAttributes.HideBySig,
property.PropertyType, System.Type.EmptyTypes);
var il = base_get.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.EmitCall(OpCodes.Call, property.GetGetMethod(), null);
il.Emit(OpCodes.Ret);
TypeBuilder.DefineMethodOverride(base_get, interfaceType.GetProperty(SchemaName).GetGetMethod());
}
try
{
var base_set = TypeBuilder.DefineMethod($"set_{LogicalName}", MethodAttributes.Virtual | MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig,
{
var base_get = TypeBuilder.DefineMethod($"get_{interfaceType.Name}_{LogicalName}",
MethodAttributes.Virtual | MethodAttributes.Private | MethodAttributes.Final | MethodAttributes.SpecialName | MethodAttributes.NewSlot | MethodAttributes.HideBySig,
property.PropertyType, System.Type.EmptyTypes);
var il = base_get.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.EmitCall(OpCodes.Call, property.GetGetMethod(), null);
il.Emit(OpCodes.Ret);
TypeBuilder.DefineMethodOverride(base_get, interfaceType.GetProperty(SchemaName).GetGetMethod());
}
{
var base_set = TypeBuilder.DefineMethod($"set_{LogicalName}", MethodAttributes.Virtual | MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig,

null, new[] { property.PropertyType });
var il = base_set.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Call, property.GetSetMethod());
null, new[] { property.PropertyType });
var il = base_set.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Call, property.GetSetMethod());

il.Emit(OpCodes.Ret);
TypeBuilder.DefineMethodOverride(base_set, interfaceType.GetProperty(SchemaName).GetSetMethod());
il.Emit(OpCodes.Ret);
TypeBuilder.DefineMethodOverride(base_set, interfaceType.GetProperty(SchemaName).GetSetMethod());


}
}
catch (Exception ex)
{
throw new Exception($"Error adding interface overrides for {SchemaName} in {TypeBuilder.Name}", ex);
}
}
}
Expand Down
25 changes: 21 additions & 4 deletions src/Shared/V2/DynamicTableBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,7 @@ public void BuildDTOConfiguration()
// options.EntityDTOConfigurations[entityCollectionSchemaName] = entityTypeConfiguration.CreateTypeInfo();

}
public bool IsCreating { get; private set; }
public bool IsCreated { get; private set; }
public TypeInfo CreateTypeInfo()
{
Expand All @@ -1564,10 +1565,17 @@ public TypeInfo CreateTypeInfo()



if (IsCreated)
if (IsCreating)
{
if (!IsCreated)
{
FinalizeType();
IsCreated = true;
}
return Builder.CreateTypeInfo();
}

IsCreated = true;
IsCreating = true;
#if DEBUG
// File.AppendAllLines("test1.txt", new[] { $"Creating {SchemaName}" });
#endif
Expand All @@ -1580,13 +1588,19 @@ public TypeInfo CreateTypeInfo()
dp.CreateTypeInfo();
}

return Builder.CreateTypeInfo();
if(!IsCreated)
FinalizeType();


var result= Builder.CreateTypeInfo();
IsCreated = true;
return result;
}
catch (Exception ex)
{
#if DEBUG
// File.AppendAllLines("test1.txt", new[] { $"Failed {SchemaName}" });
IsCreated = false;
IsCreating = false;
#endif
throw new InvalidOperationException($"Could not build {SchemaName}: {string.Join(",", Builder.GetInterfaces().Select(c => $"{c.Name}<{string.Join(",", c.GetGenericArguments().Select(t => $"{t.Name}<{t.BaseType.Name},{string.Join(",", t.GetInterfaces().Select(i => i.Name))}>"))}>"))}", ex);
}
Expand Down Expand Up @@ -1649,6 +1663,9 @@ private void BuildParent()
public HashSet<DynamicTableBuilder> Dependencies { get; } = new HashSet<DynamicTableBuilder>();
public DynamicTableBuilder AddAsDependency(DynamicTableBuilder value)
{
if (value == this)
return this;

Dependencies.Add(value);

return value;
Expand Down
2 changes: 1 addition & 1 deletion src/Shared/V2/ManifestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ internal Type CreateDynamicMigration(DynamicCodeService dynamicCodeService, JTok

}
else {
table.FinalizeType();
// table.FinalizeType();


this.options.EntityDTOs[table.CollectionSchemaName] = table.CreateTypeInfo();
Expand Down
3 changes: 3 additions & 0 deletions test/EAVFramework.UnitTest/EAVFramework.UnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
<None Update="Specs\mc-crm.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Specs\mc-oauth.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Specs\mc-oidc.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Loading

0 comments on commit 954619f

Please sign in to comment.