public static async Task CreateNeutralAsync(GameServiceClient client) { var neutral = new Neutral(); neutral.Name = ConsoleUtility.GetUserInput("Neutral Name: "); neutral.GamePackageId = await GamePackageUtility.SelectGamePackageId(client); if (!ConsoleUtility.ShouldContinue($"Creating Neutral: '{neutral.Name}', in gamePackage '{neutral.GamePackageId}'")) { await CreateNeutralAsync(client); return; } var createRequest = new CreateNeutralsRequest(); createRequest.Neutrals.Add(neutral); var createReply = await client.CreateNeutralsAsync(createRequest); if (createReply.Status.Code != 200) { ConsoleUtility.WriteLine($"Failed to create neutral: {createReply.Status.Message}"); } else { ConsoleUtility.WriteLine($"Neutral '{createReply.Neutrals.First().Name}' was created with Id '{createReply.Neutrals.First().Id}'"); } }
private static async ValueTask <IReadOnlyList <Neutral> > CreateNeutrals(GameServiceClient client, IReadOnlyList <GamePackage> packages) { ConsoleUtility.WriteLine("Creating neutrals"); List <Neutral> result = (await NeutralUtility.GetNeutralsAsync(client, null)).ToList(); if (result.Any()) { return(result); } foreach (var file in Directory.EnumerateFiles(@"C:\Users\Ryan\SkyDrive\code\LegendaryGameStarter\LegendaryGameModel2\GameSets", s_fileMask)) { var doc = XDocument.Load(file); var name = doc.Element("Set").Attribute("Name").Value; var activeGamePackage = packages.FirstOrDefault(x => x.Name == name); if (activeGamePackage == null) { ConsoleUtility.WriteLine($"Failed to find matching game package for {file}"); } foreach (var neutralElement in doc.Element("Set").Element("Cards").Elements("Card").Where(x => x?.Attribute("Area").Value == "Neutral")) { var request = new CreateNeutralsRequest(); request.CreateOptions.Add(CreateOptions.ErrorOnDuplicates); var neutral = new Neutral(); neutral.Name = neutralElement.Attribute("Name").Value; neutral.GamePackageId = activeGamePackage.Id; request.Neutrals.Add(neutral); var reply = await client.CreateNeutralsAsync(request); if (reply.Status.Code != 200) { ConsoleUtility.WriteLine($"Failed to create '{neutral.Name}': {reply.Status.Message}"); } result.AddRange(reply.Neutrals); } } return(result); }