예제 #1
0
        private static async Task <long> MapNameToId64(EdsmClient client, string line)
        {
            if (!Directory.Exists(TempCachePath))
            {
                Directory.CreateDirectory(TempCachePath);
            }

            var systemName = line.ToLowerInvariant().Trim();
            var path       = $"{TempCachePath}{Path.DirectorySeparatorChar}{string.Join("_", systemName.Split(Path.GetInvalidFileNameChars()))}";

            if (File.Exists(path) && long.TryParse(await File.ReadAllTextAsync(path), out var id64))
            {
                return(id64);
            }
            var result = await client.GetId64(systemName);

            await File.WriteAllTextAsync(path, result.ToString());

            return(result);
        }
예제 #2
0
 private static async Task <SysIdLine> ParseId(EdsmClient client, string line)
 {
     try
     {
         if (long.TryParse(line, out var id))
         {
             return(new(line, id));
         }
         try
         {
             return(new SysIdLine(line, await MapNameToId64(client, line)));
         }
         catch (Exception ex)
         {
             return(new SysIdLine(line, null, ex));
         }
     }
     finally
     {
         Console.Write($"\rSystems read: {Interlocked.Increment(ref _totalIdsLoaded)}");
     }
 }
예제 #3
0
        private static async Task <long[]> ReadIdsToMerge(string path)
        {
            using var client = new EdsmClient();
            Console.WriteLine($"Reading system ids from: {path}");

            var ids = await Task.WhenAll(File.ReadAllLines(path)
                                         .Where(line => !string.IsNullOrWhiteSpace(line))
                                         .Select(line => ParseId(client, line)));

            Console.WriteLine();
            var failed = ids.Where(x => !x.Id64.HasValue).ToArray();

            if (failed.Any())
            {
                Console.WriteLine("Failed systems:");
                foreach (var sys in failed)
                {
                    Console.WriteLine($"{sys.Name}: {sys.Exception?.Message}");
                }
            }

            return(ids.Where(i => i.Id64.HasValue).Select(x => x.Id64.GetValueOrDefault()).ToArray());
        }