/// <summary> /// Searches for a match of ALL searched tags. /// </summary> /// <param name="searchText">The text we are looking</param> /// <param name="obj">The GitHubPackDetail object to search.</param> /// <returns>A boolean representing if ALL of the tags searched returned an EXACT match</returns> private static bool FoundExactTagMatchForAllTags(string searchText, object obj) { searchText = searchText.ToLower(); GitHubPackDetail packToMatch = (GitHubPackDetail)obj; // If there is a comma and multiple tags we must match all of them if (searchText.Contains(",")) { foreach (string searchTag in searchText.Split(',')) { if (!CheckForSingleTagInTagList(searchTag.Trim(), packToMatch.Tags, packToMatch.ManagementPackSystemName)) { // If any one tag is matching from the list of tags this isn't a match return(false); } } Log.WriteTrace( EventType.UIActivity, "Matched all tags on Search String", searchText); // Every tag in the search string was found in the Tags on the Pack return(true); } else { // A Single tag was in the search, perform one check. return(CheckForSingleTagInTagList(searchText, packToMatch.Tags, packToMatch.ManagementPackSystemName)); } }
/// <summary> /// Checks to see if the search text matches the Author's name /// </summary> /// <param name="searchText">The text we are looking</param> /// <param name="obj">The GitHubPackDetail object to search.</param> /// <returns>Boolean representing if the Author was a match for the search.</returns> private static bool MatchesAuthor(string searchText, object obj) { searchText = searchText.ToLower(); GitHubPackDetail packToMatch = (GitHubPackDetail)obj; return(packToMatch.Author.ToLower().Contains(searchText)); }
/// <summary> /// Checks to see if the search text matches the Display or System name of the pack. /// </summary> /// <param name="searchText">The text we are looking</param> /// <param name="obj">The GitHubPackDetail object to search.</param> /// <returns>Boolean representing if the Display or System name was a match for the search.</returns> private static bool MatchesDisplayOrSystemName(string searchText, object obj) { searchText = searchText.ToLower(); GitHubPackDetail packToMatch = (GitHubPackDetail)obj; return(packToMatch.ManagementPackDisplayName.ToLower().Contains(searchText) || packToMatch.ManagementPackSystemName.ToLower().Contains(searchText)); }
/// <summary> /// Fetches the details of a single JSON Management Pack File. /// </summary> /// <param name="detailsJsonFileLocation">The URL of the Management File to pull</param> /// <param name="readMeFileLocation">The URL of the ReadMe markdown file</param> /// <returns>A Treading Task with a CLR object representing the Pack fetched via HTTP.</returns> private async Task <GitHubPackDetail> FetchPackDetails(string detailsJsonFileLocation, string readMeFileLocation) { // Each of these tasks will include a Try/Catch, if a detail file fails we'd like to know which one try { Log.WriteTrace( EventType.ExternalDependency, "Fetching Management Pack Details", detailsJsonFileLocation); string detailsString = await gitHubHttpClient.GetStringAsync(detailsJsonFileLocation); // We'll attempt to deserialize before logging success GitHubPackDetail deserializedPackData = JsonConvert.DeserializeObject <GitHubPackDetail>(detailsString); Log.WriteTrace( EventType.ExternalDependency, "Successfully Fetched Management Pack Details", detailsString); try { deserializedPackData.ReadMeMarkdown = await gitHubHttpClient.GetStringAsync(readMeFileLocation); } catch (Exception) { // If we cannot fetch the ReadMe we will make sure the value is null and continue. deserializedPackData.ReadMeMarkdown = null; } return(deserializedPackData); } catch (Exception ex) { Log.WriteWarning( EventType.ExternalDependency, "Failed at Fetching Management Pack Details at: " + detailsJsonFileLocation, ex.Message); // If we fail to get one pack, should we throw an exception or hide it? // throw new Exception("Failed when retrieving Management Pack Details",ex); return(null); } }