add support for XWebinarGroupEntity and it's InMemory Repository and also Register it's required Services and usage in WebinarHub ...
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using xCommons.Extensions;
|
||||
using xDataService.Interfaces;
|
||||
using xDataService.Providers;
|
||||
using xExceptions.Constants;
|
||||
using xWebinarService.Interfaces;
|
||||
using xWebinarService.Interfaces.Entities;
|
||||
using xWebinarService.Models.Entities;
|
||||
using xWebinarService.Providers;
|
||||
|
||||
namespace xWebinarService.DI {
|
||||
namespace xWebinarService.DI
|
||||
{
|
||||
public static class XDIHelperExtension
|
||||
{
|
||||
/// <summary>
|
||||
@@ -89,6 +93,11 @@ namespace xWebinarService.DI {
|
||||
throw exception;
|
||||
}
|
||||
|
||||
//
|
||||
// Register Webinar Group In Memory Repository ...
|
||||
services.AddSingleton<IXKeyGenerator<XWebinarGroupEntity, Guid>, XGuidKeyGenerator<XWebinarGroupEntity>>();
|
||||
services.Add(new ServiceDescriptor(typeof(IXWebinarGroupStore), typeof(XWebinarGroupStore), ServiceLifetime.Singleton));
|
||||
|
||||
//
|
||||
// Register Resource Providers ...
|
||||
services.Add(new ServiceDescriptor(typeof(IXWebinarTitleResourceProvider), typeof(XWebinarTitleResourceProvider), lifeTime));
|
||||
@@ -97,11 +106,11 @@ namespace xWebinarService.DI {
|
||||
//
|
||||
// Register Main Provider ...
|
||||
services.Add(new ServiceDescriptor(typeof(IXWebinarProvider), typeof(XWebinarProvider), lifeTime));
|
||||
|
||||
|
||||
//
|
||||
Log("AddWebinarService Succeed ...");
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+126
-5
@@ -1,18 +1,18 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xCommons.Extensions;
|
||||
using xExceptions.Constants;
|
||||
using xIdentityModels.Models;
|
||||
using xPushService.Base;
|
||||
using xPushService.Extensions;
|
||||
using xWebinarService.Constants;
|
||||
using xWebinarService.Models.Dtos;
|
||||
using xWebinarService.Interfaces;
|
||||
using xWebinarService.Models.Entities;
|
||||
|
||||
namespace xWebinarService.Hubs
|
||||
{
|
||||
@@ -21,16 +21,19 @@ namespace xWebinarService.Hubs
|
||||
//
|
||||
#region Props ...
|
||||
public readonly IXWebinarProvider webinarProvider;
|
||||
private readonly IXWebinarGroupStore webinarGroupStore;
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Constructor ...
|
||||
public XWebinarHub(
|
||||
ILogger<XWebinarHub> logger,
|
||||
IXWebinarProvider webinarProvider
|
||||
IXWebinarProvider webinarProvider,
|
||||
IXWebinarGroupStore webinarGroupStore
|
||||
) : base(logger)
|
||||
{
|
||||
this.webinarProvider = webinarProvider;
|
||||
this.webinarGroupStore = webinarGroupStore;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -107,6 +110,35 @@ namespace xWebinarService.Hubs
|
||||
//
|
||||
// Create a Group and Put User on it ...
|
||||
await Groups.AddToGroupAsync(connectionId, webinarId.ToString());
|
||||
|
||||
//
|
||||
// Check Exists or not ...
|
||||
var connection = new XHubConnectionDto
|
||||
{
|
||||
UserId = userInfo.UserId,
|
||||
ConnectionId = connectionId,
|
||||
Username = userInfo.UserName,
|
||||
};
|
||||
var groupEntity = await webinarGroupStore.FindOneAsync(x => x.WebinarId == webinarId);
|
||||
if (!groupEntity.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
// Update ...
|
||||
groupEntity.Connections.Clear();
|
||||
groupEntity.Connections.Add(connection);
|
||||
await webinarGroupStore.UpdateAsync(groupEntity.Id, groupEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Add ...
|
||||
groupEntity = new XWebinarGroupEntity
|
||||
{
|
||||
WebinarId = webinarId
|
||||
};
|
||||
groupEntity.Connections.Add(connection);
|
||||
await webinarGroupStore.AddAsync(groupEntity);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
@@ -183,6 +215,14 @@ namespace xWebinarService.Hubs
|
||||
var webinarName = webinarId.ToString();
|
||||
await Clients.OthersInGroup(webinarName).SendAsync(XWebinarHubAction.WebinarClosed.ToString());
|
||||
await Groups.RemoveFromGroupAsync(connectionId, webinarName);
|
||||
|
||||
//
|
||||
// Check Exists or not ...
|
||||
var groupEntity = await webinarGroupStore.FindOneAsync(x => x.WebinarId == webinarId);
|
||||
if (!groupEntity.IsNullOrDefault())
|
||||
{
|
||||
await webinarGroupStore.RemoveAsync(groupEntity.Id);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
@@ -266,6 +306,33 @@ namespace xWebinarService.Hubs
|
||||
userInfo.UserId,
|
||||
userInfo.UserName
|
||||
);
|
||||
|
||||
//
|
||||
// Check Exists or not ...
|
||||
var connection = new XHubConnectionDto
|
||||
{
|
||||
UserId = userInfo.UserId,
|
||||
ConnectionId = connectionId,
|
||||
Username = userInfo.UserName,
|
||||
};
|
||||
var groupEntity = await webinarGroupStore.FindOneAsync(x => x.WebinarId == webinarId);
|
||||
if (!groupEntity.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
// Check Current User ID Exists ...
|
||||
var userConnection = groupEntity.Connections.FirstOrDefault(c => c.UserId == userInfo.UserId);
|
||||
if (!userConnection.IsNullOrDefault())
|
||||
{
|
||||
userConnection.ConnectionId = connectionId;
|
||||
}
|
||||
else
|
||||
{
|
||||
groupEntity.Connections.Add(connection);
|
||||
}
|
||||
|
||||
//
|
||||
await webinarGroupStore.UpdateAsync(groupEntity.Id, groupEntity);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
@@ -350,11 +417,65 @@ namespace xWebinarService.Hubs
|
||||
userInfo.UserId,
|
||||
userInfo.UserName
|
||||
);
|
||||
|
||||
//
|
||||
// Check Exists or not ...
|
||||
var groupEntity = await webinarGroupStore.FindOneAsync(x => x.WebinarId == webinarId);
|
||||
if (!groupEntity.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
// Check Current User ID Exists ...
|
||||
var userConnection = groupEntity.Connections.FirstOrDefault(c => c.ConnectionId == connectionId);
|
||||
if (!userConnection.IsNullOrDefault())
|
||||
{
|
||||
groupEntity.Connections.Remove(userConnection);
|
||||
}
|
||||
|
||||
//
|
||||
await webinarGroupStore.UpdateAsync(groupEntity.Id, groupEntity);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a Collection of Webinars Visitors ...
|
||||
/// </summary>
|
||||
/// <param name="webinarId"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public async Task<IEnumerable<XHubConnectionDto>> WebinarVisitors(Guid webinarId)
|
||||
{
|
||||
//
|
||||
var result = new List<XHubConnectionDto>();
|
||||
|
||||
//
|
||||
// Reading and Validate Requirements ...
|
||||
var userInfo = Context.GetUserInfo();
|
||||
var connectionId = Context.ConnectionId;
|
||||
|
||||
|
||||
//
|
||||
// Check Group Exists ...
|
||||
var groupEntity = await webinarGroupStore.FindOneAsync(x => x.WebinarId == webinarId);
|
||||
if (!groupEntity.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
// Validate Requester is a Viewer ...
|
||||
var connection = groupEntity.Connections.FirstOrDefault(c => c.ConnectionId == connectionId ||
|
||||
c.UserId == userInfo.UserId
|
||||
);
|
||||
if (!connection.IsNullOrDefault())
|
||||
{
|
||||
result = groupEntity.Connections;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a Message to Specified Webinar ...
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using xDataService.Interfaces;
|
||||
using xWebinarService.Models.Entities;
|
||||
|
||||
namespace xWebinarService.Interfaces
|
||||
{
|
||||
public interface IXWebinarGroupStore : IXBaseRepository<XWebinarGroupEntity, Guid>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using xModels.Base;
|
||||
using xPushService.Base;
|
||||
|
||||
namespace xWebinarService.Models.Entities
|
||||
{
|
||||
public class XWebinarGroupEntity : XBaseGuidIDEntity
|
||||
{
|
||||
public Guid WebinarId { get; set; }
|
||||
public List<XHubConnectionDto> Connections { get; set; } = new List<XHubConnectionDto>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using xDataService.Configuration;
|
||||
using xDataService.InMemRepositories;
|
||||
using xDataService.Interfaces;
|
||||
using xWebinarService.Interfaces;
|
||||
using xWebinarService.Models.Entities;
|
||||
|
||||
namespace xWebinarService.Providers
|
||||
{
|
||||
public class XWebinarGroupStore : XBaseInMemoryRepositoy<XWebinarGroupEntity, Guid>, IXWebinarGroupStore
|
||||
{
|
||||
public XWebinarGroupStore(
|
||||
XDataServiceConfiguration configuration,
|
||||
IXKeyGenerator<XWebinarGroupEntity, Guid> keyGenerator = null,
|
||||
IXBaseRepositoryEvents<XWebinarGroupEntity> baseRepositoryEvents = null
|
||||
) : base(configuration, keyGenerator, baseRepositoryEvents)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
<!-- Local Modules -->
|
||||
<ItemGroup>
|
||||
<PackageReference Include="xDashboard.xDataService" Version="1.0.0" />
|
||||
<!-- <PackageReference Include="xDashboard.xDataService" Version="1.0.0" /> -->
|
||||
<PackageReference Include="xDashboard.xStringService" Version="1.0.0" />
|
||||
<!-- <PackageReference Include="xDashboard.xIdentityService" Version="1.0.0" /> -->
|
||||
</ItemGroup>
|
||||
@@ -31,8 +31,8 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../xPushService/xPushService.csproj" />
|
||||
<ProjectReference Include="../xIdentityService/xIdentityService.csproj" />
|
||||
<!--
|
||||
<ProjectReference Include="../xDataService/xDataService.csproj" />
|
||||
<!--
|
||||
<ProjectReference Include="../xStringService/xStringService.csproj" />
|
||||
-->
|
||||
</ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user