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 System;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
|
using xDataService.Interfaces;
|
||||||
|
using xDataService.Providers;
|
||||||
using xExceptions.Constants;
|
using xExceptions.Constants;
|
||||||
using xWebinarService.Interfaces;
|
using xWebinarService.Interfaces;
|
||||||
using xWebinarService.Interfaces.Entities;
|
using xWebinarService.Interfaces.Entities;
|
||||||
|
using xWebinarService.Models.Entities;
|
||||||
using xWebinarService.Providers;
|
using xWebinarService.Providers;
|
||||||
|
|
||||||
namespace xWebinarService.DI {
|
namespace xWebinarService.DI
|
||||||
|
{
|
||||||
public static class XDIHelperExtension
|
public static class XDIHelperExtension
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -89,6 +93,11 @@ namespace xWebinarService.DI {
|
|||||||
throw exception;
|
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 ...
|
// Register Resource Providers ...
|
||||||
services.Add(new ServiceDescriptor(typeof(IXWebinarTitleResourceProvider), typeof(XWebinarTitleResourceProvider), lifeTime));
|
services.Add(new ServiceDescriptor(typeof(IXWebinarTitleResourceProvider), typeof(XWebinarTitleResourceProvider), lifeTime));
|
||||||
|
|||||||
+126
-5
@@ -1,18 +1,18 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Xml.Linq;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
using xExceptions.Constants;
|
using xExceptions.Constants;
|
||||||
using xIdentityModels.Models;
|
|
||||||
using xPushService.Base;
|
using xPushService.Base;
|
||||||
using xPushService.Extensions;
|
using xPushService.Extensions;
|
||||||
using xWebinarService.Constants;
|
using xWebinarService.Constants;
|
||||||
using xWebinarService.Models.Dtos;
|
|
||||||
using xWebinarService.Interfaces;
|
using xWebinarService.Interfaces;
|
||||||
|
using xWebinarService.Models.Entities;
|
||||||
|
|
||||||
namespace xWebinarService.Hubs
|
namespace xWebinarService.Hubs
|
||||||
{
|
{
|
||||||
@@ -21,16 +21,19 @@ namespace xWebinarService.Hubs
|
|||||||
//
|
//
|
||||||
#region Props ...
|
#region Props ...
|
||||||
public readonly IXWebinarProvider webinarProvider;
|
public readonly IXWebinarProvider webinarProvider;
|
||||||
|
private readonly IXWebinarGroupStore webinarGroupStore;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
#region Constructor ...
|
#region Constructor ...
|
||||||
public XWebinarHub(
|
public XWebinarHub(
|
||||||
ILogger<XWebinarHub> logger,
|
ILogger<XWebinarHub> logger,
|
||||||
IXWebinarProvider webinarProvider
|
IXWebinarProvider webinarProvider,
|
||||||
|
IXWebinarGroupStore webinarGroupStore
|
||||||
) : base(logger)
|
) : base(logger)
|
||||||
{
|
{
|
||||||
this.webinarProvider = webinarProvider;
|
this.webinarProvider = webinarProvider;
|
||||||
|
this.webinarGroupStore = webinarGroupStore;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -107,6 +110,35 @@ namespace xWebinarService.Hubs
|
|||||||
//
|
//
|
||||||
// Create a Group and Put User on it ...
|
// Create a Group and Put User on it ...
|
||||||
await Groups.AddToGroupAsync(connectionId, webinarId.ToString());
|
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 { }
|
catch { }
|
||||||
}
|
}
|
||||||
@@ -183,6 +215,14 @@ namespace xWebinarService.Hubs
|
|||||||
var webinarName = webinarId.ToString();
|
var webinarName = webinarId.ToString();
|
||||||
await Clients.OthersInGroup(webinarName).SendAsync(XWebinarHubAction.WebinarClosed.ToString());
|
await Clients.OthersInGroup(webinarName).SendAsync(XWebinarHubAction.WebinarClosed.ToString());
|
||||||
await Groups.RemoveFromGroupAsync(connectionId, webinarName);
|
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 { }
|
catch { }
|
||||||
}
|
}
|
||||||
@@ -266,6 +306,33 @@ namespace xWebinarService.Hubs
|
|||||||
userInfo.UserId,
|
userInfo.UserId,
|
||||||
userInfo.UserName
|
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
|
catch
|
||||||
{ }
|
{ }
|
||||||
@@ -350,11 +417,65 @@ namespace xWebinarService.Hubs
|
|||||||
userInfo.UserId,
|
userInfo.UserId,
|
||||||
userInfo.UserName
|
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
|
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>
|
/// <summary>
|
||||||
/// Send a Message to Specified Webinar ...
|
/// Send a Message to Specified Webinar ...
|
||||||
/// </summary>
|
/// </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 -->
|
<!-- Local Modules -->
|
||||||
<ItemGroup>
|
<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.xStringService" Version="1.0.0" />
|
||||||
<!-- <PackageReference Include="xDashboard.xIdentityService" Version="1.0.0" /> -->
|
<!-- <PackageReference Include="xDashboard.xIdentityService" Version="1.0.0" /> -->
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -31,8 +31,8 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="../xPushService/xPushService.csproj" />
|
<ProjectReference Include="../xPushService/xPushService.csproj" />
|
||||||
<ProjectReference Include="../xIdentityService/xIdentityService.csproj" />
|
<ProjectReference Include="../xIdentityService/xIdentityService.csproj" />
|
||||||
<!--
|
|
||||||
<ProjectReference Include="../xDataService/xDataService.csproj" />
|
<ProjectReference Include="../xDataService/xDataService.csproj" />
|
||||||
|
<!--
|
||||||
<ProjectReference Include="../xStringService/xStringService.csproj" />
|
<ProjectReference Include="../xStringService/xStringService.csproj" />
|
||||||
-->
|
-->
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user