public void BarDataModel_RemoveDuplicates_RemoveBarContainingOthersTitle(string name1, string name2)
        {
            // Arrange
            var barData = new BarDataModel();

            barData.Add(new BarData {
                Title = name1
            });
            barData.Add(new BarData {
                Title = name2
            });
            // Act
            barData.RemoveDuplicates();
            // Assert
            Assert.AreEqual(1, barData.Count);
        }
        [TestCase("test1ng", 0.0, 0.0, "1TESTing", 10.0, 10.0)] // same name as in RemoveSimilarBarsNear, with different coordinates
        public void BarDataModel_RemoveDuplicates_DoNotRemoveSimilarBarsFar(string name1, double lat1, double lon1,
                                                                            string name2, double lat2, double lon2)
        {
            // Arrange
            var barData = new BarDataModel();

            barData.Add(new BarData {
                Title = name1, Latitude = lat1, Longitude = lon1
            });
            barData.Add(new BarData {
                Title = name2, Latitude = lat2, Longitude = lon2
            });
            // Act
            barData.RemoveDuplicates();
            // Assert
            Assert.AreEqual(2, barData.Count);
        }
Exemple #3
0
        public static async Task <BarDataModel> RequestBarsAroundCoords(double latitude, double longitude, double radius)
        {
            var result = new BarDataModel();
            var failedToConnectCounter = 0;
            var providerCount          = _providerList.Count;

            foreach (IBeerable provider in _providerList)
            {
                try
                {
                    var barsFromProvider = await CollectBarsFromProvider(provider, latitude, longitude, radius);

                    if (barsFromProvider != null)
                    {
                        result.AddRange(barsFromProvider);
                    }
                }
                catch (HttpRequestException)
                {
                    if (++failedToConnectCounter == providerCount)
                    {
                        throw;
                    }
                }
                catch (WebException)
                {
                    Console.Write("Provider \"{0}\" is down\n", provider.ProviderName);
                    // Provider is down, lets just ignore it
                }
            }
            var dbManager = new DatabaseManager();

            dbManager.SaveBars(result);
            result.AddRange(dbManager.GetAllBarData(result.Select(x => x.BarId)));
            result.RemoveBarsOutsideRadius(radius);
            result.RemoveDuplicates();
            return(result);
        }
Exemple #4
0
        private async void GoButton_Click(object sender, EventArgs e)
        {
            var latitude  = GetLatitude();
            var longitude = GetLongitude();
            var radius    = GetRadius();
            var failedToConnectCounter = 0;
            var providerCount          = _providerList.Count;

            try
            {
                var barsFromProvider = new List <BarData>();
                var progressStep     = 100 / providerCount;
                var result           = new BarDataModel();

                var currentProgressValue = 0;
                GoButton.Enabled = false;
                InitiateProgressBars();
                UpdateProgressBars(currentProgressValue);
                foreach (IBeerable provider in _providerList)
                {
                    try
                    {
                        barsFromProvider = await CollectBarsFromProvider(provider, latitude, longitude, radius);
                    }
                    catch (HttpRequestException)
                    {
                        if (++failedToConnectCounter == providerCount)
                        {
                            MessageBox.Show("Check your internet connection, it seems to be down.");
                        }
                    }
                    catch (WebException)
                    {
                        MessageBox.Show("Failed connecting to: " + provider.ProviderName);
                    }

                    result.AddRange(barsFromProvider);
                    currentProgressValue += progressStep;
                    UpdateProgressBars(currentProgressValue);
                }
                result.RemoveDuplicates();
                result.RemoveBarsOutsideRadius(radius);
                await Task.Run(() => result = (BarDataModel)WebApiAccess.GetAllBarData(result));

                HideProgressBars();

                // Display
                _barRating.BarsData = result;
                var currentLocation = GetCurrentLocation();
                if (result != null)
                {
                    foreach (var bar in _barRating.BarsData)
                    {
                        bar.DistanceToCurrentLocation =
                            currentLocation.GetDistanceTo(new GeoCoordinate(bar.Latitude, bar.Longitude));
                    }
                    SortList(CompareType.Distance);
                }
            }
            catch (ArgumentsForProvidersException)
            {
                MessageBox.Show("Please enter the required data correctly. Erroneus data is painted red.");
            }
            finally
            {
                HideProgressBars();
                GoButton.Enabled = true;
            }
        }