private static void Download(string[] args, CreatureDownloader creatureDownloader) { if (args.Length < 2) { ListOperations(); return; } var file = args[0]; var monsters = creatureDownloader.ListMonsters(); var urisOrNames = args .Skip(1) .Select(uriOrName => Uri.IsWellFormedUriString(uriOrName, UriKind.Absolute) ? uriOrName : monsters.FirstOrDefault(monster => string.Equals(uriOrName, monster.Key, StringComparison.OrdinalIgnoreCase)).Value ?? throw new ArgumentException("Invalid monster name or uri.")); var creatures = creatureDownloader.DownloadCreatures(urisOrNames.ToArray()); SaveToFiile(file, creatures); }
private static void ListAll(string[] args, CreatureDownloader creatureDownloader) { creatureDownloader.ListMonsters().ToList().ForEach(f => Console.WriteLine($"Name: {f.Key}, Uri: {f.Value}")); }