コード例 #1
0
        private async Task <DiscoveredPlace[]> DiscoverOnFoursquareForExploring(IReadOnlyList <KmlPlacemark> placemarks, string language, IDiscoveringProgress progressTracker, CancellationToken cancellationToken)
        {
            var result = new ConcurrentBag <DiscoveredPlace>();

            var placemarksToExplore = new List <KmlPlacemark> {
                placemarks.First()
            };

            foreach (var placemark in placemarks.Skip(1))
            {
                if (!placemarksToExplore.Any(p => _kmlCalculator.GetDistanceInMeters(p, placemark) < EXPLORE_ON_PLACEMARKS_AFTER_METERS))
                {
                    placemarksToExplore.Add(placemark);
                }
                else
                {
                    progressTracker.ReportItemProcessed();
                }
            }

            await placemarksToExplore.ForEachAsync(DEGREE_OF_PARALLELISM_PER_SERVICE, async (placemark) =>
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                var venues = await _foursquare.ExplorePopular(placemark, language, cancellationToken);
                if (venues != null)
                {
                    foreach (var venue in venues)
                    {
                        if (placemarks.Any(p => p.Name.Equals(venue.Title, StringComparison.OrdinalIgnoreCase)))
                        {
                            continue;
                        }

                        result.Add(new DiscoveredPlace
                        {
                            Venue = venue
                        });
                        _logger.Info($"Explored a recommended venue on Foursquare: {venue.Title}");
                    }
                }

                progressTracker.ReportItemProcessed();
            });

            return(result.ToArray());
        }
コード例 #2
0
        public virtual async Task <List <DiscoveredPlace> > DiscoverOnHere(IEnumerable <KmlPlacemark> placemarks, string language, IDiscoveringProgress progressTracker, CancellationToken cancellationToken)
        {
            var result = new ConcurrentBag <DiscoveredPlace>();

            await placemarks.ForEachAsync(DEGREE_OF_PARALLELISM_PER_SERVICE, async (placemark) => {
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                var venue = await _here.LookupMatchingVenue(placemark, language, cancellationToken);
                if (venue != null)
                {
                    result.Add(new DiscoveredPlace {
                        Venue = venue,
                        AttachedToPlacemark = placemark
                    });
                    _logger.Info($"Found a matching venue on HERE: {venue.Title}");
                }

                progressTracker.ReportItemProcessed();
            });

            return(result
                   .GroupBy(x => x.Venue.Id)
                   .Select(x => x.FirstOrDefault(dp => dp.IsForPlacemark) ?? x.First())
                   .ToList());
        }
コード例 #3
0
        private async Task <DiscoveredPlace[]> DiscoverOnFoursquareForMatching(IEnumerable <KmlPlacemark> placemarks, string language, IDiscoveringProgress progressTracker, CancellationToken cancellationToken)
        {
            var result = new ConcurrentBag <DiscoveredPlace>();

            await placemarks.ForEachAsync(DEGREE_OF_PARALLELISM_PER_SERVICE, async (placemark) =>
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                var venue = await _foursquare.LookupMatchingVenue(placemark, language, cancellationToken);
                if (venue != null)
                {
                    result.Add(new DiscoveredPlace
                    {
                        Venue = venue,
                        AttachedToPlacemark = placemark
                    });
                    _logger.Info($"Found a matching venue on Foursquare: {venue.Title}");
                }

                progressTracker.ReportItemProcessed();
            });

            return(result.ToArray());
        }