public string GetCurrentTenancyNameOrNull()
        {
            string[] strArrays;
            if (!this._multiTenancyConfig.IsEnabled)
            {
                return("Default");
            }
            string str = this._settingManager.GetSettingValue("App.General.WebSiteRootAddress").EnsureEndsWith('/');

            if (!str.Contains("{TENANCY_NAME}"))
            {
                return(null);
            }
            if (HttpContext.Current == null || HttpContext.Current.Request.Url == null)
            {
                return(null);
            }
            if (!FormattedStringValueExtracter.IsMatch(SubdomainTenancyNameFinder.GetCurrentSiteRootAddress().EnsureEndsWith('/'), str, out strArrays, true))
            {
                return(null);
            }
            if (strArrays.Length == 0)
            {
                return(null);
            }
            return(strArrays[0]);
        }
Exemple #2
0
        public string GetCurrentTenancyNameOrNull()
        {
            if (!_multiTenancyConfig.IsEnabled)
            {
                return(Tenant.DefaultTenantName);
            }

            if (HttpContext.Current == null || HttpContext.Current.Request.Url == null)
            {
                //Can not find current URL
                return(null);
            }

            var currentRootAddress = GetCurrentSiteRootAddress().EnsureEndsWith('/');

            string[] values;
            if (!FormattedStringValueExtracter.IsMatch(currentRootAddress, WebUrlService.WebSiteRootAddress, out values, true))
            {
                return(null);
            }

            if (values.Length <= 0)
            {
                return(null);
            }

            if (string.Equals(values[0], "www", StringComparison.InvariantCultureIgnoreCase))
            {
                return(null);
            }

            return(values[0]);
        }
Exemple #3
0
        public static string[] GetValuesFromErrorMessage(this IdentityResult identityResult, IStringLocalizer localizer)
        {
            if (identityResult.Succeeded)
            {
                throw new ArgumentException(
                          "identityResult.Succeeded should be false in order to get values from error.");
            }

            if (identityResult.Errors == null)
            {
                throw new ArgumentException("identityResult.Errors should not be null.");
            }

            var error = identityResult.Errors.First();
            var key   = $"Volo.Abp.Identity:{error.Code}";

            using (CultureHelper.Use(CultureInfo.GetCultureInfo("en")))
            {
                var englishLocalizedString = localizer[key];

                if (englishLocalizedString.ResourceNotFound)
                {
                    return(Array.Empty <string>());
                }

                if (FormattedStringValueExtracter.IsMatch(error.Description, englishLocalizedString.Value,
                                                          out var values))
                {
                    return(values);
                }

                return(Array.Empty <string>());
            }
        }
Exemple #4
0
        public static string[] GetValuesFromErrorMessage(this IdentityResult identityResult, IStringLocalizer localizer)
        {
            if (identityResult.Succeeded)
            {
                throw new ArgumentException(
                          "identityResult.Succeeded should be false in order to get values from error.");
            }

            if (identityResult.Errors == null)
            {
                throw new ArgumentException("identityResult.Errors should not be null.");
            }

            var error         = identityResult.Errors.First();
            var englishString = IdentityStrings.GetOrDefault(error.Code);

            if (englishString == null)
            {
                return(Array.Empty <string>());
            }

            if (FormattedStringValueExtracter.IsMatch(error.Description, englishString, out var values))
            {
                return(values);
            }

            return(Array.Empty <string>());
        }
Exemple #5
0
        private static string LocalizeErrorMessage(string identityErrorMessage, ILocalizationSource localizationSource)
        {
            foreach (var identityLocalization in IdentityLocalizations)
            {
                string[] values;
                if (FormattedStringValueExtracter.IsMatch(identityErrorMessage, identityLocalization.Key, out values))
                {
                    return(localizationSource.GetString(identityLocalization.Value, values.Cast <object>().ToArray()));
                }
            }

            return(localizationSource.GetString("Identity.DefaultError"));
        }
        private static string LocalizeErrorMessage(string identityErrorMessage, ILocalizationManager localizationManager)
        {
            var localizationSource = localizationManager.GetSource(CodeZeroConsts.LocalizationSourceName);

            foreach (var identityLocalization in IdentityLocalizations)
            {
                if (FormattedStringValueExtracter.IsMatch(identityErrorMessage, identityLocalization.Key, out var values))
                {
                    return(localizationSource.GetString(identityLocalization.Value, values.Cast <object>().ToArray()));
                }
            }

            return(localizationSource.GetString("Identity.DefaultError"));
        }
Exemple #7
0
        public static string LocalizeErrorMessage(this IdentityError error, IStringLocalizer localizer)
        {
            var key = $"Identity.{error.Code}";

            var localizedString = localizer[key];

            if (!localizedString.ResourceNotFound)
            {
                var englishLocalizedString = localizer.WithCulture(CultureInfo.GetCultureInfo("en"))[key];
                if (!englishLocalizedString.ResourceNotFound)
                {
                    if (FormattedStringValueExtracter.IsMatch(error.Description, englishLocalizedString.Value, out var values))
                    {
                        return(string.Format(localizedString.Value, values.Cast <object>().ToArray()));
                    }
                }
            }

            return(localizer["Identity.Default"]);
        }
Exemple #8
0
        public static string LocalizeErrorMessage(this IdentityError error, IStringLocalizer localizer)
        {
            var key = $"Volo.Abp.Identity:{error.Code}";

            var localizedString = localizer[key];

            if (!localizedString.ResourceNotFound)
            {
                var englishString = IdentityStrings.GetOrDefault(error.Code);
                if (englishString != null)
                {
                    if (FormattedStringValueExtracter.IsMatch(error.Description, englishString, out var values))
                    {
                        return(string.Format(localizedString.Value, values.Cast <object>().ToArray()));
                    }
                }
            }

            return(localizer["Identity.Default"]);
        }
Exemple #9
0
        public string GetCurrentTenancyNameOrNull()
        {
            if (!_multiTenancyConfig.IsEnabled)
            {
                return(Tenant.DefaultTenantName);
            }

            var siteRootFormat = _settingManager.GetSettingValue(AppSettings.General.WebSiteRootAddress).EnsureEndsWith('/');

            if (!siteRootFormat.Contains(WebUrlService.TenancyNamePlaceHolder))
            {
                //Web site does not support subdomain tenant name
                return(null);
            }

            if (_httpContextAccessor.HttpContext == null)
            {
                //Can not find current URL
                return(null);
            }

            var currentRootAddress = GetCurrentSiteRootAddress().EnsureEndsWith('/');

            string[] values;
            if (!FormattedStringValueExtracter.IsMatch(currentRootAddress, siteRootFormat, out values, true))
            {
                return(null);
            }

            if (values.Length <= 0)
            {
                return(null);
            }

            if (string.Equals(values[0], "www", StringComparison.InvariantCultureIgnoreCase))
            {
                return(null);
            }

            return(values[0]);
        }
Exemple #10
0
        public string GetCurrentTenancyNameOrNull()
        {
            if (!_multiTenancyConfig.IsEnabled)
            {
                return(null); //Tenant.DefaultTenantName;
            }

            var siteRootFormat = _settingManager.GetSettingValue(AppSettings.General.WebSiteRootAddress).EnsureEndsWith('/');

            if (!siteRootFormat.Contains(WebUrlService.TenancyNamePlaceHolder))
            {
                //Web site does not support subdomain tenant name
                return(null);
            }

            if (HttpContext.Current == null || HttpContext.Current.Request.Url == null)
            {
                //Can not find current URL
                return(null);
            }

            var currentRootAddress = GetCurrentSiteRootAddress().EnsureEndsWith('/');

            string[] values;
            if (!FormattedStringValueExtracter.IsMatch(currentRootAddress, siteRootFormat, out values, true))
            {
                return(null);
            }

            if (values.Length <= 0)
            {
                return(null);
            }

            return(values[0]);
        }
Exemple #11
0
 public void IsMatch_Test()
 {
     string[] values;
     FormattedStringValueExtracter.IsMatch("User oğuzhan does not exist.", "User {0} does not exist.", out values).ShouldBe(true);
     values[0].ShouldBe("oğuzhan");
 }