private static void Test_Matched_Internal(string str, string format, params NameValue[] expectedPairs) { var result = new FormattedStringValueExtracter().Extract(str, format); result.IsMatch.ShouldBe(true); if (expectedPairs == null) { result.Matches.Count.ShouldBe(0); return; } result.Matches.Count.ShouldBe(expectedPairs.Length); for (int i = 0; i < expectedPairs.Length; i++) { var actualMatch = result.Matches[i]; var expectedPair = expectedPairs[i]; actualMatch.Name.ShouldBe(expectedPair.Name); actualMatch.Value.ShouldBe(expectedPair.Value); } }
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 (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]); }
public static string LocalizeErrorMessage(this IdentityError error, IStringLocalizer localizer) { var key = $"Volo.Abp.Identity:{error.Code}"; var localizedString = localizer[key]; if (!localizedString.ResourceNotFound) { using (CultureHelper.Use(CultureInfo.GetCultureInfo("en"))) { var englishLocalizedString = localizer[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"]); }
public static string GetSettingNameFormCacheKeyOrNull(string cacheKey) { var result = FormattedStringValueExtracter.Extract(cacheKey, CacheKeyFormat, true); return(result.IsMatch ? result.Matches.Last().Value : null); }
private void Test_Not_Matched(string str, string format) { var result = new FormattedStringValueExtracter().Extract(str, format); result.IsMatch.ShouldBe(false); }
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"); }