public StatsManagerVM(StatComparisonDocumentVM owner)
            {
                _statCategories = new Dictionary <string, StatCategoryVM>();
                _statInfoVms    = new Dictionary <IStat, StatInfoVM>();
                foreach (var stat in StatsProviderManager.Instance.Stats)
                {
                    var statVm = _statInfoVms.GetOrCreate(stat, () => new StatInfoVM(stat));
                    foreach (var categoryName in stat.Categories)
                    {
                        var category = _statCategories.GetOrCreate(categoryName, () => new StatCategoryVM(categoryName));
                        category.Stats.Add(statVm);
                    }
                }

                _owner = owner;
                this.AvailableStatCategories = new ObservableCollection <StatCategoryVM>(_statCategories.Values);
                this.SelectedStats           = new ObservableCollection <StatInfoVM>();
                _selectedStatsLookup         = new HashSet <StatInfoVM>();

                var statsToAdd = new List <StatInfoVM>();

                foreach (var statKey in _owner.PersistentInfo.StatKeys)
                {
                    var stat = StatsProviderManager.Instance.GetStat(statKey);
                    if (stat == null)
                    {
                        this.LogWarning("stat '{0}' not found", statKey);
                    }
                    else
                    {
                        statsToAdd.Add(this.GetStatInfoVM(stat));
                    }
                }

                this.AddStatRange(statsToAdd, 0);

                this.SelectedStats.CollectionChanged += SelectedStats_CollectionChanged;

                this.AddStatCommand      = new RelayCommand <object>(this.AddStat, this.CanAddStat);
                this.RemoveStatCommand   = new RelayCommand <IList>(this.RemoveStat, this.CanRemoveStat);
                this.StatMoveUpCommand   = new RelayCommand <IList>(this.StatMoveUp, this.CanMoveStatUp);
                this.StatMoveDownCommand = new RelayCommand <IList>(this.StatMoveDown, this.CanMoveStatDown);

                this.OpenStatsPresetCommand = new RelayCommand(this.OpenStatsPreset);
                this.SaveStatsPresetCommand = new RelayCommand(this.SaveStatsPreset);

                this.SelectedStatsDropHandler  = new SelectedStatsDropHandlerImpl(this);
                this.AvailableStatsDropHandler = new AvailableStatsDropHandlerImpl(this);
            }
Beispiel #2
0
            public TanksManagerVM(StatComparisonDocumentVM owner)
            {
                _owner             = owner;
                _tankVms           = new Dictionary <TankUnikey, TankVM>();
                this.SelectedTanks = new ObservableCollection <TankVM>();

                foreach (var tankKey in _owner.PersistentInfo.TankKeys)
                {
                    var tank = this.GetTankVM(tankKey);
                    if (tank != null)
                    {
                        this.SelectedTanks.Add(tank);
                    }
                    else
                    {
                        this.LogWarning("tank '{0}' not found", tankKey);
                    }
                }

                if (_owner.PersistentInfo.BenchmarkTankKey != null)
                {
                    var benchmarkTank = this.GetTankVM(_owner.PersistentInfo.BenchmarkTankKey.Value);
                    if (benchmarkTank == null)
                    {
                        this.LogWarning("tank '{0}' not found", _owner.PersistentInfo.BenchmarkTankKey.Value);
                    }

                    if (!this.SelectedTanks.Contains(benchmarkTank))
                    {
                        this.LogWarning("invalid benchmark tank '{0}'", _owner.PersistentInfo.BenchmarkTankKey.Value);
                        _owner.PersistentInfo.BenchmarkTankKey = null;
                    }
                    else
                    {
                        this.BenchmarkTank = benchmarkTank;
                    }
                }

                this.SelectedTanks.CollectionChanged += SelectedTanks_CollectionChanged;

                this.InitializeCommands();

                this.SelectedTanksDropHandler = new SelectedTanksDropHandlerImpl(this);
            }
 private void AddToComparisonDocument(TankUnikey[] keys, StatComparisonDocumentVM documentVm)
 {
     foreach (var key in keys)
     {
         var tankVm = documentVm.TanksManager.GetTankVM(key);
         if (tankVm != null)
         {
             if (!documentVm.TanksManager.SelectedTanks.Contains(tankVm))
             {
                 documentVm.TanksManager.SelectedTanks.Add(tankVm);
             }
         }
         else
         {
             this.LogError("failed to get tank from key: {0}", keys);
             return;
         }
     }
 }
        public override ICreateDocumentTask CreateCreateDocumentTask(Uri uri, Guid guid, string persistentInfo)
        {
            return(CreateDocumentTask.FromFactory(() =>
            {
                var view = new StatComparisonDocumentView();
                var vm = new StatComparisonDocumentVM(this, view.CommandBindings, persistentInfo);
                view.ViewModel = vm;

                var docInfo = new DocumentInfo(guid: guid,
                                               repositoryId: null,
                                               uri: uri,
                                               title: this.L("stat_comparer", "new_comparison_default_title"),
                                               content: view,
                                               features: new IFeature[] { vm },
                                               persistentInfoProvider: vm.PersistentInfo)
                {
                    IconSource = StatComparerModule.CompareIcon
                };
                vm.DocumentInfo = docInfo;

                return docInfo;
            }));
        }
 public DropHandlerImpl(StatComparisonDocumentVM owner)
 {
     _owner = owner;
 }