public void UrlUtility_ExtractHrefFromAnchorTag_1() { var input = @"<a href='https://boo.sharepoint.com/sites/dev' target=""_blank"" otherAttribute=""other stuff"" >Blah blah blah</a>"; var output = UrlUtility.ExtractHrefFromAnchorTag(input); Assert.AreEqual("https://boo.sharepoint.com/sites/dev", output); }
public void UrlUtility_ExtractHrefFromAnchorTag_2() { var input = "https://myHost.sharepoint.com/sites/a/b/c/d"; var output = UrlUtility.ExtractHrefFromAnchorTag(input); Assert.AreEqual("https://myHost.sharepoint.com/sites/a/b/c/d", output); }
/// <summary> /// User has specified site collection. /// </summary> /// <param name="context">The context.</param> /// <param name="result">The result.</param> /// <returns></returns> private async Task AfterGetSiteCollectionUrl(IDialogContext context, IAwaitable <string> result) { var userResponse = await result; userResponse = userResponse.Trim(); // Account for Skype or other channels putting any specified URL inside an anchor tag. userResponse = UrlUtility.ExtractHrefFromAnchorTag(userResponse); var valid = false; string siteCollectionUrl = string.Empty; // User typed "last" if (Regex.IsMatch(userResponse, Constants.UtteranceRegexes.LastSiteCollectionUrl, RegexOptions.IgnoreCase)) { string prompt = Constants.Responses.LogIntoWhichSiteCollection; string lastSiteCollectionUrl = null; var lastSiteCollectionUrlPresent = context.UserData.TryGetValue <string>(Constants.StateKeys.LastLoggedInSiteCollectionUrl, out lastSiteCollectionUrl); // Last URL is present - use it. if (!string.IsNullOrEmpty(lastSiteCollectionUrl)) { valid = true; siteCollectionUrl = lastSiteCollectionUrl; } } // User didn't type "last". else { if (Regex.IsMatch(userResponse, Constants.RegexMisc.SiteCollectionUrl, RegexOptions.IgnoreCase)) { valid = true; siteCollectionUrl = userResponse; } } if (valid) { context.UserData.SetValue <string>(Constants.StateKeys.LastLoggedInSiteCollectionUrl, siteCollectionUrl); var tenantUrl = UrlUtility.GetTenantUrlFromSiteCollectionUrl(siteCollectionUrl); context.UserData.SetValue <string>(Constants.StateKeys.LastLoggedInTenantUrl, tenantUrl); await _authenticationService.ForwardToBotAuthLoginDialog(tenantUrl, context, context.Activity as IMessageActivity, AfterLogOn); } else { // TODO : Don't just quit here, instead allow X number of retries. await context.PostAsync(Constants.Responses.InvalidSiteCollectionUrl); context.Done <AuthResult>(null); } }