Compare commits

...
10 Commits
Author SHA1 Message Date
saherelm d89acf612c last ... 2026-11-27 19:21:23 +03:30
saherelm 2970815270 last ... 2026-11-26 19:37:01 +03:30
saherelm 6757b2eaf6 last works on KeyedServices Feature ... 2026-11-24 10:44:27 +03:30
saherelm e2de55e8ef last works on Keyed Services ... 2026-11-24 08:25:21 +03:30
saherelm d5da835b71 add Support for XKeyedService ... 2026-11-23 16:33:11 +03:30
saherelm 939366fbb4 last ... 2026-11-16 23:11:57 +03:30
saherelm d1f940c44b Update App Configurations ... 2026-11-15 21:25:57 +03:30
saherelm a9f92c751f Fix IsExpired TTL Extensions Method ... 2026-11-13 19:00:02 +03:30
saherelm 61d8ad831e last ... 2026-11-13 13:48:10 +03:30
saherelm 5e31f8f99a add extensions method ... 2026-11-12 23:48:33 +03:30
8 changed files with 1274 additions and 88 deletions
+8 -4
View File
@@ -1,21 +1,25 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace xCommons.Configurations { namespace xCommons.Configurations
{
/// <summary> /// <summary>
/// represent an xBackend Application /// represent an xBackend Application
/// </summary> /// </summary>
public partial class XAppConfiguration { public partial class XAppConfiguration
{
public string Name { get; set; } public string Name { get; set; }
public string Version { get; set; } public string Version { get; set; }
public string Environment { get; set; } public string Environment { get; set; }
public string XPoweredValue { get; set; } public string XPoweredValue { get; set; }
public IEnumerable<string> AllowedOrigins { get; set; }
public string WelcomeMessage { get; set; } public string WelcomeMessage { get; set; }
public string DefaultLanguage { get; set; } public string DefaultLanguage { get; set; }
public int DefaultCacheTtlMinutes { get; set; } = 15;
public IEnumerable<string> AllowedOrigins { get; set; }
public XMessageResourceTitles MessageResourceTitles { get; set; } public XMessageResourceTitles MessageResourceTitles { get; set; }
} }
public partial class XMessageResourceTitles { public partial class XMessageResourceTitles
{
public string Terms { get; set; } public string Terms { get; set; }
public string Invite { get; set; } public string Invite { get; set; }
public string RegistrationApprove { get; set; } public string RegistrationApprove { get; set; }
+136 -3
View File
@@ -21,6 +21,7 @@ using System.Security.Cryptography;
using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Serialization;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using xCommons.Configurations;
namespace xCommons.Extensions namespace xCommons.Extensions
{ {
@@ -974,7 +975,7 @@ namespace xCommons.Extensions
result.Add(updateWith); result.Add(updateWith);
// //
return source; return result;
} }
/// <summary> /// <summary>
@@ -1012,7 +1013,7 @@ namespace xCommons.Extensions
result.Add(updateWith); result.Add(updateWith);
// //
return source; return result;
} }
/// <summary> /// <summary>
@@ -1050,7 +1051,27 @@ namespace xCommons.Extensions
result.Add(updateWith); result.Add(updateWith);
// //
return source; return result;
}
/// <summary>
/// Converts an Enumerable to HashSet ...
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <returns></returns>
public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source)
{
//
var result = new HashSet<T>();
if (source.IsNull())
{
return result;
}
//
result = [.. source];
return result;
} }
/// <summary> /// <summary>
@@ -1628,6 +1649,26 @@ namespace xCommons.Extensions
return time.IsExPired(); return time.IsExPired();
} }
/// <summary>
/// Check Specified Time is Expired or not ...
/// </summary>
/// <param name="source"></param>
/// <param name="ttlSeconds"></param>
/// <returns></returns>
public static bool IsExpiredTTL(
this DateTime source,
int ttlSeconds
)
{
//
var now = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
var result = now < new DateTimeOffset(source)
.ToUnixTimeSeconds() + ttlSeconds;
//
return result;
}
/// <summary> /// <summary>
/// Determines a File Type is Image Kind or not /// Determines a File Type is Image Kind or not
/// </summary> /// </summary>
@@ -1800,6 +1841,65 @@ namespace xCommons.Extensions
return result; return result;
} }
/// <summary>
/// Extract RateLimit Rule based on given Path ...
/// </summary>
/// <param name="source"></param>
/// <param name="path"></param>
/// <returns></returns>
public static XRateLimitRule GetMatchingRule(
this XRateLimitConfiguration source,
string path
)
{
//
if (!source.Enabled)
{
return null;
}
//
var normalizedPath = path.IsNullOrEmpty()
? "/"
: path.ToNormalString();
//
var rule = source.Rules.IsNull()
? null
: source.Rules
.Where(r =>
!r.IsNull() &&
r.Enabled &&
!r.PathPrefix.IsNullOrEmpty() &&
normalizedPath.StartsWith(r.PathPrefix.ToNormalString()))
.OrderByDescending(r => r.PathPrefix.Length)
.FirstOrDefault();
//
if (!rule.IsNull())
{
return rule;
}
//
if (source.ApplyToAllRoutes)
{
//
return new XRateLimitRule
{
Enabled = true,
Name = "Default",
PathPrefix = "/",
Limit = source.DefaultLimit,
KeyMode = source.DefaultKeyMode,
PeriodSeconds = source.DefaultPeriodSeconds,
};
}
//
return null;
}
// //
#region Int Id Extensions ... #region Int Id Extensions ...
public static bool IsValidIntId(this int source) public static bool IsValidIntId(this int source)
@@ -1905,6 +2005,39 @@ namespace xCommons.Extensions
return Convert.ToBase64String(hash); return Convert.ToBase64String(hash);
} }
} }
/// <summary>
/// Apply Templates on provided String ...
/// </summary>
/// <param name="source"></param>
/// <param name="templates"></param>
/// <returns></returns>
public static string ApplyTemplates(
this string source,
IDictionary<string, string> templates = null
)
{
//
// Validate ...
if (source.IsNullOrEmpty() ||
!templates.HasChild())
{
return source;
}
//
var existsTemplates = templates.Where(
x => source.Contains(x.Key)
);
var result = source;
foreach (var template in existsTemplates)
{
result = result.Replace(template.Key, template.Value);
}
//
return result;
}
#endregion #endregion
// //
+14 -1
View File
@@ -5,6 +5,7 @@ using xCommons.Filters;
using xCommons.Constants; using xCommons.Constants;
using xCommons.Providers; using xCommons.Providers;
using xCommons.Interfaces; using xCommons.Interfaces;
using xExceptions.Constants;
using xCommons.Configurations; using xCommons.Configurations;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
@@ -14,7 +15,6 @@ using Swashbuckle.AspNetCore.SwaggerUI;
using Swashbuckle.AspNetCore.SwaggerGen; using Swashbuckle.AspNetCore.SwaggerGen;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using xExceptions.Constants;
namespace xCommons.Extensions namespace xCommons.Extensions
{ {
@@ -33,6 +33,19 @@ namespace xCommons.Extensions
return serviceProvider.GetService<T>(); return serviceProvider.GetService<T>();
} }
/// <summary>
/// Inject Specific Registered Services from IServiceCollection
/// </summary>
/// <param name="source"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static IEnumerable<T> GetRegisteredServices<T>(this IServiceCollection source)
{
//
var serviceProvider = source.BuildServiceProvider();
return serviceProvider.GetServices<T>();
}
/// <summary> /// <summary>
/// Register App Configuration as a Service /// Register App Configuration as a Service
/// </summary> /// </summary>
+3
View File
@@ -63,6 +63,9 @@ namespace xCommons.Extensions {
// //
var idContainer = parts[0]; var idContainer = parts[0];
var messageContainer = parts[1]; var messageContainer = parts[1];
//
// TODO: Fix this ...
} }
// //
+5
View File
@@ -19,9 +19,14 @@ namespace xCommons.Extensions
var xMessageResourceTitlesConfigSection = source var xMessageResourceTitlesConfigSection = source
.GetSection(ConfigurationNodeNames.MESSAGE_RESOURCE_TITLES_NODE); .GetSection(ConfigurationNodeNames.MESSAGE_RESOURCE_TITLES_NODE);
//
// Read TTL ...
int.TryParse(source[nameof(XAppConfiguration.DefaultCacheTtlMinutes)], out int defTTL);
// //
var result = new XAppConfiguration var result = new XAppConfiguration
{ {
DefaultCacheTtlMinutes = defTTL,
Name = source[nameof(XAppConfiguration.Name)], Name = source[nameof(XAppConfiguration.Name)],
Version = source[nameof(XAppConfiguration.Version)], Version = source[nameof(XAppConfiguration.Version)],
XPoweredValue = source[nameof(XAppConfiguration.XPoweredValue)], XPoweredValue = source[nameof(XAppConfiguration.XPoweredValue)],
-67
View File
@@ -1,67 +0,0 @@
using System.Linq;
using xCommons.Configurations;
namespace xCommons.Extensions
{
public static class XCommonsExtensions
{
/// <summary>
/// Extract RateLimit Rule based on given Path ...
/// </summary>
/// <param name="source"></param>
/// <param name="path"></param>
/// <returns></returns>
public static XRateLimitRule GetMatchingRule(
this XRateLimitConfiguration source,
string path
)
{
//
if (!source.Enabled)
{
return null;
}
//
var normalizedPath = path.IsNullOrEmpty()
? "/"
: path.ToNormalString();
//
var rule = source.Rules.IsNull()
? null
: source.Rules
.Where(r =>
!r.IsNull() &&
r.Enabled &&
!r.PathPrefix.IsNullOrEmpty() &&
normalizedPath.StartsWith(r.PathPrefix.ToNormalString()))
.OrderByDescending(r => r.PathPrefix.Length)
.FirstOrDefault();
//
if (!rule.IsNull())
{
return rule;
}
//
if (source.ApplyToAllRoutes)
{
//
return new XRateLimitRule
{
Enabled = true,
Name = "Default",
PathPrefix = "/",
Limit = source.DefaultLimit,
KeyMode = source.DefaultKeyMode,
PeriodSeconds = source.DefaultPeriodSeconds,
};
}
//
return null;
}
}
}
File diff suppressed because it is too large Load Diff
-13
View File
@@ -1,13 +0,0 @@
using System;
namespace xCommons.Helpers {
public partial class XDateHelper {
/// <summary>
/// retrieve utc now timestam unix like representation ...
/// </summary>
/// <returns></returns>
public static long UtcNowTimespan () {
return DateTimeOffset.UtcNow.ToUnixTimeMilliseconds ();
}
}
}