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:
+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>
|
||||
|
||||
Reference in New Issue
Block a user