Skip to content

Commit

Permalink
🔖1.23.10612.10151
Browse files Browse the repository at this point in the history
  • Loading branch information
AigioL committed Jun 11, 2023
1 parent 85848e8 commit d45bced
Show file tree
Hide file tree
Showing 26 changed files with 892 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public static async Task<int> IdentityInsertSaveChangesAsync(this IEFRepository
/// <param name="query"></param>
/// <param name="disable"></param>
/// <returns></returns>
[Obsolete("use SetDisableByIdAsync in BD.Common.Repositories.SourceGenerator")]
public static async Task<int> SetDisableAsync(this IQueryable<IDisable> query, bool disable)
{
var r = await query.ExecuteUpdateAsync(x => x.SetProperty(y => y.Disable, y => disable));
Expand All @@ -136,6 +137,7 @@ public static async Task<int> SetDisableAsync(this IQueryable<IDisable> query, b
/// <param name="id"></param>
/// <param name="disable"></param>
/// <returns></returns>
[Obsolete("use SetDisableByIdAsync in BD.Common.Repositories.SourceGenerator")]
public static async Task<int> SetDisableByIdAsync<[DynamicallyAccessedMembers(IEntity.DynamicallyAccessedMemberTypes)] TEntity, TPrimaryKey>(this IQueryable<TEntity> query, TPrimaryKey id, bool disable)
where TEntity : class, IDisable, IEntity<TPrimaryKey>
where TPrimaryKey : IEquatable<TPrimaryKey>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public Repository(TDbContext dbContext, IRequestAbortedProvider requestAbortedPr
});
}

[Obsolete("use SetDisableByIdAsync in BD.Common.Repositories.SourceGenerator")]
protected virtual Task<int> SetDisableAsync(IQueryable<TEntity> query, bool disable)
{
if (query is IQueryable<IDisable> queryDisable)
Expand All @@ -41,6 +42,7 @@ protected virtual Task<int> SetDisableAsync(IQueryable<TEntity> query, bool disa
}
}

[Obsolete("use SetDisableByIdAsync in BD.Common.Repositories.SourceGenerator")]
public virtual async Task<int> SetDisableByIdAsync(TPrimaryKey primaryKey, bool disable)
{
var query = EntityNoTracking.Where(IRepository<TEntity, TPrimaryKey>.LambdaEqualId(primaryKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public sealed class GenerateRepositoriesAttribute : Attribute
/// </summary>
public bool ApiController { get; set; } = true;

/// <summary>
/// 是否需要生成控制器构造函数,如果为 <see langword="null"/> 则不生成构造函数,否则将根据参数类型自动生成,默认值为:ArrayEmpty
/// </summary>
public string[]? ApiControllerConstructorArguments { get; set; } = Array.Empty<string>();

/// <summary>
/// 控制器路由前缀,默认值为:<see langword="null"/>
/// </summary>
public string? ApiRoutePrefix { get; set; }

/// <summary>
/// 如果需要生成实体类型且主键为 <see cref="Guid"/> 时是否需要继承接口 INEWSEQUENTIALID,默认值为:<see langword="true"/>
/// </summary>
Expand Down Expand Up @@ -77,6 +87,12 @@ public void SetValue(string key, object? value)
case nameof(ApiController):
ApiController = Convert.ToBoolean(value);
break;
case nameof(ApiControllerConstructorArguments):
ApiControllerConstructorArguments = ToStringArray(value)!;
break;
case nameof(ApiRoutePrefix):
ApiRoutePrefix = value?.ToString();
break;
case nameof(NEWSEQUENTIALID):
NEWSEQUENTIALID = Convert.ToBoolean(value);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@
<Compile Include="..\ImplicitUsings.Repositories.cs">
<LinkBase>Properties</LinkBase>
</Compile>
<Compile Include="..\ImplicitUsings.AspNetCore.cs">
<LinkBase>Properties</LinkBase>
</Compile>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BD.Common.AspNetCore.Identity.BackManage\BD.Common.AspNetCore.Identity.BackManage.csproj" />
<ProjectReference Include="..\BD.Common.Primitives\BD.Common.Primitives.csproj" />
<ProjectReference Include="..\BD.Common.Repositories.EFCore\BD.Common.Repositories.EFCore.csproj" />
<ProjectReference Include="..\BD.Common.Repositories.SourceGenerator.Annotations\BD.Common.Repositories.SourceGenerator.Annotations.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace BD.Common.Repositories.SourceGenerator.ConsoleTest.Controllers.Abstractions;

public abstract class BaseAuthorizeController<T> : ApiAuthorizeControllerBase<T> where T : ApiAuthorizeControllerBase<T>
{
public BaseAuthorizeController(ILogger<T> logger) : base(logger)
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ namespace BD.Common.Repositories.SourceGenerator.ConsoleTest.Entities.Design;
RepositoryConstructorArguments = new[] {
"ISysUserRepository",
"ASDASDRepository",
}
},
ApiControllerConstructorArguments = new[] {
"ISysMenuRepository",
},
ApiRoutePrefix = "ms/accelerator"
)]
//[Table("TestXXXs")] // 可使用 TableAttribute 指定表名称,不指定时将使用类名的复数单词
public class 示例
{
string? Id;
Guid Id;

Guid 租户Id;

[BackManageField]
string? Title;

bool 禁用;

#region CloudFileInfo

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
#pragma warning disable SA1209 // Using alias directives should be placed after other using directives
#pragma warning disable SA1211 // Using alias directives should be ordered alphabetically by alias name

global using Microsoft.Extensions.Logging;
global using BD.Common.Controllers.Abstractions;
global using BD.Common.Repositories.SourceGenerator.Annotations;

global using BD.Common.Repositories.SourceGenerator.ConsoleTest.Entities;
global using BD.Common.Repositories.SourceGenerator.ConsoleTest.Repositories;
global using BD.Common.Repositories.SourceGenerator.ConsoleTest.Repositories.Abstractions;
global using BD.Common.Repositories.SourceGenerator.ConsoleTest.Controllers;
global using BD.Common.Repositories.SourceGenerator.ConsoleTest.Controllers.Abstractions;

global using IIPAddress = BD.Common.Columns.IPAddress;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace BD.Common.Repositories.SourceGenerator.ConsoleTest.Repositories;

public sealed class ASDASDRepository
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace BD.Common.Repositories.SourceGenerator.ConsoleTest.Repositories.Abstractions;

public interface ISysMenuRepository
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace BD.Common.Repositories.SourceGenerator.ConsoleTest.Repositories.Abstractions;

public interface ISysUserRepository
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ public enum FixedProperty : ushort
UpdateTime,
CreateUserId,
OperatorUserId,
Disable,
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,22 @@ public static void Analysis(
fieldHumanizeName = "是否置顶";
return;
}
else if (fieldName == "是否禁用" ||
fieldName == "禁用" ||
fieldName == "是否启用" ||
fieldName == "启用" ||
fieldName.OICEquals("Enable") ||
fieldName.OICEquals("Enabled") ||
fieldName.OICEquals("Disable") ||
fieldName.OICEquals("Disabled") ||
fieldName.OICEquals("IsEnable") ||
fieldName.OICEquals("IsDisable"))
{
fixedProperty = FixedProperty.Disable;
fieldName = "Disable";
fieldHumanizeName = "是否禁用";
return;
}
else if (fieldName == "软删除" ||
fieldName == "是否软删除" ||
fieldName == "是否删除" ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace BD.Common.Repositories.SourceGenerator.Models;
/// <param name="Translates"></param>
public sealed record class GeneratorConfig(
ConcurrentDictionary<string, string> Translates,
ImmutableHashSet<string> AttributeTypeFullNames)
ImmutableHashSet<string> AttributeTypeFullNames,
string? ApiBaseUrlBackManageLocal,
string? ApiBaseUrlBackManageDevelopment)
{
static readonly Dictionary<string, string> DefTranslates = new()
{
Expand All @@ -19,6 +21,26 @@ public sealed record class GeneratorConfig(
{ "文件名", "FileName" },
};

static readonly Lazy<byte[]> _GetApiBaseUrlBackManageLocal = new(() =>
{
var value = Instance.ApiBaseUrlBackManageLocal;
if (string.IsNullOrWhiteSpace(value))
return "https://localhost:7129"u8.ToArray();
return Encoding.UTF8.GetBytes(value!.TrimEnd("/"));
});

public static byte[] GetApiBaseUrlBackManageLocal() => _GetApiBaseUrlBackManageLocal.Value;

static readonly Lazy<byte[]> _GetApiBaseUrlBackManageDevelopment = new(() =>
{
var value = Instance.ApiBaseUrlBackManageDevelopment;
if (string.IsNullOrWhiteSpace(value))
return ""u8.ToArray();
return Encoding.UTF8.GetBytes(value!.TrimEnd("/"));
});

public static byte[] GetApiBaseUrlBackManageDevelopment() => _GetApiBaseUrlBackManageDevelopment.Value;

/// <summary>
/// 配置文件名
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public record struct PropertyMetadata(
};

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public byte[]? GetBaseEntityType(EntityBaseClassType baseClassType) => baseClassType switch
public readonly byte[]? GetBaseEntityType(EntityBaseClassType baseClassType) => baseClassType switch
{
EntityBaseClassType.Entity => Encoding.UTF8.GetBytes($"Entity<{PropertyType}>"),
EntityBaseClassType.TenantBaseEntityV2 => Encoding.UTF8.GetBytes($"TenantBaseEntityV2<{PropertyType}>"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
tasks.Add(InBackground(() =>
{
EntityTemplate.Instance.AddSource(ctx, symbol,
new(@namespace, symbol.Name, tableClassName, className),
new(@namespace, symbol.Name, tableClassName, className,
generateRepositories.NEWSEQUENTIALID),
properties);
}));
if (generateRepositories.BackManageAddModel ||
Expand Down Expand Up @@ -76,7 +77,14 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
}));
if (generateRepositories.ApiController)
{
tasks.Add(InBackground(() =>
{
BackManageControllerTemplate.Instance.AddSource(ctx, symbol,
new(@namespace, symbol.Name, className,
ConstructorArguments: generateRepositories.ApiControllerConstructorArguments,
ApiRoutePrefix: generateRepositories.ApiRoutePrefix),
properties);
}));
}
}
}
Expand All @@ -97,7 +105,10 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
builder.AppendLine();
ex = ex.InnerException;
} while (ex != null);
ctx.AddSource(hintName, SourceText.From(builder.ToString(), Encoding.UTF8));
var errorString = builder.ToString();
Debug.WriteLine(errorString);
errorString = string.Join("\r\n", errorString.Split(new string[] { "\r\n" }, StringSplitOptions.None).Select(x => $"// {x}"));
ctx.AddSource(hintName, SourceText.From(errorString, Encoding.UTF8));
}
});
}
Expand Down
Loading

0 comments on commit d45bced

Please sign in to comment.