예제 #1
0
        /// <summary>
        /// subscribed to event
        /// loads horses from the file data services
        /// async void eventhandler testing credits: https://stackoverflow.com/a/19415703/11027921
        /// delegates https://docs.microsoft.com/en-us/dotnet/api/system.eventhandler?view=netframework-4.8
        /// </summary>
        public async void OnLoadAllDataAsync()
        {
            string callersName = GetCallerName();

            CommandStartedControlsSetup(callersName);

            if (Horses.Count == 0 && Jockeys.Count == 0 && Races.Count == 0)
            {
                List <LoadedHorse> horses = await _dataServices.GetAllHorsesAsync();

                List <LoadedJockey> jockeys = await _dataServices.GetAllJockeysAsync();

                List <RaceDetails> races = await _dataServices.GetAllRacesAsync();

                foreach (var horse in horses)
                {
                    Horses.Add(new LoadedHorse
                    {
                        Name        = horse.Name,
                        Age         = horse.Age,
                        AllRaces    = horse.AllRaces,
                        AllChildren = horse.AllChildren,
                        Father      = horse.Father,
                        Link        = horse.Link,
                        FatherLink  = horse.FatherLink
                    });
                }

                Horses = Horses.OrderBy(o => o.Age).ToList();

                foreach (var jockey in jockeys)
                {
                    Jockeys.Add(new LoadedJockey
                    {
                        Name     = jockey.Name,
                        AllRaces = jockey.AllRaces,
                        Link     = jockey.Link
                    });
                }

                foreach (var race in races)
                {
                    Races.Add(new RaceDetails
                    {
                        RaceCategory = race.RaceCategory,
                        RaceDate     = race.RaceDate,
                        RaceDistance = race.RaceDistance,
                        RaceLink     = race.RaceLink,
                        HorseList    = race.HorseList
                    });
                }
            }

            PopulateLists();

            CommandCompletedControlsSetup();
            ResetControls();
        }
예제 #2
0
        /// <summary>
        /// updates list of jockey races, if found some new
        /// </summary>
        /// <param name="doubledJockey">jockey for Jockeys</param>
        /// <param name="jockey">found doubler</param>
        public void MergeJockeysData(LoadedJockey doubledJockey, LoadedJockey jockey)
        {
            if (jockey.AllRaces != null)
            {
                doubledJockey.AllRaces = doubledJockey.AllRaces.Union(jockey.AllRaces).ToList();
            }

            Jockeys.Add(doubledJockey);
        }
예제 #3
0
        /// <summary>
        /// updates single jockey object
        /// gets data from scrap service
        /// compares with objects in current database
        /// calls merge method if object already in database
        /// </summary>
        /// <param name="jobType">type of scrapping</param>
        /// <param name="id">id on the website</param>
        /// <returns></returns>
        private async Task UpdateJockeysAsync(string jobType, int id)
        {
            LoadedJockey jockey = new LoadedJockey();

            jockey = await _scrapDataService.ScrapGenericObject <LoadedJockey>(id, jobType);

            if (jockey != null)
            {
                lock (((ICollection)Jockeys).SyncRoot)
                {
                    //if objects are already in the List
                    if (Jockeys.Any(h => h.Name.ToLower() == jockey.Name.ToLower()))
                    {
                        LoadedJockey doubledJockey = Jockeys.Where(h => h.Name.ToLower() == jockey.Name.ToLower()).FirstOrDefault();
                        Jockeys.Remove(doubledJockey);
                        MergeJockeysData(doubledJockey, jockey);
                    }
                    else
                    {
                        Jockeys.Add(jockey);
                    }
                }
            }
        }