Add Support for Hub Actions Implementation ...
This commit is contained in:
@@ -2,6 +2,9 @@ using xExceptions.Attributes;
|
|||||||
|
|
||||||
namespace xWebinarService.Constants
|
namespace xWebinarService.Constants
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Webinar Connection Hub Actions ...
|
||||||
|
/// </summary>
|
||||||
public enum XWebinarHubAction
|
public enum XWebinarHubAction
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -34,4 +37,15 @@ namespace xWebinarService.Constants
|
|||||||
[StringValue("Message")]
|
[StringValue("Message")]
|
||||||
Message,
|
Message,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Entity Hub Actions ...
|
||||||
|
/// </summary>
|
||||||
|
public enum XWebinarEntityHubAction
|
||||||
|
{
|
||||||
|
[StringValue("Subscribed")]
|
||||||
|
Subscribed,
|
||||||
|
[StringValue("Unsubscribe")]
|
||||||
|
Unsubscribe
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using xPushService.Base;
|
||||||
|
using xWebinarService.Models.Entities;
|
||||||
|
|
||||||
|
namespace xWebinarService.Hubs
|
||||||
|
{
|
||||||
|
public class XWebinarEntityHub : XBaseEntityHub<XWebinar, Guid>
|
||||||
|
{
|
||||||
|
//
|
||||||
|
#region Constructor ...
|
||||||
|
public XWebinarEntityHub(ILogger<XBaseHub> logger) : base(logger)
|
||||||
|
{ }
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using xDataService.Configuration;
|
using xDataService.Configuration;
|
||||||
using xIdentityService.Interfaces;
|
using xIdentityService.Interfaces;
|
||||||
using xModels.Dtos;
|
using xModels.Dtos;
|
||||||
|
using xWebinarService.Hubs;
|
||||||
using xWebinarService.Interfaces.Entities;
|
using xWebinarService.Interfaces.Entities;
|
||||||
using xWebinarService.Models.Dtos;
|
using xWebinarService.Models.Dtos;
|
||||||
using xWebinarService.Models.Entities;
|
using xWebinarService.Models.Entities;
|
||||||
@@ -14,6 +16,7 @@ namespace xWebinarService.Interfaces
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
#region Props ...
|
#region Props ...
|
||||||
|
IHubContext<XWebinarEntityHub> Hub { get; }
|
||||||
IXIdentityProvider IdentityProvider { get; }
|
IXIdentityProvider IdentityProvider { get; }
|
||||||
IXWebinarRepository WebinarRepository { get; }
|
IXWebinarRepository WebinarRepository { get; }
|
||||||
XDataServiceConfiguration DataSercviceConfiguration { get; }
|
XDataServiceConfiguration DataSercviceConfiguration { get; }
|
||||||
@@ -46,15 +49,23 @@ namespace xWebinarService.Interfaces
|
|||||||
/// Create Webinar ...
|
/// Create Webinar ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<XWebinarDto> CreateWebinar(XWebinarDto item);
|
Task<XWebinarDto> CreateWebinar(
|
||||||
|
XWebinarDto item,
|
||||||
|
string connectionId = null
|
||||||
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update a Webinar ...
|
/// Update a Webinar ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<XWebinarDto> UpdateWebinar(XWebinarDto item);
|
Task<XWebinarDto> UpdateWebinar(
|
||||||
|
XWebinarDto item,
|
||||||
|
string connectionId = null
|
||||||
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieve Specified Webinar ...
|
/// Retrieve Specified Webinar ...
|
||||||
@@ -93,8 +104,12 @@ namespace xWebinarService.Interfaces
|
|||||||
/// Remove Specified Webinar ...
|
/// Remove Specified Webinar ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="webinarId"></param>
|
/// <param name="webinarId"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<bool> RemoveWebinar(Guid webinarId);
|
Task<bool> RemoveWebinar(
|
||||||
|
Guid webinarId,
|
||||||
|
string connectionId = null
|
||||||
|
);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -104,10 +119,12 @@ namespace xWebinarService.Interfaces
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="webinarId"></param>
|
/// <param name="webinarId"></param>
|
||||||
/// <param name="subscriberId"></param>
|
/// <param name="subscriberId"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<bool> Subscribe(
|
Task<bool> Subscribe(
|
||||||
Guid webinarId,
|
Guid webinarId,
|
||||||
string subscriberId
|
string subscriberId,
|
||||||
|
string connectionId = null
|
||||||
);
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -126,10 +143,12 @@ namespace xWebinarService.Interfaces
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="webinarId"></param>
|
/// <param name="webinarId"></param>
|
||||||
/// <param name="subscriberId"></param>
|
/// <param name="subscriberId"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<bool> Unsubscribe(
|
Task<bool> Unsubscribe(
|
||||||
Guid webinarId,
|
Guid webinarId,
|
||||||
string subscriberId
|
string subscriberId,
|
||||||
|
string connectionId = null
|
||||||
);
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
using xDataService.Configuration;
|
using xDataService.Configuration;
|
||||||
using xDataService.Extensions;
|
using xDataService.Extensions;
|
||||||
@@ -10,7 +11,9 @@ using xIdentityModels.Dtos;
|
|||||||
using xIdentityService.Extensions;
|
using xIdentityService.Extensions;
|
||||||
using xIdentityService.Interfaces;
|
using xIdentityService.Interfaces;
|
||||||
using xModels.Dtos;
|
using xModels.Dtos;
|
||||||
|
using xPushService.Constants;
|
||||||
using xWebinarService.Constants;
|
using xWebinarService.Constants;
|
||||||
|
using xWebinarService.Hubs;
|
||||||
using xWebinarService.Interfaces;
|
using xWebinarService.Interfaces;
|
||||||
using xWebinarService.Interfaces.Entities;
|
using xWebinarService.Interfaces.Entities;
|
||||||
using xWebinarService.Models.Dtos;
|
using xWebinarService.Models.Dtos;
|
||||||
@@ -25,6 +28,7 @@ namespace xWebinarService.Providers
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
#region Props ...
|
#region Props ...
|
||||||
|
public IHubContext<XWebinarEntityHub> Hub { get; }
|
||||||
public IXIdentityProvider IdentityProvider { get; }
|
public IXIdentityProvider IdentityProvider { get; }
|
||||||
public IXWebinarRepository WebinarRepository { get; }
|
public IXWebinarRepository WebinarRepository { get; }
|
||||||
public XDataServiceConfiguration DataSercviceConfiguration { get; }
|
public XDataServiceConfiguration DataSercviceConfiguration { get; }
|
||||||
@@ -41,7 +45,8 @@ namespace xWebinarService.Providers
|
|||||||
XDataServiceConfiguration dataSercviceConfiguration,
|
XDataServiceConfiguration dataSercviceConfiguration,
|
||||||
IXWebinarTitleResourceProvider titleResourceProvider,
|
IXWebinarTitleResourceProvider titleResourceProvider,
|
||||||
IXWebinarSubscriberRepository webinarSubscriberRepository,
|
IXWebinarSubscriberRepository webinarSubscriberRepository,
|
||||||
IXWebinarDescriptionResourceProvider descriptionResourceProvider
|
IXWebinarDescriptionResourceProvider descriptionResourceProvider,
|
||||||
|
IHubContext<XWebinarEntityHub> hub = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -51,6 +56,7 @@ namespace xWebinarService.Providers
|
|||||||
TitleResourceProvider = titleResourceProvider;
|
TitleResourceProvider = titleResourceProvider;
|
||||||
WebinarSubscriberRepository = webinarSubscriberRepository;
|
WebinarSubscriberRepository = webinarSubscriberRepository;
|
||||||
DescriptionResourceProvider = descriptionResourceProvider;
|
DescriptionResourceProvider = descriptionResourceProvider;
|
||||||
|
Hub = hub;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -163,8 +169,12 @@ namespace xWebinarService.Providers
|
|||||||
/// Create Webinar ...
|
/// Create Webinar ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<XWebinarDto> CreateWebinar(XWebinarDto item)
|
public async Task<XWebinarDto> CreateWebinar(
|
||||||
|
XWebinarDto item,
|
||||||
|
string connectionId = null
|
||||||
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Validate ...
|
// Validate ...
|
||||||
@@ -276,6 +286,13 @@ namespace xWebinarService.Providers
|
|||||||
XException.ActionFailed.Throw();
|
XException.ActionFailed.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
await SendPush(
|
||||||
|
action: XBaseEntityHubAction.Add.GetStringValue(),
|
||||||
|
payLoad: entity.ToJSON(),
|
||||||
|
connectionId: connectionId
|
||||||
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Convert Entity to Dto ...
|
// Convert Entity to Dto ...
|
||||||
var result = await ToXWebinarDto(entity);
|
var result = await ToXWebinarDto(entity);
|
||||||
@@ -286,8 +303,12 @@ namespace xWebinarService.Providers
|
|||||||
/// Update a Webinar ...
|
/// Update a Webinar ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<XWebinarDto> UpdateWebinar(XWebinarDto item)
|
public async Task<XWebinarDto> UpdateWebinar(
|
||||||
|
XWebinarDto item,
|
||||||
|
string connectionId = null
|
||||||
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Validate ...
|
// Validate ...
|
||||||
@@ -413,8 +434,20 @@ namespace xWebinarService.Providers
|
|||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
entity = await WebinarRepository.GetAsync(entity.Id);
|
||||||
var result = await ToXWebinarDto(entity);
|
var result = await ToXWebinarDto(entity);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!result.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
await SendPush(
|
||||||
|
action: XBaseEntityHubAction.Update.GetStringValue(),
|
||||||
|
payLoad: entity.ToJSON(),
|
||||||
|
connectionId: connectionId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -615,9 +648,11 @@ namespace xWebinarService.Providers
|
|||||||
/// Remove Specified Webinar ...
|
/// Remove Specified Webinar ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="webinarId"></param>
|
/// <param name="webinarId"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<bool> RemoveWebinar(
|
public async Task<bool> RemoveWebinar(
|
||||||
Guid webinarId
|
Guid webinarId,
|
||||||
|
string connectionId = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -668,6 +703,15 @@ namespace xWebinarService.Providers
|
|||||||
//
|
//
|
||||||
// Check Entity Removed ...
|
// Check Entity Removed ...
|
||||||
result = !await WebinarRepository.IsExistsAsync(webinarId);
|
result = !await WebinarRepository.IsExistsAsync(webinarId);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
await SendPush(
|
||||||
|
action: XBaseEntityHubAction.Delete.GetStringValue(),
|
||||||
|
payLoad: entity.ToJSON(),
|
||||||
|
connectionId: connectionId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
@@ -681,10 +725,12 @@ namespace xWebinarService.Providers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="webinarId"></param>
|
/// <param name="webinarId"></param>
|
||||||
/// <param name="subscriberId"></param>
|
/// <param name="subscriberId"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<bool> Subscribe(
|
public async Task<bool> Subscribe(
|
||||||
Guid webinarId,
|
Guid webinarId,
|
||||||
string subscriberId
|
string subscriberId,
|
||||||
|
string connectionId = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -750,6 +796,15 @@ namespace xWebinarService.Providers
|
|||||||
};
|
};
|
||||||
entity = await WebinarSubscriberRepository.AddAsync(entity);
|
entity = await WebinarSubscriberRepository.AddAsync(entity);
|
||||||
result = !entity.IsNullOrDefault();
|
result = !entity.IsNullOrDefault();
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
await SendPush(
|
||||||
|
action: XWebinarEntityHubAction.Subscribed.GetStringValue(),
|
||||||
|
payLoad: entity.ToJSON(),
|
||||||
|
connectionId: connectionId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
@@ -822,10 +877,12 @@ namespace xWebinarService.Providers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="webinarId"></param>
|
/// <param name="webinarId"></param>
|
||||||
/// <param name="subscriberId"></param>
|
/// <param name="subscriberId"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<bool> Unsubscribe(
|
public async Task<bool> Unsubscribe(
|
||||||
Guid webinarId,
|
Guid webinarId,
|
||||||
string subscriberId
|
string subscriberId,
|
||||||
|
string connectionId = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -865,6 +922,15 @@ namespace xWebinarService.Providers
|
|||||||
);
|
);
|
||||||
entity = await WebinarSubscriberRepository.RemoveAsync(entity);
|
entity = await WebinarSubscriberRepository.RemoveAsync(entity);
|
||||||
result = !entity.IsNullOrDefault();
|
result = !entity.IsNullOrDefault();
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
await SendPush(
|
||||||
|
action: XWebinarEntityHubAction.Unsubscribe.GetStringValue(),
|
||||||
|
payLoad: entity.ToJSON(),
|
||||||
|
connectionId: connectionId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
@@ -1054,5 +1120,55 @@ namespace xWebinarService.Providers
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Hub Actions ...
|
||||||
|
/// <summary>
|
||||||
|
/// Send Custom Push Message ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="action"></param>
|
||||||
|
/// <param name="payLoad"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task SendPush(
|
||||||
|
string action,
|
||||||
|
string payLoad,
|
||||||
|
string connectionId = null
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var actions = new List<string>
|
||||||
|
{
|
||||||
|
XBaseEntityHubAction.Add.GetStringValue(),
|
||||||
|
XBaseEntityHubAction.Update.GetStringValue(),
|
||||||
|
XBaseEntityHubAction.Delete.GetStringValue(),
|
||||||
|
XBaseEntityHubAction.AddMany.GetStringValue(),
|
||||||
|
XBaseEntityHubAction.DeleteMany.GetStringValue(),
|
||||||
|
XBaseEntityHubAction.UpdateMany.GetStringValue(),
|
||||||
|
XBaseEntityHubAction.AddOrUpdate.GetStringValue(),
|
||||||
|
XWebinarEntityHubAction.Subscribed.GetStringValue(),
|
||||||
|
XWebinarEntityHubAction.Unsubscribe.GetStringValue(),
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
var isValid =
|
||||||
|
!Hub.IsNull() &&
|
||||||
|
!action.IsNullOrEmpty() &&
|
||||||
|
actions.Contains(action);
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var clients = Hub.Clients.All;
|
||||||
|
if (!connectionId.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
clients = Hub.Clients.AllExcept(connectionId);
|
||||||
|
}
|
||||||
|
await clients.SendAsync(action, payLoad, connectionId);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user