implement Optional Eventing in InMemory Stores for Push and WebRTC Connections and also Groups ...

This commit is contained in:
2025-07-14 06:00:29 +03:30
parent 2518bf1077
commit 6e1fb930a5
11 changed files with 184 additions and 72 deletions
+6 -3
View File
@@ -261,7 +261,8 @@ namespace xPushService.DI
{
//
Log($"there is no provided PushGroupStore, try to register XPushGroupInMemoryStore ...");
groupStore = new XPushGroupInMemoryStore();
var storeEvents = services.GetRegisteredService<IXPushGroupStoreEvents>();
groupStore = new XPushGroupInMemoryStore(storeEvents);
services.AddSingleton<IXPushGroupStore>(groupStore);
}
@@ -271,7 +272,8 @@ namespace xPushService.DI
{
//
Log($"there is no provided XPushConnectionStore, try to register XPushConnectionInMemoryStore ...");
connectionStore = new XPushConnectionInMemoryStore();
var storeEvents = services.GetRegisteredService<IXPushConnectionStoreEvents>();
connectionStore = new XPushConnectionInMemoryStore(storeEvents);
services.AddSingleton<IXPushConnectionStore>(connectionStore);
}
@@ -281,7 +283,8 @@ namespace xPushService.DI
{
//
Log($"there is no provided XWebRTCConnectionStore, try to register XWebRTCConnectionInMemoryStore ...");
webRtcConnectionStore = new XWebRTCConnectionInMemoryStore();
var storeEvents = services.GetRegisteredService<IXWebRTCConnectionStoreEvents>();
webRtcConnectionStore = new XWebRTCConnectionInMemoryStore(storeEvents);
services.AddSingleton<IXWebRTCConnectionStore>(webRtcConnectionStore);
}
#endregion
+9
View File
@@ -0,0 +1,9 @@
using xModels.Base;
using xPushService.Interfaces;
using xPushService.Models;
namespace xPushService.Events
{
public class XPushConnectionStoreEvents : XBaseStoreEvent<XPushConnectionDto, string>, IXPushConnectionStoreEvents
{ }
}
+9
View File
@@ -0,0 +1,9 @@
using xModels.Base;
using xPushService.Interfaces;
using xPushService.Models;
namespace xPushService.Events
{
public class XPushGroupStoreEvents : XBaseStoreEvent<XPushGroupDto, string>, IXPushGroupStoreEvents
{ }
}
+9
View File
@@ -0,0 +1,9 @@
using xModels.Base;
using xPushService.Interfaces;
using xPushService.Models;
namespace xPushService.Events
{
public class XWebRTCConnectionStoreEvents : XBaseStoreEvent<XWebRTCConnectionDto, string>, IXWebRTCConnectionStoreEvents
{ }
}
@@ -0,0 +1,8 @@
using xModels.Interfaces;
using xPushService.Models;
namespace xPushService.Interfaces
{
public interface IXPushConnectionStoreEvents : IXBaseStoreEvents<XPushConnectionDto, string>
{ }
}
+4 -2
View File
@@ -1,6 +1,8 @@
using xModels.Interfaces;
using xPushService.Models;
namespace xPushService.Interfaces {
public interface IXPushGroupStore : IXBaseStore<XPushGroupDto, string> { }
namespace xPushService.Interfaces
{
public interface IXPushGroupStore : IXBaseStore<XPushGroupDto, string>
{ }
}
+8
View File
@@ -0,0 +1,8 @@
using xModels.Interfaces;
using xPushService.Models;
namespace xPushService.Interfaces
{
public interface IXPushGroupStoreEvents : IXBaseStoreEvents<XPushGroupDto, string>
{}
}
@@ -0,0 +1,8 @@
using xModels.Interfaces;
using xPushService.Models;
namespace xPushService.Interfaces
{
public interface IXWebRTCConnectionStoreEvents : IXBaseStoreEvents<XWebRTCConnectionDto, string>
{ }
}
+69 -31
View File
@@ -10,8 +10,17 @@ using xModels.Providers;
using xPushService.Interfaces;
using xPushService.Models;
namespace xPushService.Store {
public class XPushConnectionInMemoryStore : XBaseInMemoryStore<XPushConnectionDto, string>, IXPushConnectionStore {
namespace xPushService.Store
{
public class XPushConnectionInMemoryStore : XBaseInMemoryStore<XPushConnectionDto, string>, IXPushConnectionStore
{
//
#region Constructor ...
public XPushConnectionInMemoryStore(
IXPushConnectionStoreEvents events = null
) : base(events) {}
#endregion
//
#region Custom ...
/// <summary>
@@ -19,7 +28,8 @@ namespace xPushService.Store {
/// </summary>
/// <param name="connectionId"></param>
/// <returns></returns>
public Task<XPushConnectionDto> GetByConnectionId (string connectionId) {
public Task<XPushConnectionDto> GetByConnectionId(string connectionId)
{
return Get(connectionId);
}
@@ -28,7 +38,8 @@ namespace xPushService.Store {
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public Task<IEnumerable<XPushConnectionDto>> GetByUserName (string userName) {
public Task<IEnumerable<XPushConnectionDto>> GetByUserName(string userName)
{
return FindMany(c => c.User.ToNormalString() == userName.ToNormalString());
}
@@ -38,7 +49,8 @@ namespace xPushService.Store {
/// <param name="userName"></param>
/// <param name="device"></param>
/// <returns></returns>
public Task<XPushConnectionDto> GetByUserDevice (string userName, XDeviceDto device) {
public Task<XPushConnectionDto> GetByUserDevice(string userName, XDeviceDto device)
{
return FindOne(c =>
c.User.ToNormalString() == userName.ToNormalString() &&
c.Device.IsSameContent(
@@ -52,7 +64,8 @@ namespace xPushService.Store {
/// </summary>
/// <param name="connectionId"></param>
/// <returns></returns>
public Task<bool> IsExistsConnectionId (string connectionId) {
public Task<bool> IsExistsConnectionId(string connectionId)
{
return IsExistsByKey(connectionId);
}
@@ -61,9 +74,11 @@ namespace xPushService.Store {
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public Task<bool> IsExistsUser (string userName) {
public Task<bool> IsExistsUser(string userName)
{
return GetByUserName(userName)
.ContinueWith (findTask => {
.ContinueWith(findTask =>
{
//
var findResult = findTask
.RunTask();
@@ -80,9 +95,11 @@ namespace xPushService.Store {
/// <param name="userName"></param>
/// <param name="device"></param>
/// <returns></returns>
public Task<IEnumerable<XDeviceDto>> GetUserDevices (string userName) {
public Task<IEnumerable<XDeviceDto>> GetUserDevices(string userName)
{
return GetByUserName(userName)
.ContinueWith (userConnectionsTask => {
.ContinueWith(userConnectionsTask =>
{
//
var userConnections = userConnectionsTask
.RunTask();
@@ -98,7 +115,8 @@ namespace xPushService.Store {
/// </summary>
/// <param name="connectionId"></param>
/// <returns></returns>
public Task<bool> RemoveByConnectionId (string connectionId) {
public Task<bool> RemoveByConnectionId(string connectionId)
{
return RemoveByKey(connectionId);
}
@@ -108,18 +126,21 @@ namespace xPushService.Store {
/// <param name="userName"></param>
/// <param name="device"></param>
/// <returns></returns>
public Task<bool> RemoveByUserDevice (string userName, XDeviceDto device) {
public Task<bool> RemoveByUserDevice(string userName, XDeviceDto device)
{
return GetByUserDevice(
device: device,
userName: userName
)
.ContinueWith (connectionTask => {
.ContinueWith(connectionTask =>
{
//
var connection = connectionTask
.RunTask();
//
if (connection.IsNull ()) {
if (connection.IsNull())
{
return false;
}
@@ -135,20 +156,24 @@ namespace xPushService.Store {
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public Task<bool> RemoveUser (string userName) {
public Task<bool> RemoveUser(string userName)
{
return GetByUserName(userName)
.ContinueWith (connectionsTask => {
.ContinueWith(connectionsTask =>
{
//
var connections = connectionsTask
.RunTask();
//
if (!connections.HasChild ()) {
if (!connections.HasChild())
{
return false;
}
//
var result = RemoveMany (new XBaseRangeRequest<XPushConnectionDto> {
var result = RemoveMany(new XBaseRangeRequest<XPushConnectionDto>
{
Items = connections
})
.RunTask();
@@ -163,15 +188,18 @@ namespace xPushService.Store {
/// </summary>
/// <param name="connectionId"></param>
/// <returns></returns>
public Task<DateTime> GetLastSeenByConnectionId (string connectionId) {
public Task<DateTime> GetLastSeenByConnectionId(string connectionId)
{
return GetByConnectionId(connectionId)
.ContinueWith (connectionTask => {
.ContinueWith(connectionTask =>
{
//
var connection = connectionTask
.RunTask();
//
if (connection.IsNull ()) {
if (connection.IsNull())
{
throw XException.NotFound.ToException();
}
@@ -186,15 +214,18 @@ namespace xPushService.Store {
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public Task<DateTime> GetLastSeenByUserName (string userName) {
public Task<DateTime> GetLastSeenByUserName(string userName)
{
return GetByUserName(userName)
.ContinueWith (connectionsTask => {
.ContinueWith(connectionsTask =>
{
//
var connections = connectionsTask
.RunTask();
//
if (!connections.HasChild ()) {
if (!connections.HasChild())
{
throw XException.NotFound.ToException();
}
@@ -214,18 +245,21 @@ namespace xPushService.Store {
/// <param name="userName"></param>
/// <param name="device"></param>
/// <returns></returns>
public Task<DateTime> GetLastSeenByUserDevice (string userName, XDeviceDto device) {
public Task<DateTime> GetLastSeenByUserDevice(string userName, XDeviceDto device)
{
return GetByUserDevice(
device: device,
userName: userName
)
.ContinueWith (connectionTask => {
.ContinueWith(connectionTask =>
{
//
var connection = connectionTask
.RunTask();
//
if (connection.IsNull ()) {
if (connection.IsNull())
{
throw XException.NotFound.ToException();
}
@@ -240,9 +274,11 @@ namespace xPushService.Store {
/// </summary>
/// <param name="connectionId"></param>
/// <returns></returns>
public Task<bool> UpdateLastSeen (string connectionId) {
public Task<bool> UpdateLastSeen(string connectionId)
{
return IsExistsConnectionId(connectionId)
.ContinueWith (isExistsTask => {
.ContinueWith(isExistsTask =>
{
//
// define empty result ...
var result = false;
@@ -254,7 +290,8 @@ namespace xPushService.Store {
//
// check result is false ...
if (!result) {
if (!result)
{
return result;
}
@@ -263,7 +300,8 @@ namespace xPushService.Store {
var connection = GetByConnectionId(connectionId)
.RunTask();
result = !connection.IsNull();
if (!result) {
if (!result)
{
return result;
}
+11 -2
View File
@@ -2,6 +2,15 @@ using xModels.Providers;
using xPushService.Interfaces;
using xPushService.Models;
namespace xPushService.Store {
public class XPushGroupInMemoryStore : XBaseInMemoryStore<XPushGroupDto, string>, IXPushGroupStore { }
namespace xPushService.Store
{
public class XPushGroupInMemoryStore : XBaseInMemoryStore<XPushGroupDto, string>, IXPushGroupStore
{
//
#region Constructor ...
public XPushGroupInMemoryStore(
IXPushGroupStoreEvents events = null
) : base(events) { }
#endregion
}
}
+11 -2
View File
@@ -2,6 +2,15 @@ using xModels.Providers;
using xPushService.Interfaces;
using xPushService.Models;
namespace xPushService.Store {
public class XWebRTCConnectionInMemoryStore : XBaseInMemoryStore<XWebRTCConnectionDto, string>, IXWebRTCConnectionStore { }
namespace xPushService.Store
{
public class XWebRTCConnectionInMemoryStore : XBaseInMemoryStore<XWebRTCConnectionDto, string>, IXWebRTCConnectionStore
{
//
#region Constructor ...
public XWebRTCConnectionInMemoryStore(
IXWebRTCConnectionStoreEvents events = null
) : base(events) { }
#endregion
}
}