private void UpdateCountryCacheSource(AreaCache country) { var baseUrl = country.URL; var source = GetSourceCode(baseUrl); var match = Regex.Match(source, Filters.Country.filter1, RegexOptions.Singleline); if (!match.Success) { return; } var type = "province"; var matches = Regex.Matches(match.Groups["sub"]?.Value, Filters.Country.filter2); var subAreas = matches .OfType <Match>() .Select(item => new AreaCache( item.Groups["name"]?.Value, baseUrl + item.Groups["uri"].Value) { ID = item.Groups["id"]?.Value, Type = type }) .ToArray(); foreach (var item in subAreas) { UpdateSubAreaCacheSource(item); } country.AddRange(subAreas); }
private void UpdateSubAreaCacheSource(AreaCache area) { if (area == null) { return; } var baseUrl = area.URL; var source = GetSourceCode(baseUrl); var match = Regex.Match(source, Filters.SubArea.filter1, RegexOptions.Singleline); if (!match.Success) { return; } var type = match.Groups["type"]?.Value; var matches = Regex.Matches(match.Groups["sub"]?.Value, Filters.SubArea.filter2); var subAreas = matches .OfType <Match>() .Select(item => new AreaCache( name: item.Groups["name"]?.Value, url: CombineUrl(baseUrl, item.Groups["uri"]?.Value)) { ID = item.Groups["id"]?.Value, Type = type }) .ToArray(); foreach (var item in subAreas .Where(item => !string.IsNullOrWhiteSpace(item.URL))) { UpdateSubAreaCacheSource(item); } area.AddRange(subAreas); }
public Area GetChinaArea() { var data = chinaCountryAreaData; if (data == null) { var chinaCountryCache = new AreaCache( name: "中国", url: $@"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/{DateTime.Now.Year - 1}/") { ID = "0", Type = "country" }; UpdateCountryCacheSource(chinaCountryCache); data = chinaCountryCache.ToData(); chinaCountryAreaData = data; } return(data); }