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 ...");
|
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);
|
services.AddSingleton<IXPushGroupStore>(groupStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,7 +272,8 @@ namespace xPushService.DI
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
Log($"there is no provided XPushConnectionStore, try to register XPushConnectionInMemoryStore ...");
|
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);
|
services.AddSingleton<IXPushConnectionStore>(connectionStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,7 +283,8 @@ namespace xPushService.DI
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
Log($"there is no provided XWebRTCConnectionStore, try to register XWebRTCConnectionInMemoryStore ...");
|
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);
|
services.AddSingleton<IXWebRTCConnectionStore>(webRtcConnectionStore);
|
||||||
}
|
}
|
||||||
#endregion
|
#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 xModels.Interfaces;
|
||||||
using xPushService.Models;
|
using xPushService.Models;
|
||||||
|
|
||||||
namespace xPushService.Interfaces {
|
namespace xPushService.Interfaces
|
||||||
public interface IXPushGroupStore : IXBaseStore<XPushGroupDto, string> { }
|
{
|
||||||
|
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.Interfaces;
|
||||||
using xPushService.Models;
|
using xPushService.Models;
|
||||||
|
|
||||||
namespace xPushService.Store {
|
namespace xPushService.Store
|
||||||
public class XPushConnectionInMemoryStore : XBaseInMemoryStore<XPushConnectionDto, string>, IXPushConnectionStore {
|
{
|
||||||
|
public class XPushConnectionInMemoryStore : XBaseInMemoryStore<XPushConnectionDto, string>, IXPushConnectionStore
|
||||||
|
{
|
||||||
|
//
|
||||||
|
#region Constructor ...
|
||||||
|
public XPushConnectionInMemoryStore(
|
||||||
|
IXPushConnectionStoreEvents events = null
|
||||||
|
) : base(events) {}
|
||||||
|
#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
#region Custom ...
|
#region Custom ...
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -19,7 +28,8 @@ namespace xPushService.Store {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Task<XPushConnectionDto> GetByConnectionId (string connectionId) {
|
public Task<XPushConnectionDto> GetByConnectionId(string connectionId)
|
||||||
|
{
|
||||||
return Get(connectionId);
|
return Get(connectionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +38,8 @@ namespace xPushService.Store {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Task<IEnumerable<XPushConnectionDto>> GetByUserName (string userName) {
|
public Task<IEnumerable<XPushConnectionDto>> GetByUserName(string userName)
|
||||||
|
{
|
||||||
return FindMany(c => c.User.ToNormalString() == userName.ToNormalString());
|
return FindMany(c => c.User.ToNormalString() == userName.ToNormalString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +49,8 @@ namespace xPushService.Store {
|
|||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
/// <param name="device"></param>
|
/// <param name="device"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Task<XPushConnectionDto> GetByUserDevice (string userName, XDeviceDto device) {
|
public Task<XPushConnectionDto> GetByUserDevice(string userName, XDeviceDto device)
|
||||||
|
{
|
||||||
return FindOne(c =>
|
return FindOne(c =>
|
||||||
c.User.ToNormalString() == userName.ToNormalString() &&
|
c.User.ToNormalString() == userName.ToNormalString() &&
|
||||||
c.Device.IsSameContent(
|
c.Device.IsSameContent(
|
||||||
@@ -52,7 +64,8 @@ namespace xPushService.Store {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Task<bool> IsExistsConnectionId (string connectionId) {
|
public Task<bool> IsExistsConnectionId(string connectionId)
|
||||||
|
{
|
||||||
return IsExistsByKey(connectionId);
|
return IsExistsByKey(connectionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,9 +74,11 @@ namespace xPushService.Store {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Task<bool> IsExistsUser (string userName) {
|
public Task<bool> IsExistsUser(string userName)
|
||||||
|
{
|
||||||
return GetByUserName(userName)
|
return GetByUserName(userName)
|
||||||
.ContinueWith (findTask => {
|
.ContinueWith(findTask =>
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var findResult = findTask
|
var findResult = findTask
|
||||||
.RunTask();
|
.RunTask();
|
||||||
@@ -80,9 +95,11 @@ namespace xPushService.Store {
|
|||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
/// <param name="device"></param>
|
/// <param name="device"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Task<IEnumerable<XDeviceDto>> GetUserDevices (string userName) {
|
public Task<IEnumerable<XDeviceDto>> GetUserDevices(string userName)
|
||||||
|
{
|
||||||
return GetByUserName(userName)
|
return GetByUserName(userName)
|
||||||
.ContinueWith (userConnectionsTask => {
|
.ContinueWith(userConnectionsTask =>
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var userConnections = userConnectionsTask
|
var userConnections = userConnectionsTask
|
||||||
.RunTask();
|
.RunTask();
|
||||||
@@ -98,7 +115,8 @@ namespace xPushService.Store {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Task<bool> RemoveByConnectionId (string connectionId) {
|
public Task<bool> RemoveByConnectionId(string connectionId)
|
||||||
|
{
|
||||||
return RemoveByKey(connectionId);
|
return RemoveByKey(connectionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,18 +126,21 @@ namespace xPushService.Store {
|
|||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
/// <param name="device"></param>
|
/// <param name="device"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Task<bool> RemoveByUserDevice (string userName, XDeviceDto device) {
|
public Task<bool> RemoveByUserDevice(string userName, XDeviceDto device)
|
||||||
|
{
|
||||||
return GetByUserDevice(
|
return GetByUserDevice(
|
||||||
device: device,
|
device: device,
|
||||||
userName: userName
|
userName: userName
|
||||||
)
|
)
|
||||||
.ContinueWith (connectionTask => {
|
.ContinueWith(connectionTask =>
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var connection = connectionTask
|
var connection = connectionTask
|
||||||
.RunTask();
|
.RunTask();
|
||||||
|
|
||||||
//
|
//
|
||||||
if (connection.IsNull ()) {
|
if (connection.IsNull())
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,20 +156,24 @@ namespace xPushService.Store {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Task<bool> RemoveUser (string userName) {
|
public Task<bool> RemoveUser(string userName)
|
||||||
|
{
|
||||||
return GetByUserName(userName)
|
return GetByUserName(userName)
|
||||||
.ContinueWith (connectionsTask => {
|
.ContinueWith(connectionsTask =>
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var connections = connectionsTask
|
var connections = connectionsTask
|
||||||
.RunTask();
|
.RunTask();
|
||||||
|
|
||||||
//
|
//
|
||||||
if (!connections.HasChild ()) {
|
if (!connections.HasChild())
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
var result = RemoveMany (new XBaseRangeRequest<XPushConnectionDto> {
|
var result = RemoveMany(new XBaseRangeRequest<XPushConnectionDto>
|
||||||
|
{
|
||||||
Items = connections
|
Items = connections
|
||||||
})
|
})
|
||||||
.RunTask();
|
.RunTask();
|
||||||
@@ -163,15 +188,18 @@ namespace xPushService.Store {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Task<DateTime> GetLastSeenByConnectionId (string connectionId) {
|
public Task<DateTime> GetLastSeenByConnectionId(string connectionId)
|
||||||
|
{
|
||||||
return GetByConnectionId(connectionId)
|
return GetByConnectionId(connectionId)
|
||||||
.ContinueWith (connectionTask => {
|
.ContinueWith(connectionTask =>
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var connection = connectionTask
|
var connection = connectionTask
|
||||||
.RunTask();
|
.RunTask();
|
||||||
|
|
||||||
//
|
//
|
||||||
if (connection.IsNull ()) {
|
if (connection.IsNull())
|
||||||
|
{
|
||||||
throw XException.NotFound.ToException();
|
throw XException.NotFound.ToException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,15 +214,18 @@ namespace xPushService.Store {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Task<DateTime> GetLastSeenByUserName (string userName) {
|
public Task<DateTime> GetLastSeenByUserName(string userName)
|
||||||
|
{
|
||||||
return GetByUserName(userName)
|
return GetByUserName(userName)
|
||||||
.ContinueWith (connectionsTask => {
|
.ContinueWith(connectionsTask =>
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var connections = connectionsTask
|
var connections = connectionsTask
|
||||||
.RunTask();
|
.RunTask();
|
||||||
|
|
||||||
//
|
//
|
||||||
if (!connections.HasChild ()) {
|
if (!connections.HasChild())
|
||||||
|
{
|
||||||
throw XException.NotFound.ToException();
|
throw XException.NotFound.ToException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,18 +245,21 @@ namespace xPushService.Store {
|
|||||||
/// <param name="userName"></param>
|
/// <param name="userName"></param>
|
||||||
/// <param name="device"></param>
|
/// <param name="device"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Task<DateTime> GetLastSeenByUserDevice (string userName, XDeviceDto device) {
|
public Task<DateTime> GetLastSeenByUserDevice(string userName, XDeviceDto device)
|
||||||
|
{
|
||||||
return GetByUserDevice(
|
return GetByUserDevice(
|
||||||
device: device,
|
device: device,
|
||||||
userName: userName
|
userName: userName
|
||||||
)
|
)
|
||||||
.ContinueWith (connectionTask => {
|
.ContinueWith(connectionTask =>
|
||||||
|
{
|
||||||
//
|
//
|
||||||
var connection = connectionTask
|
var connection = connectionTask
|
||||||
.RunTask();
|
.RunTask();
|
||||||
|
|
||||||
//
|
//
|
||||||
if (connection.IsNull ()) {
|
if (connection.IsNull())
|
||||||
|
{
|
||||||
throw XException.NotFound.ToException();
|
throw XException.NotFound.ToException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,9 +274,11 @@ namespace xPushService.Store {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Task<bool> UpdateLastSeen (string connectionId) {
|
public Task<bool> UpdateLastSeen(string connectionId)
|
||||||
|
{
|
||||||
return IsExistsConnectionId(connectionId)
|
return IsExistsConnectionId(connectionId)
|
||||||
.ContinueWith (isExistsTask => {
|
.ContinueWith(isExistsTask =>
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// define empty result ...
|
// define empty result ...
|
||||||
var result = false;
|
var result = false;
|
||||||
@@ -254,7 +290,8 @@ namespace xPushService.Store {
|
|||||||
|
|
||||||
//
|
//
|
||||||
// check result is false ...
|
// check result is false ...
|
||||||
if (!result) {
|
if (!result)
|
||||||
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,7 +300,8 @@ namespace xPushService.Store {
|
|||||||
var connection = GetByConnectionId(connectionId)
|
var connection = GetByConnectionId(connectionId)
|
||||||
.RunTask();
|
.RunTask();
|
||||||
result = !connection.IsNull();
|
result = !connection.IsNull();
|
||||||
if (!result) {
|
if (!result)
|
||||||
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,15 @@ using xModels.Providers;
|
|||||||
using xPushService.Interfaces;
|
using xPushService.Interfaces;
|
||||||
using xPushService.Models;
|
using xPushService.Models;
|
||||||
|
|
||||||
namespace xPushService.Store {
|
namespace xPushService.Store
|
||||||
public class XPushGroupInMemoryStore : XBaseInMemoryStore<XPushGroupDto, string>, IXPushGroupStore { }
|
{
|
||||||
|
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.Interfaces;
|
||||||
using xPushService.Models;
|
using xPushService.Models;
|
||||||
|
|
||||||
namespace xPushService.Store {
|
namespace xPushService.Store
|
||||||
public class XWebRTCConnectionInMemoryStore : XBaseInMemoryStore<XWebRTCConnectionDto, string>, IXWebRTCConnectionStore { }
|
{
|
||||||
|
public class XWebRTCConnectionInMemoryStore : XBaseInMemoryStore<XWebRTCConnectionDto, string>, IXWebRTCConnectionStore
|
||||||
|
{
|
||||||
|
//
|
||||||
|
#region Constructor ...
|
||||||
|
public XWebRTCConnectionInMemoryStore(
|
||||||
|
IXWebRTCConnectionStoreEvents events = null
|
||||||
|
) : base(events) { }
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user