private static IReadOnlyList <ErrorCode> GetErrorCodes(CommandLineOptions options) { using (var client = new HttpClient()) { var enumMembers = GetErrorCodeEnumMembers(client); var warningLevels = GetWarningLevels(client); var messages = GetResourceDictionary(client); var docLinks = GetDocumentationLinks(client, options); var docDetails = GetDocDetails(client, docLinks.Keys, options); string GetMessage(string name) => messages.GetValueOrDefault(name, "").Trim().TrimEnd('.').TrimEnd(); int GetWarningLevel(string name) => warningLevels.GetValueOrDefault(name); string GetDocLink(int value) => docLinks.TryGetValue(value, out var link) ? link : ""; string GetDetails(int value) => docDetails.TryGetValue(value, out var link) ? link : ""; var errorCodes = enumMembers .Select(m => ErrorCode.Create(m, GetMessage, GetWarningLevel, GetDocLink, GetDetails)) .ToList(); return(errorCodes); } }
private static async Task <IReadOnlyList <ErrorCode> > GetErrorCodesAsync(CommandLineOptions options) { using var client = new HttpClient(); var enumMembers = await GetErrorCodeEnumMembersAsync(client, options.BranchOrTag); var messages = await GetResourceDictionaryAsync(client, options.BranchOrTag); var docRelativeUris = options.IncludeLinks ? await GetDocRelativeUrisAsync(client) : null; string GetMessage(string name) => messages.TryGetValue(name, out var msg) ? msg : ""; var docBaseUri = new Uri(DocBaseUrl); Uri GetDocLink(int value) { if (options.IncludeLinks) { var link = docRelativeUris.TryGetValue(value, out var relativeUrl) ? new KnownGoodUri(docBaseUri, relativeUrl) : new Uri(string.Format(DocUrlTemplateFallback, value)); return(link); } return(null); } var errorCodes = new List <ErrorCode>(); foreach (var m in enumMembers) { errorCodes.Add(ErrorCode.Create(m, GetMessage, GetDocLink)); } return(errorCodes); }