private void UpdateBenchmarking(StatInfoVM statInfo)
        {
            Dictionary <TankVM, StatVM> tankStats;

            if (!_statVms.TryGetValue(statInfo, out tankStats))
            {
                return;
            }

            var statVms = tankStats.Values.ToArray();

            if (this.TanksManager.BenchmarkTank == null)
            {
                foreach (var statVm in statVms)
                {
                    statVm.BenchmarkIcon = null;
                }

                return;
            }

            if (statVms.All(v => v.IsLoaded))
            {
                var benchmarkTankStatVm = tankStats[this.TanksManager.BenchmarkTank];
                benchmarkTankStatVm.BenchmarkIcon = null;

                foreach (var statVm in statVms)
                {
                    if (statVm != benchmarkTankStatVm)
                    {
                        statVm.BenchmarkIcon = statVm.GetBenchmarkIcon(benchmarkTankStatVm);
                    }
                }
            }
        }
            private void MoveStatItem(StatInfoVM stat, int insertIndex)
            {
                var oldIndex = _owner.SelectedStats.IndexOf(stat);

                insertIndex = insertIndex > oldIndex ? insertIndex - 1 : insertIndex;
                _owner.SelectedStats.Move(oldIndex, insertIndex);
            }
        private StatVM GetStatVM(TankVM tank, StatInfoVM statInfo)
        {
            var tankStats = _statVms.GetOrCreate(statInfo, () => new Dictionary <TankVM, StatVM>());

            return(tankStats.GetOrCreate(tank,
                                         () => new StatVM(statInfo,
                                                          statInfo.Model,
                                                          TankInstanceManager.GetInstance(tank.Repository, tank.Model))));
        }
 private void RawAddStat(StatInfoVM stat, int index)
 {
     if (!_selectedStatsLookup.Contains(stat))
     {
         this.SelectedStats.Insert(index, stat);
         _selectedStatsLookup.Add(stat);
         stat.IsSelected = true;
     }
 }
        private void UpdateComparison(StatInfoVM statInfo)
        {
            Dictionary <TankVM, StatVM> tankStats;

            if (!_statVms.TryGetValue(statInfo, out tankStats))
            {
                return;
            }

            if (statInfo.Model.CompareStrategy != CompareStrategy.HigherBetter &&
                statInfo.Model.CompareStrategy != CompareStrategy.LowerBetter)
            {
                foreach (var stat in tankStats.Values)
                {
                    stat.IsBest = false;
                }

                return;
            }

            if (tankStats.Values.All(v => v.IsLoaded))
            {
                StatVM[] bestStats;

                // besure to convert the values to Array to make them threadsafe
                var statValues = tankStats.Values.ToArray();

                if (statInfo.Model.CompareStrategy == CompareStrategy.HigherBetter)
                {
                    bestStats = statValues.WithMax(s => s.Value, statInfo.Model.Comparer);
                }
                else
                {
                    bestStats = statValues.WithMin(s => s.Value, statInfo.Model.Comparer);
                }

                if (bestStats.Length == tankStats.Count)
                {
                    foreach (var stat in statValues)
                    {
                        stat.IsBest = false;
                    }
                }
                else
                {
                    var bestStatsSet = new HashSet <StatVM>(bestStats);

                    foreach (var stat in statValues)
                    {
                        stat.IsBest = bestStatsSet.Contains(stat);
                    }
                }
            }
        }
            private void AddStat(StatInfoVM stat, int index)
            {
                this.RawAddStat(stat, index);

                this.UpdateCategoryVisibilities();
            }