Exemplo n.º 1
0
        private async Task <bool> LoadData()
        {
            IDataSource source = null;

            try
            {
                source = new ArmoryDataSource.DataSource(null);
            }
            catch (InvalidDataSourceException)
            {
                return(false);
            }

            ISkill[] skills = await source.GetSkills();

            IArmorPiece[] armors = await source.GetArmorPieces();

            ICharm[] charms = await source.GetCharms();

            IJewel[] jewels = await source.GetJewels();

            if (skills == null || armors == null || charms == null || jewels == null)
            {
                CloseApplicationBecauseOfDataSource(source.Description);
                return(false);
            }

            IList <SkillViewModel> allSkills = skills
                                               .OrderBy(x => x.Id)
                                               .Select(x => new SkillViewModel(x, jewels.Where(j => j.Abilities.Any(a => a.Skill.Id == x.Id)).ToList(), rootViewModel, skillSelectorWindow.SkillSelector))
                                               .ToList();

            skillSelectorWindow.SkillSelector.Skills = allSkills;

            IList <AbilityViewModel> allAbilities = allSkills
                                                    .SelectMany(x => x.Abilities)
                                                    .ToList();

            rootViewModel.SelectedAbilities = allAbilities;

            GlobalData.Instance.SetSkills(skills);
            GlobalData.Instance.SetArmors(armors);
            GlobalData.Instance.Charms = charms.SelectMany(x => x.Levels).ToList();
            GlobalData.Instance.Jewels = jewels;

            rootViewModel.SetAllEquipments(
                armors.Select(x => new ArmorPieceViewModel(rootViewModel, x))
                .Concat(GlobalData.Instance.Charms.Select(x => new EquipmentViewModel(rootViewModel, x)))
                .ToList()
                );

            return(true);
        }