Пример #1
0
        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);
        }
Пример #2
0
        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);
        }