Initial ...

This commit is contained in:
2026-03-22 14:08:25 +03:30
commit d3464ef39c
71 changed files with 19087 additions and 0 deletions
+95
View File
@@ -0,0 +1,95 @@
using System.Linq;
using Microsoft.Extensions.Logging;
using xCommons.Extensions;
using xExceptions.Constants;
using xIdentityModels.Configurations;
using xIds.Constants;
using xIds.Interfaces;
namespace xIds.Providers
{
public class XIdentityMessageProvider : IXIdentityMessageProvider
{
//
public string InviteMsg { get; set; }
public string RegistrationApproveMsg { get; set; }
public string RegisteredMsg { get; set; }
public string VerificationCodeMsg { get; set; }
public string ChangePasswordMsg { get; set; }
public string PasswordChangedMsg { get; set; }
public string NewDeviceLoggedInMsg { get; set; }
private readonly ILogger<IXIdentityMessageProvider> logger;
private readonly XIdentityConfiguration identityConfiguration;
public XIdentityMessageProvider(
ILogger<IXIdentityMessageProvider> logger,
XIdentityConfiguration identityConfiguration
)
{
this.logger = logger;
this.identityConfiguration = identityConfiguration;
}
/// <summary>
/// Determine All things is Ready or Not
/// </summary>
/// <returns></returns>
public bool IsReady()
{
return !InviteMsg.IsNullOrEmpty() &&
!RegistrationApproveMsg.IsNullOrEmpty() &&
!RegisteredMsg.IsNullOrEmpty() &&
!VerificationCodeMsg.IsNullOrEmpty() &&
!ChangePasswordMsg.IsNullOrEmpty() &&
!PasswordChangedMsg.IsNullOrEmpty() &&
!NewDeviceLoggedInMsg.IsNullOrEmpty();
}
/// <summary>
/// Retrieve a Translated Value Based on Given Lang
/// </summary>
/// <param name="resourceTitle"></param>
/// <param name="lang"></param>
/// <returns></returns>
private string GetStringResource(string resourceTitle, string lang)
{
//
var item = identityConfiguration.IdentityMessages
.FirstOrDefault(sr =>
sr.Language.ToNormalString() == lang.ToNormalString() &&
sr.ResourceTitle.ToNormalString() == resourceTitle.ToNormalString());
//
if (item == null)
{
return null;
}
//
return item.TranslatedValue;
}
/// <summary>
/// Prepare Helper Class and Fill Messages
/// with Specific Language
/// </summary>
/// <param name="lang"></param>
public void PrepareMessages(string lang)
{
//
InviteMsg = GetStringResource(IdentityMessagesKeys.InviteMsg, lang);
RegisteredMsg = GetStringResource(IdentityMessagesKeys.RegisteredMsg, lang);
ChangePasswordMsg = GetStringResource(IdentityMessagesKeys.ChangePasswordMsg, lang);
PasswordChangedMsg = GetStringResource(IdentityMessagesKeys.PasswordChangedMsg, lang);
VerificationCodeMsg = GetStringResource(IdentityMessagesKeys.VerificationCodeMsg, lang);
NewDeviceLoggedInMsg = GetStringResource(IdentityMessagesKeys.NewDeviceLoggedInMsg, lang);
RegistrationApproveMsg = GetStringResource(IdentityMessagesKeys.RegistrationApproveMsg, lang);
//
if (!IsReady())
{
XException.InvalidArgs.Throw();
}
}
}
}