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 logger; private readonly XIdentityConfiguration identityConfiguration; public XIdentityMessageProvider( ILogger logger, XIdentityConfiguration identityConfiguration ) { this.logger = logger; this.identityConfiguration = identityConfiguration; } /// /// Determine All things is Ready or Not /// /// public bool IsReady() { return !InviteMsg.IsNullOrEmpty() && !RegistrationApproveMsg.IsNullOrEmpty() && !RegisteredMsg.IsNullOrEmpty() && !VerificationCodeMsg.IsNullOrEmpty() && !ChangePasswordMsg.IsNullOrEmpty() && !PasswordChangedMsg.IsNullOrEmpty() && !NewDeviceLoggedInMsg.IsNullOrEmpty(); } /// /// Retrieve a Translated Value Based on Given Lang /// /// /// /// 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; } /// /// Prepare Helper Class and Fill Messages /// with Specific Language /// /// 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(); } } } }