mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-07-05 06:00:29 -04:00
Removed NioTSO client and server
- NioTSO client isn't needed because we're using RayLib - Added FreeSO's API server to handle most backend operations
This commit is contained in:
parent
f12ba1502b
commit
22191ce648
591 changed files with 53264 additions and 3362 deletions
59
server/FSO.Server.Database/DA/Tasks/SqlTasks.cs
Executable file
59
server/FSO.Server.Database/DA/Tasks/SqlTasks.cs
Executable file
|
@ -0,0 +1,59 @@
|
|||
using Dapper;
|
||||
using FSO.Server.Database.DA.Utils;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace FSO.Server.Database.DA.Tasks
|
||||
{
|
||||
public class SqlTasks : AbstractSqlDA, ITasks
|
||||
{
|
||||
public SqlTasks(ISqlContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public int Create(DbTask task)
|
||||
{
|
||||
return Context.Connection.Query<int>(
|
||||
"INSERT INTO fso_tasks (task_type, task_status, shard_id) " +
|
||||
"VALUES (@task_type, @task_status, @shard_id); SELECT LAST_INSERT_ID();", new
|
||||
{
|
||||
task_type = task.task_type.ToString(),
|
||||
task_status = task.task_status.ToString(),
|
||||
shard_id = task.shard_id
|
||||
}).First();
|
||||
}
|
||||
|
||||
|
||||
public void CompleteTask(int task_id, DbTaskStatus status)
|
||||
{
|
||||
Context.Connection.Execute("UPDATE fso_tasks set task_status = @task_status, time_completed = current_timestamp WHERE task_id = @task_id", new
|
||||
{
|
||||
task_id = task_id,
|
||||
task_status = status.ToString()
|
||||
});
|
||||
}
|
||||
|
||||
public void SetStatus(int task_id, DbTaskStatus status)
|
||||
{
|
||||
Context.Connection.Execute("UPDATE fso_tasks set task_status = @task_status WHERE task_id = @task_id", new {
|
||||
task_id = task_id,
|
||||
task_status = status.ToString()
|
||||
});
|
||||
}
|
||||
|
||||
public DbTask CompletedAfter(DbTaskType type, DateTime time)
|
||||
{
|
||||
return Context.Connection.Query<DbTask>("SELECT * FROM fso_tasks WHERE task_type = @type AND task_status = 'completed' AND time_completed >= @time",
|
||||
new { type = type.ToString(), time }).FirstOrDefault();
|
||||
}
|
||||
|
||||
public PagedList<DbTask> All(int offset = 1, int limit = 20)
|
||||
{
|
||||
var connection = Context.Connection;
|
||||
var total = connection.Query<int>("SELECT COUNT(*) FROM fso_tasks").FirstOrDefault();
|
||||
var results = connection.Query<DbTask>("SELECT t.*, s.name as shard_name FROM fso_tasks t LEFT JOIN fso_shards s ON s.shard_id = t.shard_id ORDER BY time_created DESC LIMIT @offset, @limit", new { offset = offset, limit = limit });
|
||||
return new PagedList<DbTask>(results, offset, total);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue