diff --git a/DI/XDIHelperExtension.cs b/DI/XDIHelperExtension.cs index 7e28bf9..abc31de 100644 --- a/DI/XDIHelperExtension.cs +++ b/DI/XDIHelperExtension.cs @@ -261,7 +261,8 @@ namespace xPushService.DI { // Log($"there is no provided PushGroupStore, try to register XPushGroupInMemoryStore ..."); - groupStore = new XPushGroupInMemoryStore(); + var storeEvents = services.GetRegisteredService(); + groupStore = new XPushGroupInMemoryStore(storeEvents); services.AddSingleton(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(); + connectionStore = new XPushConnectionInMemoryStore(storeEvents); services.AddSingleton(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(); + webRtcConnectionStore = new XWebRTCConnectionInMemoryStore(storeEvents); services.AddSingleton(webRtcConnectionStore); } #endregion diff --git a/Events/XPushConnectionStoreEvents.cs b/Events/XPushConnectionStoreEvents.cs new file mode 100644 index 0000000..a56404e --- /dev/null +++ b/Events/XPushConnectionStoreEvents.cs @@ -0,0 +1,9 @@ +using xModels.Base; +using xPushService.Interfaces; +using xPushService.Models; + +namespace xPushService.Events +{ + public class XPushConnectionStoreEvents : XBaseStoreEvent, IXPushConnectionStoreEvents + { } +} \ No newline at end of file diff --git a/Events/XPushGroupStoreEvents.cs b/Events/XPushGroupStoreEvents.cs new file mode 100644 index 0000000..a00ad81 --- /dev/null +++ b/Events/XPushGroupStoreEvents.cs @@ -0,0 +1,9 @@ +using xModels.Base; +using xPushService.Interfaces; +using xPushService.Models; + +namespace xPushService.Events +{ + public class XPushGroupStoreEvents : XBaseStoreEvent, IXPushGroupStoreEvents + { } +} \ No newline at end of file diff --git a/Events/XWebRTCConnectionStoreEvents.cs b/Events/XWebRTCConnectionStoreEvents.cs new file mode 100644 index 0000000..8a1ea21 --- /dev/null +++ b/Events/XWebRTCConnectionStoreEvents.cs @@ -0,0 +1,9 @@ +using xModels.Base; +using xPushService.Interfaces; +using xPushService.Models; + +namespace xPushService.Events +{ + public class XWebRTCConnectionStoreEvents : XBaseStoreEvent, IXWebRTCConnectionStoreEvents + { } +} \ No newline at end of file diff --git a/Interfaces/IXPushConnectionStoreEvents.cs b/Interfaces/IXPushConnectionStoreEvents.cs new file mode 100644 index 0000000..2b4cc39 --- /dev/null +++ b/Interfaces/IXPushConnectionStoreEvents.cs @@ -0,0 +1,8 @@ +using xModels.Interfaces; +using xPushService.Models; + +namespace xPushService.Interfaces +{ + public interface IXPushConnectionStoreEvents : IXBaseStoreEvents + { } +} \ No newline at end of file diff --git a/Interfaces/IXPushGroupStore.cs b/Interfaces/IXPushGroupStore.cs index c25eb68..481db41 100644 --- a/Interfaces/IXPushGroupStore.cs +++ b/Interfaces/IXPushGroupStore.cs @@ -1,6 +1,8 @@ using xModels.Interfaces; using xPushService.Models; -namespace xPushService.Interfaces { - public interface IXPushGroupStore : IXBaseStore { } +namespace xPushService.Interfaces +{ + public interface IXPushGroupStore : IXBaseStore + { } } \ No newline at end of file diff --git a/Interfaces/IXPushGroupStoreEvents.cs b/Interfaces/IXPushGroupStoreEvents.cs new file mode 100644 index 0000000..0073d62 --- /dev/null +++ b/Interfaces/IXPushGroupStoreEvents.cs @@ -0,0 +1,8 @@ +using xModels.Interfaces; +using xPushService.Models; + +namespace xPushService.Interfaces +{ + public interface IXPushGroupStoreEvents : IXBaseStoreEvents + {} +} \ No newline at end of file diff --git a/Interfaces/IXWebRTCConnectionStoreEvents.cs b/Interfaces/IXWebRTCConnectionStoreEvents.cs new file mode 100644 index 0000000..cb64f18 --- /dev/null +++ b/Interfaces/IXWebRTCConnectionStoreEvents.cs @@ -0,0 +1,8 @@ +using xModels.Interfaces; +using xPushService.Models; + +namespace xPushService.Interfaces +{ + public interface IXWebRTCConnectionStoreEvents : IXBaseStoreEvents + { } +} \ No newline at end of file diff --git a/Store/XPushConnectionInMemoryStore.cs b/Store/XPushConnectionInMemoryStore.cs index ca0ec36..a031e87 100644 --- a/Store/XPushConnectionInMemoryStore.cs +++ b/Store/XPushConnectionInMemoryStore.cs @@ -10,8 +10,17 @@ using xModels.Providers; using xPushService.Interfaces; using xPushService.Models; -namespace xPushService.Store { - public class XPushConnectionInMemoryStore : XBaseInMemoryStore, IXPushConnectionStore { +namespace xPushService.Store +{ + public class XPushConnectionInMemoryStore : XBaseInMemoryStore, IXPushConnectionStore + { + // + #region Constructor ... + public XPushConnectionInMemoryStore( + IXPushConnectionStoreEvents events = null + ) : base(events) {} + #endregion + // #region Custom ... /// @@ -19,8 +28,9 @@ namespace xPushService.Store { /// /// /// - public Task GetByConnectionId (string connectionId) { - return Get (connectionId); + public Task GetByConnectionId(string connectionId) + { + return Get(connectionId); } /// @@ -28,8 +38,9 @@ namespace xPushService.Store { /// /// /// - public Task> GetByUserName (string userName) { - return FindMany (c => c.User.ToNormalString () == userName.ToNormalString ()); + public Task> GetByUserName(string userName) + { + return FindMany(c => c.User.ToNormalString() == userName.ToNormalString()); } /// @@ -38,10 +49,11 @@ namespace xPushService.Store { /// /// /// - public Task GetByUserDevice (string userName, XDeviceDto device) { - return FindOne (c => - c.User.ToNormalString () == userName.ToNormalString () && - c.Device.IsSameContent ( + public Task 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 { /// /// /// - public Task IsExistsConnectionId (string connectionId) { - return IsExistsByKey (connectionId); + public Task IsExistsConnectionId(string connectionId) + { + return IsExistsByKey(connectionId); } /// @@ -61,15 +74,17 @@ namespace xPushService.Store { /// /// /// - public Task IsExistsUser (string userName) { - return GetByUserName (userName) - .ContinueWith (findTask => { + public Task 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 { /// /// /// - public Task> GetUserDevices (string userName) { - return GetByUserName (userName) - .ContinueWith (userConnectionsTask => { + public Task> 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 { /// /// /// - public Task RemoveByConnectionId (string connectionId) { - return RemoveByKey (connectionId); + public Task RemoveByConnectionId(string connectionId) + { + return RemoveByKey(connectionId); } /// @@ -108,23 +126,26 @@ namespace xPushService.Store { /// /// /// - public Task RemoveByUserDevice (string userName, XDeviceDto device) { - return GetByUserDevice ( + public Task 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 { /// /// /// - public Task RemoveUser (string userName) { - return GetByUserName (userName) - .ContinueWith (connectionsTask => { + public Task 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 { - Items = connections - }) + var result = RemoveMany(new XBaseRangeRequest + { + Items = connections + }) .RunTask(); // @@ -163,16 +188,19 @@ namespace xPushService.Store { /// /// /// - public Task GetLastSeenByConnectionId (string connectionId) { - return GetByConnectionId (connectionId) - .ContinueWith (connectionTask => { + public Task 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 { /// /// /// - public Task GetLastSeenByUserName (string userName) { - return GetByUserName (userName) - .ContinueWith (connectionsTask => { + public Task 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 { /// /// /// - public Task GetLastSeenByUserDevice (string userName, XDeviceDto device) { - return GetByUserDevice ( + public Task 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 { /// /// /// - public Task UpdateLastSeen (string connectionId) { - return IsExistsConnectionId (connectionId) - .ContinueWith (isExistsTask => { + public Task 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; diff --git a/Store/XPushGroupInMemoryStore.cs b/Store/XPushGroupInMemoryStore.cs index 60712cc..d1c3036 100644 --- a/Store/XPushGroupInMemoryStore.cs +++ b/Store/XPushGroupInMemoryStore.cs @@ -2,6 +2,15 @@ using xModels.Providers; using xPushService.Interfaces; using xPushService.Models; -namespace xPushService.Store { - public class XPushGroupInMemoryStore : XBaseInMemoryStore, IXPushGroupStore { } +namespace xPushService.Store +{ + public class XPushGroupInMemoryStore : XBaseInMemoryStore, IXPushGroupStore + { + // + #region Constructor ... + public XPushGroupInMemoryStore( + IXPushGroupStoreEvents events = null + ) : base(events) { } + #endregion + } } \ No newline at end of file diff --git a/Store/XWebRTCConnectionInMemoryStore.cs b/Store/XWebRTCConnectionInMemoryStore.cs index 02dd98f..a02ad7f 100644 --- a/Store/XWebRTCConnectionInMemoryStore.cs +++ b/Store/XWebRTCConnectionInMemoryStore.cs @@ -2,6 +2,15 @@ using xModels.Providers; using xPushService.Interfaces; using xPushService.Models; -namespace xPushService.Store { - public class XWebRTCConnectionInMemoryStore : XBaseInMemoryStore, IXWebRTCConnectionStore { } +namespace xPushService.Store +{ + public class XWebRTCConnectionInMemoryStore : XBaseInMemoryStore, IXWebRTCConnectionStore + { + // + #region Constructor ... + public XWebRTCConnectionInMemoryStore( + IXWebRTCConnectionStoreEvents events = null + ) : base(events) { } + #endregion + } } \ No newline at end of file