Added policy messages for WS. Fixed DB changes via stores. Updated chat voices messages via WS to use stores.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user