Exemplo n.º 1
0
        private static async ValueTask <IReadOnlyList <Ability> > CreateAbilities(GameServiceClient client, IReadOnlyList <GamePackage> packages)
        {
            ConsoleUtility.WriteLine("Creating abilities");

            var existingAbilities = await AbilityUtility.GetAbilitiesAsync(client, null);

            if (existingAbilities.Any())
            {
                return(existingAbilities);
            }

            var doc = XDocument.Load(@"C:\Users\Ryan\SkyDrive\code\LegendaryGameStarter\LegendaryGameModel2\Abilities\Abilities.xml");

            var request = new CreateAbilitiesRequest();

            request.Abilities.AddRange(doc.Root.Elements("Ability").Select(ability =>
            {
                var gamePackage = packages.First(x => x.Name.Equals(ability.Element("Source").Value, StringComparison.OrdinalIgnoreCase));
                return(new Ability {
                    Name = ability.Element("Name").Value, Description = ability.Element("Description").Value, GamePackage = gamePackage
                });
            }));

            var result = await client.CreateAbilitiesAsync(request);

            ConsoleUtility.WriteLine($"Status: {result.Status.Code}: {result.Status.Message}");

            return(result.Abilities);
        }