Added policy messages for WS. Fixed DB changes via stores. Updated chat voices messages via WS to use stores.
This commit is contained in:
@ -32,8 +32,8 @@ namespace HermesSocketServer.Store
|
||||
string sql = $"SELECT \"chatterId\", \"ttsVoiceId\" FROM \"TtsChatVoice\" WHERE \"userId\" = @user";
|
||||
await _database.Execute(sql, data, (reader) =>
|
||||
{
|
||||
string chatterId = reader.GetInt64(0).ToString();
|
||||
_store.Add(chatterId, new ChatterVoice()
|
||||
var chatterId = reader.GetInt64(0);
|
||||
_store.Add(chatterId.ToString(), new ChatterVoice()
|
||||
{
|
||||
UserId = _userId,
|
||||
ChatterId = chatterId,
|
||||
@ -70,7 +70,7 @@ namespace HermesSocketServer.Store
|
||||
}
|
||||
|
||||
_logger.Debug($"TtsChatVoice - Adding {count} rows to database: {sql}");
|
||||
await _database.ExecuteScalar(sql);
|
||||
await _database.ExecuteScalarTransaction(sql);
|
||||
}
|
||||
if (_modified.Any())
|
||||
{
|
||||
@ -81,7 +81,7 @@ namespace HermesSocketServer.Store
|
||||
_modified.Clear();
|
||||
}
|
||||
_logger.Debug($"TtsChatVoice - Modifying {count} rows in database: {sql}");
|
||||
await _database.ExecuteScalar(sql);
|
||||
await _database.ExecuteScalarTransaction(sql);
|
||||
}
|
||||
if (_deleted.Any())
|
||||
{
|
||||
@ -92,7 +92,7 @@ namespace HermesSocketServer.Store
|
||||
_deleted.Clear();
|
||||
}
|
||||
_logger.Debug($"TtsChatVoice - Deleting {count} rows from database: {sql}");
|
||||
await _database.ExecuteScalar(sql);
|
||||
await _database.ExecuteScalarTransaction(sql);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -86,7 +86,9 @@ namespace HermesSocketServer.Store
|
||||
.Append("),");
|
||||
}
|
||||
sb.Remove(sb.Length - 1, 1)
|
||||
.Append($") AS c(\"{string.Join("\", \"", columns)}\") WHERE id = c.id;");
|
||||
.Append($") AS c(\"{string.Join("\", \"", columns)}\") WHERE ")
|
||||
.Append(string.Join(" AND ", keyColumns.Select(c => "t.\"" + c + "\" = c.\"" + c + "\"")))
|
||||
.Append(";");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
@ -131,6 +133,12 @@ namespace HermesSocketServer.Store
|
||||
sb.Append("'")
|
||||
.Append(value)
|
||||
.Append("'");
|
||||
else if (type == typeof(Guid))
|
||||
sb.Append("'")
|
||||
.Append(value?.ToString())
|
||||
.Append("'");
|
||||
else if (type == typeof(TimeSpan))
|
||||
sb.Append(((TimeSpan)value).TotalMilliseconds);
|
||||
else
|
||||
sb.Append(value);
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
using HermesSocketLibrary.db;
|
||||
using HermesSocketServer.Models;
|
||||
|
||||
namespace HermesSocketServer.Store
|
||||
{
|
||||
public class PolicyStore : GroupSaveStore<string, Policy>
|
||||
public class PolicyStore : GroupSaveStore<string, PolicyMessage>
|
||||
{
|
||||
private readonly string _userId;
|
||||
private readonly Database _database;
|
||||
private readonly Serilog.ILogger _logger;
|
||||
private readonly GroupSaveSqlGenerator<Policy> _generator;
|
||||
private readonly GroupSaveSqlGenerator<PolicyMessage> _generator;
|
||||
|
||||
|
||||
public PolicyStore(string userId, Database database, Serilog.ILogger logger) : base(logger)
|
||||
@ -25,7 +26,7 @@ namespace HermesSocketServer.Store
|
||||
{ "count", "Usage" },
|
||||
{ "timespan", "Span" },
|
||||
};
|
||||
_generator = new GroupSaveSqlGenerator<Policy>(ctp);
|
||||
_generator = new GroupSaveSqlGenerator<PolicyMessage>(ctp);
|
||||
}
|
||||
|
||||
public override async Task Load()
|
||||
@ -34,25 +35,25 @@ namespace HermesSocketServer.Store
|
||||
string sql = $"SELECT id, \"groupId\", path, count, timespan FROM \"GroupPermissionPolicy\" WHERE \"userId\" = @user";
|
||||
await _database.Execute(sql, data, (reader) =>
|
||||
{
|
||||
string id = reader.GetString(0).ToString();
|
||||
_store.Add(id, new Policy()
|
||||
var id = reader.GetGuid(0);
|
||||
_store.Add(id.ToString(), new PolicyMessage()
|
||||
{
|
||||
Id = id,
|
||||
UserId = _userId,
|
||||
GroupId = reader.GetString(1),
|
||||
GroupId = reader.GetGuid(1),
|
||||
Path = reader.GetString(2),
|
||||
Usage = reader.GetInt32(3),
|
||||
Span = TimeSpan.FromMilliseconds(reader.GetInt32(4)),
|
||||
Span = reader.GetInt32(4),
|
||||
});
|
||||
});
|
||||
_logger.Information($"Loaded {_store.Count} policies from database.");
|
||||
}
|
||||
|
||||
protected override void OnInitialAdd(string key, Policy value)
|
||||
protected override void OnInitialAdd(string key, PolicyMessage value)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnInitialModify(string key, Policy value)
|
||||
protected override void OnInitialModify(string key, PolicyMessage value)
|
||||
{
|
||||
}
|
||||
|
||||
@ -75,7 +76,7 @@ namespace HermesSocketServer.Store
|
||||
}
|
||||
|
||||
_logger.Debug($"GroupPermissionPolicy - Adding {count} rows to database: {sql}");
|
||||
await _database.ExecuteScalar(sql);
|
||||
await _database.ExecuteScalarTransaction(sql);
|
||||
}
|
||||
if (_modified.Any())
|
||||
{
|
||||
@ -86,7 +87,7 @@ namespace HermesSocketServer.Store
|
||||
_modified.Clear();
|
||||
}
|
||||
_logger.Debug($"GroupPermissionPolicy - Modifying {count} rows in database: {sql}");
|
||||
await _database.ExecuteScalar(sql);
|
||||
await _database.ExecuteScalarTransaction(sql);
|
||||
}
|
||||
if (_deleted.Any())
|
||||
{
|
||||
@ -97,7 +98,7 @@ namespace HermesSocketServer.Store
|
||||
_deleted.Clear();
|
||||
}
|
||||
_logger.Debug($"GroupPermissionPolicy - Deleting {count} rows from database: {sql}");
|
||||
await _database.ExecuteScalar(sql);
|
||||
await _database.ExecuteScalarTransaction(sql);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ namespace HermesSocketServer.Store
|
||||
_added.Clear();
|
||||
}
|
||||
_logger.Debug($"User - Adding {count} rows to database: {sql}");
|
||||
await _database.ExecuteScalar(sql);
|
||||
await _database.ExecuteScalarTransaction(sql);
|
||||
}
|
||||
if (_modified.Any())
|
||||
{
|
||||
@ -81,7 +81,7 @@ namespace HermesSocketServer.Store
|
||||
_modified.Clear();
|
||||
}
|
||||
_logger.Debug($"User - Modifying {count} rows in database: {sql}");
|
||||
await _database.ExecuteScalar(sql);
|
||||
await _database.ExecuteScalarTransaction(sql);
|
||||
}
|
||||
if (_deleted.Any())
|
||||
{
|
||||
@ -92,7 +92,7 @@ namespace HermesSocketServer.Store
|
||||
_deleted.Clear();
|
||||
}
|
||||
_logger.Debug($"User - Deleting {count} rows from database: {sql}");
|
||||
await _database.ExecuteScalar(sql);
|
||||
await _database.ExecuteScalarTransaction(sql);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ namespace HermesSocketServer.Store
|
||||
}
|
||||
|
||||
_logger.Debug($"TtsVoice - Adding {count} rows to database: {sql}");
|
||||
await _database.ExecuteScalar(sql);
|
||||
await _database.ExecuteScalarTransaction(sql);
|
||||
}
|
||||
if (_modified.Any())
|
||||
{
|
||||
@ -84,7 +84,7 @@ namespace HermesSocketServer.Store
|
||||
_modified.Clear();
|
||||
}
|
||||
_logger.Debug($"TtsVoice - Modifying {count} rows in database: {sql}");
|
||||
await _database.ExecuteScalar(sql);
|
||||
await _database.ExecuteScalarTransaction(sql);
|
||||
}
|
||||
if (_deleted.Any())
|
||||
{
|
||||
@ -95,7 +95,7 @@ namespace HermesSocketServer.Store
|
||||
_deleted.Clear();
|
||||
}
|
||||
_logger.Debug($"TtsVoice - Deleting {count} rows from database: {sql}");
|
||||
await _database.ExecuteScalar(sql);
|
||||
await _database.ExecuteScalarTransaction(sql);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user