implement Optional Eventing in InMemory Stores for Push and WebRTC Connections and also Groups ...
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
using xModels.Base;
|
||||
using xPushService.Interfaces;
|
||||
using xPushService.Models;
|
||||
|
||||
namespace xPushService.Events
|
||||
{
|
||||
public class XPushConnectionStoreEvents : XBaseStoreEvent<XPushConnectionDto, string>, IXPushConnectionStoreEvents
|
||||
{ }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using xModels.Base;
|
||||
using xPushService.Interfaces;
|
||||
using xPushService.Models;
|
||||
|
||||
namespace xPushService.Events
|
||||
{
|
||||
public class XPushGroupStoreEvents : XBaseStoreEvent<XPushGroupDto, string>, IXPushGroupStoreEvents
|
||||
{ }
|
||||
}
|
||||
@@ -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>
|
||||
{ }
|
||||
}
|
||||
@@ -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>
|
||||
{ }
|
||||
}
|
||||
@@ -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>
|
||||
{ }
|
||||
}
|
||||
@@ -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,8 +28,9 @@ namespace xPushService.Store {
|
||||
/// </summary>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public Task<XPushConnectionDto> GetByConnectionId (string connectionId) {
|
||||
return Get (connectionId);
|
||||
public Task<XPushConnectionDto> GetByConnectionId(string connectionId)
|
||||
{
|
||||
return Get(connectionId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -28,8 +38,9 @@ namespace xPushService.Store {
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public Task<IEnumerable<XPushConnectionDto>> GetByUserName (string userName) {
|
||||
return FindMany (c => c.User.ToNormalString () == userName.ToNormalString ());
|
||||
public Task<IEnumerable<XPushConnectionDto>> GetByUserName(string userName)
|
||||
{
|
||||
return FindMany(c => c.User.ToNormalString() == userName.ToNormalString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -38,10 +49,11 @@ namespace xPushService.Store {
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="device"></param>
|
||||
/// <returns></returns>
|
||||
public Task<XPushConnectionDto> GetByUserDevice (string userName, XDeviceDto device) {
|
||||
return FindOne (c =>
|
||||
c.User.ToNormalString () == userName.ToNormalString () &&
|
||||
c.Device.IsSameContent (
|
||||
public Task<XPushConnectionDto> GetByUserDevice(string userName, XDeviceDto device)
|
||||
{
|
||||
return FindOne(c =>
|
||||
c.User.ToNormalString() == userName.ToNormalString() &&
|
||||
c.Device.IsSameContent(
|
||||
device, null, null, null, false
|
||||
)
|
||||
);
|
||||
@@ -52,8 +64,9 @@ namespace xPushService.Store {
|
||||
/// </summary>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public Task<bool> IsExistsConnectionId (string connectionId) {
|
||||
return IsExistsByKey (connectionId);
|
||||
public Task<bool> IsExistsConnectionId(string connectionId)
|
||||
{
|
||||
return IsExistsByKey(connectionId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -61,15 +74,17 @@ namespace xPushService.Store {
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public Task<bool> IsExistsUser (string userName) {
|
||||
return GetByUserName (userName)
|
||||
.ContinueWith (findTask => {
|
||||
public Task<bool> IsExistsUser(string userName)
|
||||
{
|
||||
return GetByUserName(userName)
|
||||
.ContinueWith(findTask =>
|
||||
{
|
||||
//
|
||||
var findResult = findTask
|
||||
.RunTask();
|
||||
|
||||
//
|
||||
var result = findResult.Any ();
|
||||
var result = findResult.Any();
|
||||
return result;
|
||||
});
|
||||
}
|
||||
@@ -80,15 +95,17 @@ namespace xPushService.Store {
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="device"></param>
|
||||
/// <returns></returns>
|
||||
public Task<IEnumerable<XDeviceDto>> GetUserDevices (string userName) {
|
||||
return GetByUserName (userName)
|
||||
.ContinueWith (userConnectionsTask => {
|
||||
public Task<IEnumerable<XDeviceDto>> GetUserDevices(string userName)
|
||||
{
|
||||
return GetByUserName(userName)
|
||||
.ContinueWith(userConnectionsTask =>
|
||||
{
|
||||
//
|
||||
var userConnections = userConnectionsTask
|
||||
.RunTask();
|
||||
|
||||
//
|
||||
var result = userConnections.Select (c => c.Device);
|
||||
var result = userConnections.Select(c => c.Device);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
@@ -98,8 +115,9 @@ namespace xPushService.Store {
|
||||
/// </summary>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public Task<bool> RemoveByConnectionId (string connectionId) {
|
||||
return RemoveByKey (connectionId);
|
||||
public Task<bool> RemoveByConnectionId(string connectionId)
|
||||
{
|
||||
return RemoveByKey(connectionId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -108,23 +126,26 @@ namespace xPushService.Store {
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="device"></param>
|
||||
/// <returns></returns>
|
||||
public Task<bool> RemoveByUserDevice (string userName, XDeviceDto device) {
|
||||
return GetByUserDevice (
|
||||
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;
|
||||
}
|
||||
|
||||
//
|
||||
var result = Remove (connection)
|
||||
var result = Remove(connection)
|
||||
.RunTask();
|
||||
return result;
|
||||
});
|
||||
@@ -135,22 +156,26 @@ namespace xPushService.Store {
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public Task<bool> RemoveUser (string userName) {
|
||||
return GetByUserName (userName)
|
||||
.ContinueWith (connectionsTask => {
|
||||
public Task<bool> RemoveUser(string userName)
|
||||
{
|
||||
return GetByUserName(userName)
|
||||
.ContinueWith(connectionsTask =>
|
||||
{
|
||||
//
|
||||
var connections = connectionsTask
|
||||
.RunTask();
|
||||
|
||||
//
|
||||
if (!connections.HasChild ()) {
|
||||
if (!connections.HasChild())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
var result = RemoveMany (new XBaseRangeRequest<XPushConnectionDto> {
|
||||
Items = connections
|
||||
})
|
||||
var result = RemoveMany(new XBaseRangeRequest<XPushConnectionDto>
|
||||
{
|
||||
Items = connections
|
||||
})
|
||||
.RunTask();
|
||||
|
||||
//
|
||||
@@ -163,16 +188,19 @@ namespace xPushService.Store {
|
||||
/// </summary>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public Task<DateTime> GetLastSeenByConnectionId (string connectionId) {
|
||||
return GetByConnectionId (connectionId)
|
||||
.ContinueWith (connectionTask => {
|
||||
public Task<DateTime> GetLastSeenByConnectionId(string connectionId)
|
||||
{
|
||||
return GetByConnectionId(connectionId)
|
||||
.ContinueWith(connectionTask =>
|
||||
{
|
||||
//
|
||||
var connection = connectionTask
|
||||
.RunTask();
|
||||
|
||||
//
|
||||
if (connection.IsNull ()) {
|
||||
throw XException.NotFound.ToException ();
|
||||
if (connection.IsNull())
|
||||
{
|
||||
throw XException.NotFound.ToException();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -186,22 +214,25 @@ namespace xPushService.Store {
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public Task<DateTime> GetLastSeenByUserName (string userName) {
|
||||
return GetByUserName (userName)
|
||||
.ContinueWith (connectionsTask => {
|
||||
public Task<DateTime> GetLastSeenByUserName(string userName)
|
||||
{
|
||||
return GetByUserName(userName)
|
||||
.ContinueWith(connectionsTask =>
|
||||
{
|
||||
//
|
||||
var connections = connectionsTask
|
||||
.RunTask ();
|
||||
.RunTask();
|
||||
|
||||
//
|
||||
if (!connections.HasChild ()) {
|
||||
throw XException.NotFound.ToException ();
|
||||
if (!connections.HasChild())
|
||||
{
|
||||
throw XException.NotFound.ToException();
|
||||
}
|
||||
|
||||
//
|
||||
var result = connections
|
||||
.Select (c => c.LastSeen)
|
||||
.Max ();
|
||||
.Select(c => c.LastSeen)
|
||||
.Max();
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -214,19 +245,22 @@ namespace xPushService.Store {
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="device"></param>
|
||||
/// <returns></returns>
|
||||
public Task<DateTime> GetLastSeenByUserDevice (string userName, XDeviceDto device) {
|
||||
return GetByUserDevice (
|
||||
public Task<DateTime> GetLastSeenByUserDevice(string userName, XDeviceDto device)
|
||||
{
|
||||
return GetByUserDevice(
|
||||
device: device,
|
||||
userName: userName
|
||||
)
|
||||
.ContinueWith (connectionTask => {
|
||||
.ContinueWith(connectionTask =>
|
||||
{
|
||||
//
|
||||
var connection = connectionTask
|
||||
.RunTask ();
|
||||
.RunTask();
|
||||
|
||||
//
|
||||
if (connection.IsNull ()) {
|
||||
throw XException.NotFound.ToException ();
|
||||
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) {
|
||||
return IsExistsConnectionId (connectionId)
|
||||
.ContinueWith (isExistsTask => {
|
||||
public Task<bool> UpdateLastSeen(string connectionId)
|
||||
{
|
||||
return IsExistsConnectionId(connectionId)
|
||||
.ContinueWith(isExistsTask =>
|
||||
{
|
||||
//
|
||||
// define empty result ...
|
||||
var result = false;
|
||||
@@ -254,25 +290,27 @@ namespace xPushService.Store {
|
||||
|
||||
//
|
||||
// check result is false ...
|
||||
if (!result) {
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// retreive connection ...
|
||||
var connection = GetByConnectionId (connectionId)
|
||||
var connection = GetByConnectionId(connectionId)
|
||||
.RunTask();
|
||||
result = !connection.IsNull ();
|
||||
if (!result) {
|
||||
result = !connection.IsNull();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Update Connection last seen ...
|
||||
connection.LastSeen = DateTime.UtcNow;
|
||||
var updatedConnection = Update (connection)
|
||||
.RunTask ();
|
||||
result = !updatedConnection.IsNull ();
|
||||
var updatedConnection = Update(connection)
|
||||
.RunTask();
|
||||
result = !updatedConnection.IsNull();
|
||||
|
||||
//
|
||||
return result;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user