Backup and Clean Push Service and implement new Structure of Push Service ...

This commit is contained in:
2025-11-14 16:40:45 +03:30
parent cfcb2d12b4
commit 3bd4b8d562
40 changed files with 333 additions and 2560 deletions
+199
View File
@@ -0,0 +1,199 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.SignalR;
using xCommons.Constants;
using xCommons.Extensions;
using xCommons.Helpers;
using xIdentityModels.Constants;
using xPushService.Models;
namespace xPushService.Extensions
{
public static class ClaimsPrincipalExtensions
{
/// <summary>
/// Generate User Info based on HubCallerContext ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static XHubUserInfo GetUserInfo(this HubCallerContext source)
{
//
XHubUserInfo result = null;
//
if (source.IsNull() || source.User.IsNull() || !source.User.Claims.HasChild())
{
return result;
}
//
result = new XHubUserInfo
{
UserId = source.User.Claims.FirstOrDefault(c => c.Type == XCustomClaims.UserId)?.Value ?? "",
UserName = source.User.Claims.FirstOrDefault(c => c.Type == XCustomClaims.UserName)?.Value ?? "",
FirstName = source.User.Claims.FirstOrDefault(c => c.Type == XCustomClaims.FirstName)?.Value ?? "",
LastName = source.User.Claims.FirstOrDefault(c => c.Type == XCustomClaims.LastName)?.Value ?? "",
Picture = source.User.Claims.FirstOrDefault(c => c.Type == XCustomClaims.Picture)?.Value ?? "",
Email = source.User.Claims.FirstOrDefault(c => c.Type == XCustomClaims.Email)?.Value ?? null,
PhoneNumber = source.User.Claims.FirstOrDefault(c => c.Type == XCustomClaims.PhoneNumber)?.Value ?? null,
};
//
#region Handle Gender ...
var genders = ObjectHelper.ToEnumerableKeys<XGender>();
var genderStr = source.User.Claims.FirstOrDefault(c => c.Type == XCustomClaims.Gender).Value ?? null;
if (genderStr.IsNullOrEmpty())
{
result.Gender = XGender.Male;
}
else
{
result.Gender = genderStr.GetValue<XGender>();
}
#endregion
//
#region Handle IsBanned ...
var isBannedStr = source.User.Claims.FirstOrDefault(c => c.Type == XCustomClaims.IsBanned).Value ?? null;
if (isBannedStr.IsNullOrEmpty())
{
result.IsBanned = false;
}
else
{
//
var isBanned = false;
Boolean.TryParse(isBannedStr, out isBanned);
//
result.IsBanned = isBanned;
}
#endregion
//
#region Handle IsEnabled ...
var isEnabledStr = source.User.Claims.FirstOrDefault(c => c.Type == XCustomClaims.IsEnabled).Value ?? null;
if (isEnabledStr.IsNullOrEmpty())
{
result.IsEnabled = false;
}
else
{
//
var isEnabled = false;
Boolean.TryParse(isEnabledStr, out isEnabled);
//
result.IsEnabled = isEnabled;
}
#endregion
//
#region Handle Email Confirmed ...
var emailConfirmedStr = source.User.Claims.FirstOrDefault(c => c.Type == XCustomClaims.EmailVerified).Value ?? null;
if (emailConfirmedStr.IsNullOrEmpty())
{
result.EmailConfirmed = false;
}
else
{
//
var emailConfirmed = false;
Boolean.TryParse(emailConfirmedStr, out emailConfirmed);
//
result.EmailConfirmed = emailConfirmed;
}
#endregion
//
#region Handle PhoneNumber Confirmed ...
var phoneNumberConfirmedStr = source.User.Claims.FirstOrDefault(c => c.Type == XCustomClaims.PhoneNumberVerified).Value ?? null;
if (phoneNumberConfirmedStr.IsNullOrEmpty())
{
result.PhoneNumberConfirmed = false;
}
else
{
//
var phoneNumberConfirmed = false;
Boolean.TryParse(phoneNumberConfirmedStr, out phoneNumberConfirmed);
//
result.PhoneNumberConfirmed = phoneNumberConfirmed;
}
#endregion
//
#region Handle ExpiredOn ...
var expiredOnStr = source.User.Claims.FirstOrDefault(c => c.Type == XCustomClaims.ExpiredOn).Value ?? null;
if (expiredOnStr.IsNullOrEmpty())
{
result.ExpiredOn = null;
}
else
{
//
long expiredOn = 0;
long.TryParse(expiredOnStr, out expiredOn);
//
result.ExpiredOn = expiredOn;
}
#endregion
//
#region Handle AuthenticatedOn ...
var authenticatedOnStr = source.User.Claims.FirstOrDefault(c => c.Type == XCustomClaims.AuthenticatedOn).Value ?? null;
if (authenticatedOnStr.IsNullOrEmpty())
{
result.AuthenticatedOn = null;
}
else
{
//
long authenticatedOn = 0;
long.TryParse(authenticatedOnStr, out authenticatedOn);
//
result.AuthenticatedOn = authenticatedOn;
}
#endregion
//
#region Handle BrithDate ...
var brithDateStr = source.User.Claims.FirstOrDefault(c => c.Type == XCustomClaims.BrithDate)?.Value ?? "";
if (brithDateStr.IsNullOrEmpty())
{
// BrithDate = null;
}
else
{
//
DateTime bDate;
DateTime.TryParse(brithDateStr, out bDate);
//
result.BrithDate = bDate;
}
#endregion
//
result.Issuers = source.User.Claims.Where(c => c.Type == XCustomClaims.Issuer)?
.Select(c => c.Value) ?? new HashSet<string>();
result.Audiences = source.User.Claims.Where(c => c.Type == XCustomClaims.Audience)?
.Select(c => c.Value) ?? new HashSet<string>();
result.ClientIds = source.User.Claims.Where(c => c.Type == XCustomClaims.ClientId)?
.Select(c => c.Value) ?? new HashSet<string>();
result.Scopes = source.User.Claims.Where(c => c.Type == XCustomClaims.Scope)?
.Select(c => c.Value) ?? new HashSet<string>();
result.Roles = source.User.Claims.Where(c => c.Type == XCustomClaims.Role)?
.Select(c => c.Value) ?? new HashSet<string>();
//
return result;
}
}
}
-157
View File
@@ -1,157 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using xCommons.Extensions;
using xPushService.Models;
namespace xPushService.Extensions {
public static class XWebRTCConnectionExtensions {
/// <summary>
/// Validate Connection ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static bool IsValid (this XWebRTCConnectionDto source) {
//
var result = false;
result = !source
.IsNull () && !source.CallerConnectionId
.IsNullOrEmpty () && (
source.Callees
.HasChild () ? source.Callees
.All (callee => !callee.ConnectionId.IsNullOrDefault ()) :
true
);
//
return result;
}
/// <summary>
/// Check a ConnectionId is Caller of a connection ...
/// </summary>
/// <param name="source"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
public static bool IsCaller (
this XWebRTCConnectionDto source,
string connectionId
) {
//
var result = false;
//
// Validate Args ...
if (!source.IsValid () ||
connectionId.IsNullOrEmpty ()
) {
return result;
}
//
result = connectionId
.ToNormalString () == source.CallerConnectionId
.ToNormalString ();
return result;
}
/// <summary>
/// Check a ConnectionId is in Callees of a connection ...
/// </summary>
/// <param name="source"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
public static bool IsInCallees (
this XWebRTCConnectionDto source,
string connectionId
) {
//
var result = false;
//
// Validate Args ...
if (!source.IsValid () ||
!source.Callees.HasChild () ||
connectionId.IsNullOrEmpty ()
) {
return result;
}
//
result = source.Callees.Any (callee => callee.ConnectionId
.ToNormalString () == connectionId
.ToNormalString ());
//
return result;
}
/// <summary>
/// Get Receivers ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static IReadOnlyList<string> GetReceivers (this XWebRTCConnectionDto source) {
//
var result = new List<string> ();
//
// Validate Args ...
if (!source.IsValid ()) {
return result;
}
//
// Add Caller ...
result.Add (source.CallerConnectionId);
//
// Add Callees ...
source.Callees
.ToList ()
.ForEach (callee => {
result.Add (callee.ConnectionId);
});
//
return result;
}
/// <summary>
/// Retrieve Callee from Callees ...
/// </summary>
/// <param name="source"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
public static XWebRTCCalleeDto GetCallee (
this XWebRTCConnectionDto source,
string connectionId
) {
//
// Validate Args ...
if (!source.IsValid () ||
connectionId.IsNullOrEmpty ()
) {
return null;
}
//
// Check Connection Id is In Callees or not ...
var isInCallees = source.IsInCallees (connectionId);
if (!isInCallees) {
return null;
}
//
// retrieve result ...
var result = source.Callees
.FirstOrDefault (callee => callee.ConnectionId
.ToNormalString () == connectionId
.ToNormalString ()
);
//
// return result ...
return result;
}
}
}