mirror of
https://github.com/project-redbud/FunGame-Server.git
synced 2025-04-20 11:09:36 +08:00
升级 .NET 9;测试 SQLite 初始数据库
This commit is contained in:
parent
3f27123c03
commit
562658bc62
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<BaseOutputPath>..\bin</BaseOutputPath>
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<ApplicationIcon>logo.ico</ApplicationIcon>
|
||||
|
@ -204,6 +204,11 @@ namespace Milimoe.FunGame.Server.Others
|
||||
public static void AfterCreateSQLService(SQLHelper sqlHelper)
|
||||
{
|
||||
Config.SQLMode = sqlHelper.Mode;
|
||||
if (sqlHelper is SQLiteHelper sqliteHelper && !sqliteHelper.DatabaseExists())
|
||||
{
|
||||
ServerHelper.WriteLine("正在初始化数据库 . . .", InvokeMessageType.Core);
|
||||
sqliteHelper.ExecuteSqlFile(AppDomain.CurrentDomain.BaseDirectory + "fungame_sqlite.sql");
|
||||
}
|
||||
ServerLogin(sqlHelper);
|
||||
ClearRoomList(sqlHelper);
|
||||
sqlHelper.Dispose();
|
||||
|
@ -46,7 +46,7 @@ namespace Milimoe.FunGame.Server.Utility
|
||||
}
|
||||
else ServerHelper.Error(new SQLServiceException());
|
||||
}
|
||||
return "data source=" + DataSource;
|
||||
return $"data source={AppDomain.CurrentDomain.BaseDirectory}" + DataSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,6 @@ namespace Milimoe.FunGame.Server.Utility.DataUtility
|
||||
/// </summary>
|
||||
/// <param name="script"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public override int Execute(string script)
|
||||
{
|
||||
bool localTransaction = _transaction == null;
|
||||
@ -92,6 +91,7 @@ namespace Milimoe.FunGame.Server.Utility.DataUtility
|
||||
NewTransaction();
|
||||
}
|
||||
OpenConnection();
|
||||
Script = script;
|
||||
ServerHelper.WriteLine("SQLQuery -> " + script, InvokeMessageType.Api);
|
||||
using MySqlCommand command = new(script, _connection);
|
||||
command.CommandType = CommandType;
|
||||
@ -139,6 +139,7 @@ namespace Milimoe.FunGame.Server.Utility.DataUtility
|
||||
NewTransaction();
|
||||
}
|
||||
OpenConnection();
|
||||
Script = script;
|
||||
ServerHelper.WriteLine("SQLQuery -> " + script, InvokeMessageType.Api);
|
||||
|
||||
using MySqlCommand command = new(script, _connection)
|
||||
@ -150,6 +151,7 @@ namespace Milimoe.FunGame.Server.Utility.DataUtility
|
||||
{
|
||||
SelectCommand = command
|
||||
};
|
||||
_dataSet = new();
|
||||
adapter.Fill(_dataSet);
|
||||
|
||||
if (localTransaction) Commit();
|
||||
|
@ -78,7 +78,6 @@ namespace Milimoe.FunGame.Server.Utility.DataUtility
|
||||
/// </summary>
|
||||
/// <param name="script"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public override int Execute(string script)
|
||||
{
|
||||
bool localTransaction = _transaction == null;
|
||||
@ -90,6 +89,7 @@ namespace Milimoe.FunGame.Server.Utility.DataUtility
|
||||
NewTransaction();
|
||||
}
|
||||
OpenConnection();
|
||||
Script = script;
|
||||
ServerHelper.WriteLine("SQLQuery -> " + script, InvokeMessageType.Api);
|
||||
using SqliteCommand command = new(script, _connection);
|
||||
command.CommandType = CommandType;
|
||||
@ -138,6 +138,7 @@ namespace Milimoe.FunGame.Server.Utility.DataUtility
|
||||
NewTransaction();
|
||||
}
|
||||
OpenConnection();
|
||||
Script = script;
|
||||
ServerHelper.WriteLine("SQLQuery -> " + script, InvokeMessageType.Api);
|
||||
using SqliteCommand command = new(script, _connection)
|
||||
{
|
||||
@ -211,6 +212,39 @@ namespace Milimoe.FunGame.Server.Utility.DataUtility
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查数据库是否存在
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool DatabaseExists()
|
||||
{
|
||||
return File.Exists(ServerInfo.SQLServerDataBase);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行SQL文件中的所有SQL语句来初始化数据库
|
||||
/// </summary>
|
||||
/// <param name="sqlFilePath">SQL文件路径</param>
|
||||
public void ExecuteSqlFile(string sqlFilePath)
|
||||
{
|
||||
if (!File.Exists(sqlFilePath))
|
||||
{
|
||||
throw new FileNotFoundException("SQL文件不存在", sqlFilePath);
|
||||
}
|
||||
|
||||
string sqlContent = File.ReadAllText(sqlFilePath);
|
||||
string[] sqlCommands = sqlContent.Split([";"], StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach (string commandText in sqlCommands)
|
||||
{
|
||||
string sql = commandText.Trim();
|
||||
if (!string.IsNullOrEmpty(sql))
|
||||
{
|
||||
Execute(sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isDisposed = false;
|
||||
|
||||
/// <summary>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>Milimoe.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
|
||||
|
@ -103,17 +103,10 @@ try
|
||||
options.JsonSerializerOptions.WriteIndented = true;
|
||||
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);
|
||||
options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
|
||||
options.JsonSerializerOptions.Converters.Add(new DateTimeConverter());
|
||||
options.JsonSerializerOptions.Converters.Add(new DataTableConverter());
|
||||
options.JsonSerializerOptions.Converters.Add(new DataSetConverter());
|
||||
options.JsonSerializerOptions.Converters.Add(new UserConverter());
|
||||
options.JsonSerializerOptions.Converters.Add(new RoomConverter());
|
||||
options.JsonSerializerOptions.Converters.Add(new CharacterConverter());
|
||||
options.JsonSerializerOptions.Converters.Add(new MagicResistanceConverter());
|
||||
options.JsonSerializerOptions.Converters.Add(new EquipSlotConverter());
|
||||
options.JsonSerializerOptions.Converters.Add(new SkillConverter());
|
||||
options.JsonSerializerOptions.Converters.Add(new EffectConverter());
|
||||
options.JsonSerializerOptions.Converters.Add(new ItemConverter());
|
||||
foreach (JsonConverter converter in JsonTool.JsonSerializerOptions.Converters)
|
||||
{
|
||||
options.JsonSerializerOptions.Converters.Add(converter);
|
||||
}
|
||||
});
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
|
Loading…
x
Reference in New Issue
Block a user