コード例 #1
0
        public override string ToString()
        {
            StringBuilder result = new StringBuilder();

            result.AppendFormat("Race: {0}\n", RaceName);
            result.Append("------------------\n");

            foreach (Price price in Prices)
            {
                result.AppendFormat("Type: {0}\n", price.PriceType);

                foreach (HorsePrice horsePrice in price.HorsePrices.OrderBy(horsePrice => horsePrice.Price))
                {
                    Horse horse;

                    if (Horses.TryGetValue(horsePrice.HorseNumber, out horse))
                    {
                        result.AppendFormat("\tPrice: {0}, Horse: {1}\n", horsePrice.Price, horse.Name);
                    }
                    else
                    {
                        result.Append("Error: \n");
                    }
                }
            }

            return(result.ToString());
        }
コード例 #2
0
        /// <summary>
        /// updates single horse object
        /// gets data from scrap service
        /// compares with objects in current database
        /// calls merge method if object already in database
        /// </summary>
        /// <param name="jobType"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        private async Task UpdateHorsesAsync(string jobType, int id)
        {
            LoadedHorse horse = new LoadedHorse();

            horse = await _scrapDataService.ScrapGenericObject <LoadedHorse>(id, jobType);

            if (horse != null)
            {
                lock (((ICollection)Horses).SyncRoot)
                {
                    //if objects are already in the List
                    if (Horses.Any(h => h.Name.ToLower() == horse.Name.ToLower()))
                    {
                        LoadedHorse doubledHorse = Horses.Where(h => h.Name.ToLower() == horse.Name.ToLower()).Where(h => h.Age == horse.Age).FirstOrDefault();
                        if (doubledHorse != null)
                        {
                            Horses.Remove(doubledHorse);
                            MergeHorsesData(doubledHorse, horse);
                        }
                        else
                        {
                            Horses.Add(horse);
                        }
                    }
                    else
                    {
                        Horses.Add(horse);
                    }
                }
            }
        }
コード例 #3
0
    void AddHorse(GameObject horse)
    {
        Horses dad = horse.GetComponentsInParent <Horses>()[0];

        // Build the respawn position based off of the first
        // SubHorse to collide with us
        if (horsesSaved == 0)
        {
            respawnPos = new Vector2(
                RespawnX.position.x,
                horse.transform.position.y
                );
        }

        // Remove horse that hit us
        dad.GetComponent <ChildrenList>().RemoveFromList(horse.GetComponent <SubHorse>());
        GameObject.Destroy(horse);

        // Spawn new horses once we get enough horses
        if (dad.controlledSubUnits.Count == 0)
        {
            // Horse controller should be in limbo
            dad.inLimbo = true;

            StartCoroutine(SpawnHorseAfter());
        }

        horsesSaved++;
    }
コード例 #4
0
        public void SortHorses()
        {
            //declares and assigns
            var dt          = new DataTable();
            var iHorseIndex = 0;

            dt.Columns.Add(new DataColumn("Total", System.Type.GetType("System.Int32")));
            dt.Columns.Add(new DataColumn("Horse", System.Type.GetType("System.Object")));

            //process
            //add horses to the datatable
            foreach (var h in Horses)
            {
                dt.Rows.Add(dt.NewRow());
                dt.Rows[iHorseIndex][0]   = h.Total;
                dt.Rows[iHorseIndex++][1] = h;
            }

            //clear all horses
            Horses.Clear();

            //sort the horses in the table
            dt.DefaultView.Sort = "Total desc";
            var dtHorses = dt.DefaultView.ToTable();

            //now readd the sorted horses.
            foreach (DataRow dr in dtHorses.Rows)
            {
                Horses.Add((IHorse)dr[1]);
            }
        }
コード例 #5
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();
        }
コード例 #6
0
        public MainResponse AddUpdateHorse(HorseAddRequest horseAddRequest, string actionBy)
        {
            if (horseAddRequest.HorseId == 0)
            {
                var horseExist = _horseRepository.GetSingle(x => x.Name == horseAddRequest.Name && x.IsActive == true && x.IsDeleted == false);
                if (horseExist != null && horseExist.HorseId > 0)
                {
                    _mainResponse.Message = Constants.HORSE_EXIST;
                    _mainResponse.Success = false;
                    return(_mainResponse);
                }
                var horse = new Horses
                {
                    Name          = horseAddRequest.Name,
                    HorseTypeId   = horseAddRequest.HorseTypeId,
                    JumpHeightId  = horseAddRequest.JumpHeightId,
                    GroupId       = horseAddRequest.GroupId,
                    NSBAIndicator = horseAddRequest.NSBAIndicator,
                    IsActive      = true,
                    CreatedBy     = actionBy,
                    CreatedDate   = DateTime.Now
                };
                var _horse = _horseRepository.Add(horse);

                _mainResponse.NewId   = _horse.HorseId;
                _mainResponse.Message = Constants.HORSE_ADDED;
                _mainResponse.Success = true;
            }
            else
            {
                var horse = _horseRepository.GetSingle(x => x.HorseId == horseAddRequest.HorseId && x.IsActive == true && x.IsDeleted == false);
                if (horse != null)
                {
                    horse.Name          = horseAddRequest.Name;
                    horse.HorseTypeId   = horseAddRequest.HorseTypeId;
                    horse.GroupId       = horseAddRequest.GroupId;
                    horse.JumpHeightId  = horseAddRequest.JumpHeightId;
                    horse.NSBAIndicator = horseAddRequest.NSBAIndicator;
                    horse.ModifiedBy    = actionBy;
                    horse.ModifiedDate  = DateTime.Now;

                    _horseRepository.Update(horse);

                    _mainResponse.NewId   = horseAddRequest.HorseId;
                    _mainResponse.Message = Constants.HORSE_UPDATED;
                    _mainResponse.Success = true;
                }
                else
                {
                    _mainResponse.Success = false;
                    _mainResponse.Message = Constants.NO_RECORD_FOUND;
                }
            }
            return(_mainResponse);
        }
コード例 #7
0
ファイル: MainViewModel.cs プロジェクト: wi16b142/Training10
        private void GuiUpdate(string msg)
        {
            App.Current.Dispatcher.Invoke(() =>
            {
                string name = msg.Split(':')[0];
                int speed   = int.Parse(msg.Split(':')[1]);

                Horses.Add(new HorseVM(name, speed));
                UpdateFastestHorse();
            });
        }
コード例 #8
0
        public static Horses Create(FakeHorseRepository fakeRepository, int id = 1, string name = "Ed")
        {
            var horse = new Horses
            {
                Id   = id,
                Name = name,
            };

            fakeRepository.Horses.Add(horse);

            return(horse);
        }
コード例 #9
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            Contests.Dispose();
            ContestParticipants.Dispose();

            Horses.Dispose();
            HorseOwners.Dispose();
            Racecourses.Dispose();
            HorseFactories.Dispose();

            Jockeys.Dispose();
            Trainers.Dispose();
        }
コード例 #10
0
        /// <summary>
        /// updates list of horses races and children, if found some new
        /// </summary>
        /// <param name="doubledHorse">horse from Horses</param>
        /// <param name="horse">scrapped new horse</param>
        public void MergeHorsesData(LoadedHorse doubledHorse, LoadedHorse horse)
        {
            if (horse.AllRaces != null)
            {
                doubledHorse.AllRaces = doubledHorse.AllRaces.Union(horse.AllRaces).ToList();
            }

            if (horse.AllChildren != null)
            {
                doubledHorse.AllChildren = doubledHorse.AllChildren.Union(horse.AllChildren).ToList();
            }

            Horses.Add(doubledHorse);
        }
コード例 #11
0
        public override bool Equals(object obj)
        {
            var item = obj as RaceData;

            if (item == null)
            {
                return(false);
            }

            var different = Horses.Except(item.Horses).ToList();

            return(RaceName.Equals(item.RaceName) &&
                   Horses.SequenceEqual(item.Horses) &&
                   Prices.SequenceEqual(item.Prices));
        }
コード例 #12
0
        private Horse makeHorse(int ownerID)
        {
            List <String> maleNames   = ReadFile(@"F:\Code\HorseTrack\HorseTrack\Data\MaleHorseNames.txt");
            List <String> femaleNames = ReadFile(@"F:\Code\HorseTrack\HorseTrack\Data\FemaleHorseNames.txt");
            List <String> breeds      = ReadFile(@"F:\Code\HorseTrack\HorseTrack\Data\Breeds.txt");
            List <String> colors      = ReadFile(@"F:\Code\HorseTrack\HorseTrack\Data\Colors.txt");
            Random        rand        = new Random();

            String name;
            String gender;
            int    _gender = rand.Next(4);

            if (_gender <= 1)
            {
                name = maleNames.ElementAt(rand.Next(maleNames.Count - 1));
                maleNames.Remove(name);
                gender = (_gender == 0) ? "Stallion" : "Gelding";
            }
            else
            {
                name = femaleNames.ElementAt(rand.Next(femaleNames.Count - 1));
                femaleNames.Remove(name);
                gender = "Mare";
            }
            String breed = breeds.ElementAt(rand.Next(breeds.Count - 1));
            String color = colors.ElementAt(rand.Next(colors.Count - 1));
            String age   = rand.Next(20).ToString();

            Horse horse = new Horse
            {
                ID       = Horses.Count,
                OwnderID = ownerID,
                Name     = name,
                Gender   = gender,
                Breed    = breed,
                Color    = color,
                Age      = age
            };

            HorseDict.Add(horse.ID.ToString(), horse.Name);
            Horses.Add(horse);
            return(horse);
        }
コード例 #13
0
ファイル: UnitTest1.cs プロジェクト: enrique-aguilar/Farm
        public void TestMethod1()
        {
            Sheep terry = new Sheep();

            terry.Name = "Terry";
            Assert.AreEqual("Terry", terry.Name);

            Horses seabiscuit = new Horses();

            seabiscuit.Name = "Seabiscuit";
            Assert.AreEqual("Seabiscuit", seabiscuit.Name);

            Chicken albertEggstein = new Chicken();

            albertEggstein.Name = "Albert Eggstein";
            Assert.AreEqual("Albert Eggstein", albertEggstein.Name);

            Cow bessie = new Cow();

            bessie.Name = "Bessie";
            Assert.AreEqual("Bessie", bessie.Name);
        }
コード例 #14
0
        /// <summary>
        /// updates collections of generic type
        /// I/O operations
        /// creates loads of parallel tasks to improve performance speed
        /// use of SemaphoreSlim to control tasks
        /// SemaphoreSlim credits: https://blog.briandrupieski.com/throttling-asynchronous-methods-in-csharp
        /// SemaphoreSlim corrections: https://stackoverflow.com/a/56641448/11027921
        /// Task.Run corrections: https://stackoverflow.com/a/56631208/11027921
        /// credits for SemaphoreSlim cancellation: https://stackoverflow.com/a/24099764/11027921
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="genericCollection">collection parameter</param>
        /// <param name="idFrom">object id limitation</param>
        /// <param name="idTo">object id limitation</param>
        /// <param name="jobType">type of scrapping</param>
        /// <returns></returns>
        public async Task <List <T> > UpdateDataAsync <T>(List <T> genericCollection, int idFrom, int idTo, string jobType)
        {
            ProgressBarData progressBar;
            int             loopCounterProgressBar = 0;
            string          jobTypeProgressBar     = "";

            //parse collections, display job
            if (typeof(T) == typeof(LoadedHorse))
            {
                Horses             = new List <LoadedHorse>(genericCollection.Cast <LoadedHorse>());
                jobTypeProgressBar = "Updating horse data";
            }
            else if (typeof(T) == typeof(LoadedJockey))
            {
                Jockeys            = new List <LoadedJockey>(genericCollection.Cast <LoadedJockey>());
                jobTypeProgressBar = "Updating jockey data";
            }
            else if (typeof(T) == typeof(RaceDetails))
            {
                Races = new List <RaceDetails>(genericCollection.Cast <RaceDetails>());
                jobTypeProgressBar = "Updating historic data";
            }

            //initial
            SemaphoreSlim throttler = new SemaphoreSlim(_degreeOfParallelism);
            List <Task>   tasks     = new List <Task>();

            TokenSource       = new CancellationTokenSource();
            CancellationToken = TokenSource.Token;

            progressBar = GetProgressBar(jobType, idFrom, idTo, loopCounterProgressBar);

            progressBar = new ProgressBarData()
            {
                JobType    = jobType,
                FromId     = idFrom,
                ToId       = idTo,
                LoopCouner = loopCounterProgressBar
            };

            _eventAggregator.GetEvent <ProgressBarEvent>().Publish(progressBar);

            //run loop
            for (int i = idFrom; i < idTo + 1; i++)
            {
                int id = i;

                if (CancellationToken.IsCancellationRequested)
                {
                    break;
                }

                //create loads of parallel tasks
                tasks.Add(Task.Run(async() =>
                {
                    await throttler.WaitAsync();
                    try
                    {
                        if (CancellationToken.IsCancellationRequested)
                        {
                            return;
                        }

                        if (typeof(T) == typeof(LoadedHorse))
                        {
                            await UpdateHorsesAsync(jobType, id);
                        }
                        else if (typeof(T) == typeof(LoadedJockey))
                        {
                            await UpdateJockeysAsync(jobType, id);
                        }
                        else if (typeof(T) == typeof(RaceDetails))
                        {
                            await UpdateRacesAsync(jobType, id);
                        }
                    }
                    catch
                    {
                        MessageBox.Show(id.ToString());
                    }
                    finally
                    {
                        loopCounterProgressBar++;

                        progressBar = GetProgressBar(jobTypeProgressBar, idFrom, idTo, loopCounterProgressBar);

                        _eventAggregator.GetEvent <ProgressBarEvent>().Publish(progressBar);

                        throttler.Release();
                    }
                }));
            }

            try
            {
                await Task.WhenAll(tasks);
            }
            finally
            {
                //save when finish
                if (typeof(T) == typeof(LoadedJockey))
                {
                    await _dataServices.SaveAllJockeysAsync(Jockeys.ToList());
                }
                else if (typeof(T) == typeof(LoadedHorse))
                {
                    await _dataServices.SaveAllHorsesAsync(Horses.ToList());
                }
                else if (typeof(T) == typeof(RaceDetails))
                {
                    if (jobType.Contains("Historic"))
                    {
                        await _dataServices.SaveAllRaces(Races.ToList());
                    }
                    else if (jobType.Contains("testRaces"))
                    {
                        await _dataServices.SaveRaceSimulatedResultsAsync(Races.ToList());
                    }
                }
            }

            if (typeof(T) == typeof(LoadedHorse))
            {
                return((List <T>)Convert.ChangeType(Horses, typeof(List <T>)));
            }
            else if (typeof(T) == typeof(LoadedJockey))
            {
                return((List <T>)Convert.ChangeType(Jockeys, typeof(List <T>)));
            }
            else if (typeof(T) == typeof(RaceDetails))
            {
                return((List <T>)Convert.ChangeType(Races, typeof(List <T>)));
            }
            else
            {
                throw new ArgumentException();
            }
        }
コード例 #15
0
 public override int GetHashCode()
 {
     return(23 * RaceName.GetHashCode() +
            Horses.GetHashCode() +
            Prices.GetHashCode());
 }