Skip to content

Commit

Permalink
misc 增加生成数据库时的错误处理
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Feb 13, 2024
1 parent 8965e7e commit 6622d56
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 13 deletions.
4 changes: 0 additions & 4 deletions XinjingdailyBot.Generator/AppServiceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ internal sealed class AppServiceGenerator : ISourceGenerator
public void Initialize(GeneratorInitializationContext context)
{
// 无需处理
if (!Debugger.IsAttached)
{
Debugger.Launch();
}
}

/// <inheritdoc/>
Expand Down
19 changes: 13 additions & 6 deletions XinjingdailyBot.Generator/Templates.Designer.cs

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

16 changes: 14 additions & 2 deletions XinjingdailyBot.Generator/Templates.resx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,16 @@ _dbClient.CodeFirst.InitTables&lt;{1}&gt;();</value>
<comment>数据库文件内容</comment>
</data>
<data name="DbTableFooter" xml:space="preserve">
<value>_logger.LogWarning("数据库结构生成完毕, 建议禁用 Database.Generate 来加快启动速度");
<value>}
catch (Exception ex)
{
_logger.LogError(ex, "创建数据库失败, 可能没有权限");
_logger.LogInformation("按任意键退出...");
Console.ReadKey();
Environment.Exit(1);
}

_logger.LogWarning("数据库结构生成完毕, 建议禁用 Database.Generate 来加快启动速度");
}

return Task.CompletedTask;
Expand All @@ -176,6 +185,7 @@ _dbClient.CodeFirst.InitTables&lt;{1}&gt;();</value>
<value>using Microsoft.Extensions.Options;
using SqlSugar;
using XinjingdailyBot.Infrastructure;
using XinjingdailyBot.Model.Models;

namespace XinjingdailyBot.WebAPI.Extensions;

Expand Down Expand Up @@ -208,7 +218,9 @@ public sealed class GeneratedDbInitService(
_logger.LogWarning(ex, "创建数据库失败, 可能没有权限");
}

//创建数据表</value>
//创建数据表
try
{</value>
<comment>数据库文件头</comment>
</data>
<data name="ScheduleContent" xml:space="preserve">
Expand Down
13 changes: 13 additions & 0 deletions XinjingdailyBot.Model/Models/StateContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using SqlSugar;

namespace XinjingdailyBot.Model.Models;

/// <summary>
/// 用户状态上下文
/// </summary>
[SugarTable("state_context", TableDescription = "用户状态上下文")]
public sealed record StateContext
{
public int UserId { get; set; }
public string Context { get; set; }
}
2 changes: 1 addition & 1 deletion XinjingdailyBot.WebAPI/Extensions/DatabaseExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void AddSqlSugarSetup(this IServiceCollection services, IConfigura
if (config == null)
{
_logger.Error("数据库配置不能为空");
_logger.Error("按任意键退出...");
_logger.Info("按任意键退出...");
Console.ReadKey();
Environment.Exit(1);
}
Expand Down
Binary file modified XinjingdailyBot.WebAPI/Properties/appService.json
Binary file not shown.
Binary file modified XinjingdailyBot.WebAPI/Properties/dbtable.json
Binary file not shown.
Binary file modified XinjingdailyBot.WebAPI/Properties/schedule.json
Binary file not shown.

0 comments on commit 6622d56

Please sign in to comment.