public static ISystem GetSystemNearestTo(Point3D currentpos, Point3D wantedpos, double maxfromcurpos, double maxfromwanted, SystemsDB.SystemsNearestMetric routemethod, int limitto) { if (SystemsDatabase.Instance.RebuildRunning) // return from cache is rebuild is running { lock (systemsByEdsmId) { var candidates = systemsByName.Values .SelectMany(s => s) .Select(s => new { dc = s.Distance(currentpos.X, currentpos.Y, currentpos.Z), dw = s.Distance(wantedpos.X, wantedpos.Y, wantedpos.Z), sys = s }) .Where(s => s.dw < maxfromwanted && s.dc < maxfromcurpos) .OrderBy(s => s.dw) .Select(s => s.sys) .ToList(); return(DB.SystemsDB.GetSystemNearestTo(candidates, currentpos, wantedpos, maxfromcurpos, maxfromwanted, routemethod)); } } else { return(SystemsDatabase.Instance.ExecuteWithDatabase(conn => GetSystemNearestTo(currentpos, wantedpos, maxfromcurpos, maxfromwanted, routemethod, limitto, conn))); } }
private static ISystem GetSystemNearestTo(Point3D currentpos, Point3D wantedpos, double maxfromcurpos, double maxfromwanted, SystemsDB.SystemsNearestMetric routemethod, int limitto, SystemsDatabaseConnection cn) { ISystem sys = DB.SystemsDB.GetSystemNearestTo(currentpos, wantedpos, maxfromcurpos, maxfromwanted, routemethod, cn.Connection, (s) => AddToCache(s), limitto); return(sys); }