示例#1
0
    private searchParams sParam; // parameters of search ( start node, end node and map)

    //instantiate values
    public AStarPathing(searchParams sParam)
    {
        this.sParam = sParam;
        initNodes(sParam.Map);
        this.startNode       = this.nodes[sParam.StartLocation.X, sParam.StartLocation.Y];
        this.startNode.State = Node.state.open;
        this.endNode         = this.nodes[sParam.EndLocaton.X, sParam.EndLocaton.Y];
    }
示例#2
0
        async Task threadProc()
        {
            List <PersonBasicWebModel> peopleFromWebservice = null;
            List <PersonBasicWebModel> people = new List <PersonBasicWebModel>();

            for (int iter = 0; iter < 3; ++iter)
            {
                searchParams sp = this.theSearchParams;

                /// query the web service
                ///
                isSearchingNow = true;
                if (sp != null)
                {
                    peopleFromWebservice = await App.WebService.FindPeople(sp.NameQuery, sp.Country, sp.MetroID, sp.FriendsOnly, Config.App == MobileAppEnum.SnookerForVenues);
                }
                isSearchingNow = false;

                /// query the local database
                ///
                List <PersonBasicWebModel> peopleFromLocalDb = new List <PersonBasicWebModel>();
                if (Config.App == MobileAppEnum.SnookerForVenues && sp.IsMyMetro)
                {
                    var idsOfPeoplePlayed = App.Repository.GetAthleteNamesFromResults(true);
                    peopleFromLocalDb = App.Cache.People.Get(idsOfPeoplePlayed, true);
                }

                /// merge peopleFromWebservice and peopleFromHere
                ///
                people = new List <PersonBasicWebModel>();
                foreach (var person in peopleFromLocalDb)
                {
                    people.Add(person);
                }
                if (peopleFromWebservice != null)
                {
                    foreach (var person in peopleFromWebservice)
                    {
                        if (people.Where(i => i.ID == person.ID).Count() == 0)
                        {
                            people.Add(person);
                        }
                    }
                }

                if (shouldDoAnotherSearch == false)
                {
                    break;
                }
            }

            /// fill up
            ///
            Device.BeginInvokeOnMainThread(() =>
            {
                this.fill(people, peopleFromWebservice);
                if (this.LoadCompleted != null)
                {
                    this.LoadCompleted();
                }
            });
        }
示例#3
0
        void reloadAsync(bool forceWorldwide = false)
        {
            TraceHelper.TraceInfoForResponsiveness("FindPeopleControl.reloadAsync");

            /// search parameters to use
            ///

            var community = this.communitySelectorControl.Selection;

            this.communityLoaded = community;
            Country country = community.Country;
            int?    metroID = null;

            if (community.MetroID > 0)
            {
                metroID = community.MetroID;
            }
            string nameQuery = this.entrySearch.Text;

            if (nameQuery == null)
            {
                nameQuery = "";
            }
            nameQuery = nameQuery.Trim();
            bool friendsOnly = community.IsFriendsOnly == true;

            if (forceWorldwide)
            {
                country     = null;
                metroID     = null;
                friendsOnly = false;
            }
            this.theSearchParams = new searchParams()
            {
                NameQuery   = nameQuery,
                Country     = country,
                MetroID     = metroID,
                FriendsOnly = friendsOnly,
                IsMyMetro   = community.IsMyMetro,
            };

            /// if already searching, search again
            ///
            if (isSearchingNow == true)
            {
                shouldDoAnotherSearch = true;
                return;
            }
            shouldDoAnotherSearch = false;

            /// update the UI
            ///
            if (this.LoadStarted != null)
            {
                this.LoadStarted();
            }
            this.panelStatus.IsVisible           = true;
            this.labelStatus.Text                = "Querying snookerbyb.com ...";
            this.listOfPeopleControl.IsVisible   = false;
            this.buttonSearchWorldwide.IsVisible = false;

            /// load data async
            ///
            Task.Run(async() => { await this.threadProc(); });
        }
示例#4
0
        async void threadProc()
        {
            for (long iter = 0; ; ++iter)
            {
                Thread.Sleep(500);

                bool shouldCheck = iter % 3 == 0;                 // check every 1500ms
                if (this.avoidLoadingVenuesUntilThisTime != null && DateTime.Now < this.avoidLoadingVenuesUntilThisTime.Value)
                {
                    shouldCheck = false;
                }

                if (shouldCheck == true)
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        // check if the user moved the map
                        if (map.VisibleRegion != null)
                        {
                            Location newLocation = new Location(map.VisibleRegion.Center.Latitude, map.VisibleRegion.Center.Longitude);
                            int newRadius        = (int)map.VisibleRegion.Radius.Meters;
                            if ((currentLocation != null && newLocation != null && Distance.Calculate(newLocation, currentLocation).Miles > 5) ||
                                (currentRadiusInMeters != null && System.Math.Abs(currentRadiusInMeters.Value - newRadius) > 10000))
                            {
                                this.currentLocation   = newLocation;
                                this.needToSearchAgain = true;
                            }
                        }

                        if (this.needToSearchAgain)
                        {
                            TraceHelper.TraceInfoForResponsiveness("threadProc - needToSearchAgain=true");

                            this.needToSearchAgain     = false;
                            this.currentRadiusInMeters = (int)(map.VisibleRegion != null ? map.VisibleRegion.Radius.Meters : 50000);

                            int radius = this.currentRadiusInMeters.Value;
                            if (radius > 500000)
                            {
                                radius = (int)(radius * 1.5);
                            }
                            if (radius > 1000000)
                            {
                                radius = (int)(radius * 1.5);
                            }

                            // start the search
                            searchParamsToUse = new searchParams()
                            {
                                RequireSnookerTables = false,
                                Require12ftTables    = false,
                                SearchQuery          = this.entrySearch.Text,
                                Location             = this.currentLocation,
                                RadiusInMeters       = radius,
                                Country = (this.CurrentCommunity != null && this.CurrentCommunity.Country != null) ? this.CurrentCommunity.Country.ThreeLetterCode : "",
                            };

                            this.panelStatus.IsVisible = true;
                            this.labelStatus.Text      = "Loading venues...";
                        }
                    });
                }

                if (this.searchParamsToUse == null)
                {
                    continue;
                }

                var venuesFromWeb = await App.WebService.FindSnookerVenues2(searchParamsToUse.Location, searchParamsToUse.Country, searchParamsToUse.RadiusInMeters, searchParamsToUse.SearchQuery, MaxVenuesToLoad);

                this.searchParamsToUse = null;

                Device.BeginInvokeOnMainThread(() => { this.doOnVenuesLoaded(venuesFromWeb); });
            }
        }