public List <TableSubject> GetSubjects(string query, bool returnIfRetired, SpaceNavigation currentLocation = null) { List <string> idsToUpdate = new List <string>(); using (SQLiteConnection connection = new SQLiteConnection($"Data Source={App.DatabasePath}")) { List <TableSubject> Subjects = new List <TableSubject>(); try { connection.Open(); SQLiteCommand command = new SQLiteCommand(query, connection); SQLiteDataReader reader = command.ExecuteReader(); while (reader.Read()) { string id = reader["subject_id"] as string; idsToUpdate.Add(id); string filename = reader["filename"] as string; string image = CheckLocalPath(filename) ?? reader["image"] as string; double ra = (double)reader["ra"]; double dec = (double)reader["dec"]; int classificationCount = Convert.ToInt32(reader["classifications_count"]); TableSubject RetrievedSubject = new TableSubject(id, image, ra, dec, classificationCount, currentLocation); Subjects.Add(RetrievedSubject); } connection.Close(); } catch (SQLiteException exception) { string ErrorMessage = $"Error Connecting to Database. Error: {exception.Message}"; Messenger.Default.Send(ErrorMessage, "DatabaseError"); } UpdateDBFromIds(idsToUpdate); if (returnIfRetired) { return(Subjects); } else { return(Subjects.Any(subject => !subject.IsRetired) ? Subjects : new List <TableSubject>()); } } }
public async Task <SpaceCutout> GetSpaceCutout(SpaceNavigation location) { double plateScale = 1.75; double ra = Math.Round(location.Center.RightAscension, 3); double dec = Math.Round(location.Center.Declination, 3); SpaceCutout cutout = new SpaceCutout(); if (DECALSIsResponding) { using (WebResponse response = await FetchDECALSCutout(ra, dec, plateScale)) if (response != null) { double RaStep = (location.RaRange / 3) + (location.RaRange * 0.049); double leftRA = Math.Round(location.Center.RightAscension + RaStep, 3); double rightRA = Math.Round(location.Center.RightAscension - RaStep, 3); cutout.ImageOne = BitmapFromUrl(response.ResponseUri.ToString()); cutout.ImageTwo = BitmapFromUrl(DECaLSEndpoint(plateScale, dec, leftRA)); cutout.ImageThree = BitmapFromUrl(DECaLSEndpoint(plateScale, dec, rightRA)); } } if (SDSSIsResponding && cutout.ImageOne == null) { using (WebResponse response = await FetchSDSSCutout(ra, dec, plateScale)) if (response != null) { cutout.ImageOne = BitmapFromUrl(response.ResponseUri.ToString()); } } if (cutout.ImageOne == null) { GlobalData.GetInstance().Logger?.AddEntry("Cutout_Services_Down"); cutout.ImageOne = BitmapFromUrl("pack://application:,,,/Images/General/star-bg.jpg"); } return(cutout); }
string SubjectsWithinBoundsQuery(SpaceNavigation location) { return($"select * from Subjects where dec > {location.MinDec} and dec < {location.MaxDec} and ra > {location.MinRa} and ra < {location.MaxRa}"); }
public List <TableSubject> GetLocalSubjects(SpaceNavigation currentLocation, bool returnIfRetired = false) { string query = SubjectsWithinBoundsQuery(currentLocation); return(GetSubjects(query, returnIfRetired, currentLocation)); }
public PeripheralItem(SpaceNavigation location) { Location = location; }