/// <summary> /// Sets the URL. /// </summary> public void ParseWiki() { this.WikiUrl = WikiHelper.CreateItemUri(this.Name); this.SetImageUrl(); this.SetLocation(); }
/// <summary> /// Sets the image URL. /// </summary> private void SetImageUrl() { try { this.ImageUrl = WikiHelper.GetItemImageUrl(this.Name); } catch (InvalidOperationException) { } }
/// <summary> /// Sets the location. /// </summary> private void SetLocation() { var webPage = new HtmlWeb(); HtmlDocument document = default; try { document = webPage.Load(WikiHelper.CreateItemUri(this.Name)); } catch { return; } this.SetWikiLocation(document); }
/// <summary> /// Froms the XML. /// </summary> /// <param name="element">The element.</param> /// <returns>The gem.</returns> public static Gem FromXml(XElement element) { var name = element.Attribute("nameSpec").Value; var isSupport = element.Attribute("skillId").Value.Contains(SupportValue); if (isSupport) { name += $" {SupportValue}"; } return(new Gem() { Name = name, WikiUrl = WikiHelper.CreateItemUri(name), Id = element.Attribute("skillId").Value, }); }
/// <inheriteddoc /> protected override void OnToMediaWiki(ref StringBuilder builder) { var nsFilter = this.Settings.NamespaceFilter; Regex regex = null; RegexOptions?regexOpts = null; if (nsFilter != null) { if (regexOpts.HasValue) { regex = new Regex(nsFilter, regexOpts.Value); } else { regex = new Regex(nsFilter); } } builder.AppendFormat("== {0} ==", this.ClrAssembly.FullName) .AppendLine(); // extension methods { builder.AppendLine() .AppendFormat("=== Extension methods ===") .AppendLine(); var extensionMethods = this.GetTypes() .SelectMany(t => t.GetMethods()) .Where(m => m.IsExtensionMethod); if (this.Settings.DocumentPublicMethods == false) { extensionMethods = extensionMethods.Where(m => m.ClrMember.IsPublic == false); } if (this.Settings.DocumentPrivateMethods == false) { extensionMethods = extensionMethods.Where(m => m.ClrMember.IsPublic); } if (extensionMethods.Count() > 0) { foreach (var grpMethods in extensionMethods.GroupBy(em => { var name = (em.ClrMember.Name ?? string.Empty).ToUpper().Trim(); if (name != string.Empty) { var firstLetter = name[0]; if (firstLetter >= '0' && firstLetter <= '9') { return("0 - 9"); } else if ((firstLetter >= 'A' && firstLetter <= 'Z')) { return(firstLetter.ToString()); } else if ((firstLetter >= 'Ä' && firstLetter <= 'Ü') || (firstLetter == 'ß')) { return("Ä - Ü, ß"); } } return(string.Empty); }) .OrderBy(gex => gex.Key, StringComparer.InvariantCultureIgnoreCase)) { var title = grpMethods.Key; builder.AppendFormat("==== {0} ====", title != string.Empty ? title : "#") .AppendLine(); builder.AppendLine(@"{| class=""prettytable"" style=""width:100%"""); builder.AppendLine(@"|- ! style=""width: 192px"" |'''Name''' !'''Summary''' ! style=""width: 192px"" |'''Target type''' ! style=""width: 192px"" |'''Namespace'''"); foreach (var method in grpMethods.OrderBy(t => t.ClrMember.Name, StringComparer.InvariantCultureIgnoreCase) .ThenBy(t => t.ToString(), StringComparer.InvariantCultureIgnoreCase)) { builder.AppendLine() .AppendFormat(@"|- |[[{0}]] |{1} |{2} |{3} ", WikiHelper.ToTableCellValue(method.DisplayName) , WikiHelper.ToTableCellValue((WikiHelper.ToWikiMarkup(method.Summary) ?? string.Empty).Trim()) , WikiHelper.ToTableCellValue(method.ExtensionMethodTargetType.FullDisplayName) , WikiHelper.ToTableCellValue(method.ClrMember.DeclaringType.Namespace)); } builder.AppendLine() .AppendLine(@"|}"); } } } // types { builder.AppendLine() .AppendFormat("=== Types ===") .AppendLine(); foreach (var grpTypes in this.GetTypes() .Where(t => regex == null || regex.IsMatch(t.ClrType.Namespace ?? string.Empty)) .GroupBy(t => (t.ClrType.Namespace ?? string.Empty).Trim()) .OrderBy(t => t.Key, StringComparer.InvariantCultureIgnoreCase)) { var @namespace = grpTypes.Key; IEnumerable <TypeDocumentation> typesToList = grpTypes.ToArray(); if (this.Settings.DocumentPublicTypes == false) { typesToList = typesToList.Where(t => t.ClrType.IsPublic == false); } if (this.Settings.DocumentPrivateTypes == false) { typesToList = typesToList.Where(t => t.ClrType.IsPublic); } if (typesToList.Count() < 1) { continue; } builder.AppendLine(); builder.AppendFormat("==== {0} ====", @namespace != string.Empty ? @namespace : "(no namespace)") .AppendLine(); builder.AppendLine(@"{| class=""prettytable"" style=""width:100%"""); builder.AppendLine(@"|- ! style=""width: 192px"" |'''Name''' !'''Summary'''"); foreach (var type in typesToList.OrderBy(t => t.ClrType.Name, StringComparer.InvariantCultureIgnoreCase)) { builder.AppendLine() .AppendFormat(@"|- |[[{0}]] |{1} ", WikiHelper.ToTableCellValue(type.ClrType.Name) , (WikiHelper.ToWikiMarkup(type.Summary) ?? string.Empty).Trim()); } builder.AppendLine() .AppendLine(@"|}"); } } }
private ComposeExtensionResponse GetComposeExtensionResponse(Activity activity) { ComposeExtensionResponse composeExtensionResponse = null; ImageResult imageResult = null; List <ComposeExtensionAttachment> lstComposeExtensionAttachment = new List <ComposeExtensionAttachment>(); StateClient stateClient = activity.GetStateClient(); BotData userData = stateClient.BotState.GetUserData(activity.ChannelId, activity.From.Id); bool IsSettingUrl = false; var composeExtensionQuery = activity.GetComposeExtensionQueryData(); if (string.Equals(activity.Name.ToLower(), Strings.ComposeExtensionQuerySettingUrl)) { IsSettingUrl = true; } if (composeExtensionQuery.CommandId == null || composeExtensionQuery.Parameters == null) { return(null); } var initialRunParameter = WikiHelper.GetQueryParameterByName(composeExtensionQuery, Strings.manifestInitialRun); var queryParameter = WikiHelper.GetQueryParameterByName(composeExtensionQuery, Strings.manifestParameterName); if (userData == null) { composeExtensionResponse = new ComposeExtensionResponse(); string message = Strings.ComposeExtensionNoUserData; composeExtensionResponse.ComposeExtension = WikiHelper.GetMessageResponseResult(message); return(composeExtensionResponse); } /** * Below are the checks for various states that may occur * Note that the order of many of these blocks of code do matter */ // situation where the incoming payload was received from the config popup if (!string.IsNullOrEmpty(composeExtensionQuery.State)) { WikiHelper.ParseSettingsAndSave(composeExtensionQuery.State, userData, stateClient, activity); /** * //// need to keep going to return a response so do not return here * //// these variables are changed so if the word 'setting' kicked off the compose extension, * //// then the word setting will not retrigger the config experience **/ queryParameter = ""; initialRunParameter = "true"; } // this is a sitaution where the user's preferences have not been set up yet if (string.IsNullOrEmpty(userData.GetProperty <string>(Strings.ComposeExtensionCardTypeKeyword))) { composeExtensionResponse = WikiHelper.GetConfig(composeExtensionResponse); return(composeExtensionResponse); } /** * // this is the situation where the user has entered the word 'reset' and wants * // to clear his/her settings * // resetKeyword for English is "reset" **/ if (string.Equals(queryParameter.ToLower(), Strings.ComposeExtensionResetKeyword)) { //make the userData null userData = null; composeExtensionResponse = new ComposeExtensionResponse(); composeExtensionResponse.ComposeExtension = WikiHelper.GetMessageResponseResult(Strings.ComposeExtensionResetText); return(composeExtensionResponse); } /** * // this is the situation where the user has entered "setting" or "settings" in order * // to repromt the config experience * // keywords for English are "setting" and "settings" **/ if ((string.Equals(queryParameter.ToLower(), Strings.ComposeExtensionSettingKeyword) || string.Equals(queryParameter.ToLower(), Strings.ComposeExtensionSettingsKeyword)) || (IsSettingUrl)) { composeExtensionResponse = WikiHelper.GetConfig(composeExtensionResponse); return(composeExtensionResponse); } /** * // this is the situation where the user in on the initial run of the compose extension * // e.g. when the user first goes to the compose extension and the search bar is still blank * // in order to get the compose extension to run the initial run, the setting "initialRun": true * // must be set in the manifest for the compose extension **/ if (initialRunParameter == "true") { //Signin Experience, please uncomment below code for Signin Experience //composeExtensionResponse = WikiHelper.GetSignin(composeExtensionResponse); //return composeExtensionResponse; composeExtensionResponse = new ComposeExtensionResponse(); composeExtensionResponse.ComposeExtension = WikiHelper.GetMessageResponseResult(Strings.ComposeExtensionInitialRunText); return(composeExtensionResponse); } /** * * Below here is simply the logic to call the Wikipedia API and create the response for * * a query; the general flow is to call the Wikipedia API for the query and then call the * * Wikipedia API for each entry for the query to see if that entry has an image; in order * * to get the asynchronous sections handled, an array of Promises for cards is used; each * * Promise is resolved when it is discovered if an image exists for that entry; once all * * of the Promises are resolved, the response is sent back to Teams * */ WikiResult wikiResult = WikiHelper.SearchWiki(queryParameter, composeExtensionQuery); // enumerate search results and build Promises for cards for response foreach (var searchResult in wikiResult.query.search) { //Get the Image result on the basis of Image Title one by one imageResult = WikiHelper.SearchWikiImage(searchResult); //Get the Image Url from imageResult string imageUrl = WikiHelper.GetImageURL(imageResult); //Set the Highlighter title string highlightedTitle = WikiHelper.GetHighLightedTitle(searchResult.title, queryParameter); string cardText = searchResult.snippet + " ..."; // create the card itself and the preview card based upon the information // check user preference for which type of card to create lstComposeExtensionAttachment.Add(TemplateUtility.CreateComposeExtensionCardsAttachments(highlightedTitle, cardText, imageUrl, userData.GetProperty <string>(Strings.ComposeExtensionCardTypeKeyword))); } composeExtensionResponse = WikiHelper.GetComposeExtenionQueryResult(composeExtensionResponse, lstComposeExtensionAttachment); return(composeExtensionResponse); }