示例#1
0
        public void RegisterInstance(CSComponent component)
        {
            Instances.Add(component);

            if (StartMethod != null)
            {
                StartList.Add(component);
            }
        }
        public async Task <ActionResult> Save(int raceId, int runNumber, [FromBody] IEnumerable <StartListDto> startList)
        {
            List <StartList> dbStartList = new List <StartList>();

            foreach (var startListItem in startList)
            {
                StartList dbStartListItem = this.mapper.Map <StartList>(startListItem);
                dbStartList.Add(this.mapper.Map <StartList>(startListItem));
            }

            var result = await this.startListLogic.SaveAsync(raceId, runNumber, dbStartList);

            return(result.Match(
                       success => this.StatusCode(200, success.Id),
                       validationError => this.StatusCode(400, validationError.Errors),
                       error => this.StatusCode(500, error.ErrorCode)));
        }
示例#3
0
        public void ValidateDefaultStartListTest()
        {
            // Arrange
            var validators = new StartListValidator();
            var skier      = new StartList();

            // Act
            var result = validators.Validate(skier);

            // Assert
            Assert.False(result.IsValid);
            Assert.Equal(4, result.Errors.Count);

            Assert.Equal(ErrorCode.GreaterThanOrEqual, result.ErrorCodeFor(nameof(StartList.StartNumber)));
            Assert.Equal(ErrorCode.GreaterThanOrEqual, result.ErrorCodeFor(nameof(StartList.RunNumber)));
            Assert.Equal(ErrorCode.ForeignKey, result.ErrorCodeFor(nameof(StartList.SkierId)));
            Assert.Equal(ErrorCode.ForeignKey, result.ErrorCodeFor(nameof(StartList.RaceId)));
        }
示例#4
0
        public async Task SetupAsync()
        {
            try
            {
                if (!_eventsSetup)
                {
                    SetupRaceEvents();
                }
                _currentSkier = await _activeRaceService.GetCurrentSkier(RaceState.Race.Id);
                await LoadStartList();

                await CurrentSkierViewModel.InitializeAsync();

                await RankingViewModel.InitializeAsync();
            }
            catch (Exception)
            {
                MessageBoxUtil.Error("Fehler beim Laden der Daten");
            }
        }
示例#5
0
        public static StartListState GetStartListState(
            this StartList startList,
            IEnumerable <RaceData> raceData,
            int sensorAmount,
            int runningStartListId)
        {
            if (startList.IsDisqualified)
            {
                return(StartListState.Disqualified);
            }

            if (startList.Id == runningStartListId)
            {
                return(StartListState.Running);
            }

            if (raceData.Any(d => d.SensorId == sensorAmount))
            {
                return(StartListState.Done);
            }

            return(StartListState.NotStarted);
        }
示例#6
0
        private void SetupCommands()
        {
            ReadyTrackCommand = new AsyncCommand(ReadyTrack,
                                                 () =>
                                                 (_currentSkier == null || _currentSkier != null &&
                                                  (_currentSkier.StartStateId ==
                                                   (int)StartState.Finished ||
                                                   _currentSkier.StartStateId ==
                                                   (int)StartState.Disqualified)) &&
                                                 StartList.Any());
            CancelSkierCommand = new AsyncCommand <int>(async skierId => await CancelSkier(skierId));
            CancelRaceCommand  = new AsyncCommand(CancelRace, () =>
                                                  RaceState.Race.RaceStateId ==
                                                  (int)Dal.Domain.Enums.RaceState.Running);
            EndRaceCommand =
                new AsyncCommand(
                    EndRace,
                    () => (_currentSkier == null ||
                           _currentSkier.StartStateId != (int)Dal.Domain.Enums.RaceState.Finished) &&
                    StartList.Count == 0 &&
                    RaceState.Race.RaceStateId ==
                    (int)Dal.Domain.Enums.RaceState.Running);
            DisqualifyCurrentSkierCommand = new AsyncCommand(
                async() => await _activeRaceControlService.DisqualifyCurrentSkier(), () =>
                _currentSkier != null &&
                _currentSkier.StartStateId == (int)StartState.Running);

            DisqualifyLateCommand = new AsyncCommand(() => _activeRaceControlService.DisqualifyFinishedSkier(
                                                         RankingViewModel.SelectedRaceRanking.StartList.SkierId), () =>
            {
                var selectedRanking = RankingViewModel
                                      .SelectedRaceRanking;
                return(selectedRanking != null &&
                       selectedRanking.StartList.StartStateId ==
                       (int)StartState.Finished);
            });
        }
示例#7
0
        public void Update(Object[] args)
        {
            if (StartMethod != null)
            {
                foreach (var instance in StartList)
                {
                    var node = instance.Node;

                    if (node != null && node.IsEnabled())
                    {
                        if (node.Scene != null)
                        {
                            StartMethod.Invoke(instance, null);
                        }
                    }
                }

                // TODO: need to handle delayed starts when node isn't enabled
                StartList.Clear();
            }

            if (UpdateMethod != null)
            {
                foreach (var instance in Instances)
                {
                    bool remove = false;

                    var node = instance.Node;

                    // TODO: Ideally we want to remove disabled instances,
                    // and re-add them when re-enabled
                    if (node != null /*&& node.IsEnabled()*/)
                    {
                        if (node.Scene != null)
                        {
                            if (node.IsEnabled())
                            {
                                UpdateMethod.Invoke(instance, args);
                            }
                        }
                        else
                        {
                            remove = true;
                        }
                    }
                    else
                    {
                        remove = true;
                    }

                    if (remove)
                    {
                        RemoveList.Add(instance);
                    }
                }
            }

            foreach (var instance in RemoveList)
            {
                Instances.Remove(instance);
            }

            RemoveList.Clear();
        }
示例#8
0
 private async Task LoadStartList() =>
 StartList.Repopulate(await _activeRaceService.GetRemainingStartList(RaceState.Race.Id));
示例#9
0
 public static StartListForRaceDto FromStartList(StartList sl) => new StartListForRaceDto(
     sl.StartNumber,
     sl.Skier,
     sl.StartStateId
     );