public string GetCar(Int16 carid) { try { throw new Exception("something broke"); } catch (Exception e) { Console.WriteLine(e.ToString()); DBController dbc = new DBController(); dbc.AddLog("GetCar?carid={carid}", carid, null, null, e.ToString().Substring(0, Math.Min(e.ToString().Count(), 254)), ""); dbc.Close(); } return ""; }
public void CompetitionSignUp(Int16 carid, Int16 competitionid) { try { DBController dbc = new DBController(); dbc.CompetitionSignUp(carid, competitionid); dbc.Close(); } catch (Exception e) { Console.WriteLine(e.ToString()); DBController dbc = new DBController(); dbc.AddLog("CompetitionSignUp?carid={carid}&competitionid={competitionid}", carid, null, competitionid, e.ToString().Substring(0, Math.Min(e.ToString().Count(), 254)), ""); dbc.Close(); } return; }
public string AddTripToCompetition(Int16 competitionid, Int16 carid, Int64 tripid) { try { DBController dbc = new DBController(); dbc.UpdateWithCompetitionAttempt(competitionid, carid, tripid); dbc.Close(); } catch (Exception e) { Console.WriteLine(e.ToString()); DBController dbc = new DBController(); dbc.AddLog("AddTripToCompetition", carid, tripid, competitionid, e.ToString().Substring(0, Math.Min(e.ToString().Count(), 254)), ""); dbc.Close(); } return "succes"; }
public void UpdateCarWithUsername(Int16 carid, string username) { try { DBController dbc = new DBController(); dbc.UpdateCarWithUsername(carid, username); dbc.Close(); } catch(Exception e) { Console.WriteLine(e.ToString()); DBController dbc = new DBController(); dbc.AddLog("UpdateCarWithUsername?carid={carid}&username={username}", carid, null, null, e.ToString().Substring(0, Math.Min(e.ToString().Count(), 254)), username); dbc.Close(); } return; }
public void AddTest(Stream facts) { try { Console.WriteLine("Message Received"); StreamReader sr = new StreamReader(facts); string text = sr.ReadToEnd(); Console.WriteLine("It was: " + text); } catch (Exception e) { Console.WriteLine(e.ToString()); DBController dbc = new DBController(); dbc.AddLog("AddTest", null, null, null, e.ToString().Substring(0, 254), e.ToString().Substring(0, Math.Min(e.ToString().Count(), 499))); dbc.Close(); return; } return; }
public string GetAllCompetitions() { try { DBController dbc = new DBController(); List<Competition> allCompetitions = dbc.GetAllCompetitions(); dbc.Close(); return JsonConvert.SerializeObject(allCompetitions); } catch (Exception e) { Console.WriteLine(e.ToString()); DBController dbc = new DBController(); dbc.AddLog("GetAllCompetitions", null, null, null, e.ToString().Substring(0, Math.Min(e.ToString().Count(), 254)), ""); dbc.Close(); } return ""; }
public string GetTripsForList(Int16 carid, int offset) { try { DBController dbc = new DBController(); List<Trip> trips = dbc.GetTripsForListByCarId(carid, offset); dbc.Close(); return JsonConvert.SerializeObject(trips); } catch (Exception e) { Console.WriteLine(e.ToString()); DBController dbc = new DBController(); dbc.AddLog("GetTripsForList?carid={carid}&offset={offset}", carid, null, null, e.ToString().Substring(0, Math.Min(e.ToString().Count(), 254)), offset.ToString()); dbc.Close(); } return ""; }
public string GetTrip(Int16 carid, Int64 tripid) { try { DBController dbc = new DBController(); Trip trip = dbc.GetTripByCarIdAndTripId(carid, tripid); dbc.Close(); return JsonConvert.SerializeObject(trip); } catch (Exception e) { Console.WriteLine(e.ToString()); DBController dbc = new DBController(); dbc.AddLog("GetTrip?carid={carid}&tripid={tripid}", carid, tripid, null, e.ToString().Substring(0, Math.Min(e.ToString().Count(), 254)), ""); dbc.Close(); } return ""; }
public string GetOrCreateCar(Int64 imei) { try { DBController dbc = new DBController(); Car car = dbc.GetCarByIMEI(imei); if (car == null) { dbc.AddNewCar(imei); Car newCar = dbc.GetCarByIMEI(imei); return JsonConvert.SerializeObject(newCar); } dbc.Close(); return JsonConvert.SerializeObject(car); } catch (Exception e) { Console.WriteLine(e.ToString()); DBController dbc = new DBController(); dbc.AddLog("GetOrCreateCar?imei={imei}", null, null, null, e.ToString().Substring(0, Math.Min(e.ToString().Count(), 254)), imei.ToString()); dbc.Close(); } return ""; }
public string GetCompetitionById(Int16 competitionid) { try { DBController dbc = new DBController(); Competition competition = dbc.GetCompetitionByCompetitionId(competitionid); dbc.Close(); return JsonConvert.SerializeObject(competition); } catch (Exception e) { Console.WriteLine(e.ToString()); DBController dbc = new DBController(); dbc.AddLog("GetCompetitionById?competitionid={competitionid}", null, null, competitionid, e.ToString().Substring(0, Math.Min(e.ToString().Count(), 254)), ""); dbc.Close(); } return ""; }
public string GetCompetitionsForListView(Int16 carid, int offset) { try { DBController dbc = new DBController(); Car car = dbc.GetCarByCarId(carid); int countrank = 1; List<CompetingIn> CompetingIns = new List<CompetingIn>(); List<Competition> competitions = dbc.GetAllCompetitionsWithOffset(offset); List<Int16> CarCompetitions = dbc.GetCompetitionIdByCarId(carid); dbc.Close(); if (!car.Username.ToLower().StartsWith("lb")) { competitions.Remove(competitions.Single(p => p.CompetitionId == 1)); } List<CompetitionView> competitionsForListView = new List<CompetitionView>(); foreach (Competition com in competitions) { CompetitionView comView = new CompetitionView(com); if (CarCompetitions.Contains(com.CompetitionId)) { comView.IsParticipating = true; } CompetingIns = dbc.GetCompetitionInByCompetitionId(com.CompetitionId); List<CompetingIn> scored = CompetingIns.Where(o => o.Attempts > 0).ToList(); List<CompetingIn> notScored = CompetingIns.Where(o => o.Attempts == 0).ToList(); List<CompetingIn> templist = scored.OrderBy(o => o.Score).ToList(); templist.AddRange(notScored); comView.ParticipantCount = templist.Count; foreach (CompetingIn compin in templist) { if (compin.CarId == carid) { comView.AttemptCount = compin.Attempts; comView.Score = compin.Score; comView.Rank = countrank; } else { countrank++; } } countrank = 1; competitionsForListView.Add(comView); } return JsonConvert.SerializeObject(competitionsForListView); } catch (Exception e) { Console.WriteLine(e.ToString()); DBController dbc = new DBController(); dbc.AddLog("GetCompetitionsForListView?carid={carid}&offset={offset}", carid, null, null, e.ToString().Substring(0, Math.Min(e.ToString().Count(), 254)), offset.ToString()); dbc.Close(); } return ""; }
public string GetCompetitionsByCarId(Int16 carid) { try { DBController dbc = new DBController(); List<Competition> carCompetitions = dbc.GetCompetitionByCarId(carid); dbc.Close(); return JsonConvert.SerializeObject(carCompetitions); } catch (Exception e) { Console.WriteLine(e.ToString()); DBController dbc = new DBController(); dbc.AddLog("GetCompetitionsByCarId?carid={carid}", carid, null, null, e.ToString().Substring(0, Math.Min(e.ToString().Count(), 254)), ""); dbc.Close(); } return ""; }
public string GetCompetitionForOverview(Int16 competitionid, Int16 carid) { try { DBController dbc = new DBController(); int countrank = 1; List<CompetingIn> CompetingIns = new List<CompetingIn>(); Competition competition = dbc.GetCompetitionByCompetitionId(competitionid); dbc.Close(); CompetitionOverview comView = new CompetitionOverview(competition); CompetingIns = dbc.GetCompetitionInByCompetitionId(competition.CompetitionId); List<CompetingIn> scored = CompetingIns.Where(o => o.Attempts > 0).ToList(); List<CompetingIn> notScored = CompetingIns.Where(o => o.Attempts == 0).ToList(); comView.Leaderboard = scored.OrderBy(o => o.Score).ToList(); comView.Leaderboard.AddRange(notScored); comView.ParticipantCount = comView.Leaderboard.Count; foreach (CompetingIn compin in comView.Leaderboard) { if (compin.CarId == carid) { comView.AttemptCount = compin.Attempts; comView.Score = compin.Score; comView.Rank = countrank; } else { countrank++; } } return JsonConvert.SerializeObject(comView); } catch (Exception e) { Console.WriteLine(e.ToString()); DBController dbc = new DBController(); dbc.AddLog("GetCompetitionForOverview?competitionid={competitionid}&carid={carid}", carid, null, competitionid, e.ToString().Substring(0, Math.Min(e.ToString().Count(), 254)), ""); dbc.Close(); } return ""; }
public string AddFacts(Stream facts) { int carIdLog = -1; Int64 tripIdLog = -1; try { //Reading the stream of data sent from client Console.WriteLine("Message Received"); StreamReader sr = new StreamReader(facts); string text = sr.ReadToEnd(); Console.WriteLine("It was: " + text); //Parsing the nested JSON objects to a JArray JArray allfacts = JArray.Parse(text) as JArray; dynamic allthefacts = allfacts; //Assigning a tripid DBController dbc = new DBController(); Int16 carId = (Int16)allthefacts[0].carid; Int64 assignedTripId = dbc.AddTripInformation(carId); dbc.Close(); carIdLog = carId; tripIdLog = assignedTripId; Console.WriteLine("Assigned TripId: " + assignedTripId); //Converting each JSON object to a Fact object List<Fact> factObjs = new List<Fact>(); foreach (dynamic fact in allthefacts) { fact.tripid = assignedTripId; factObjs.Add(new Fact(fact)); } //Add Facts to DB dbc = new DBController(); foreach (Fact f in factObjs) { dbc.AddRawFact(f); } dbc.Close(); Mapmatch.MatchTrip(carId, assignedTripId); Console.WriteLine("Trip " + assignedTripId + " was map-matched for CarId " + carId + "."); Console.WriteLine("Updating Facts for trip " + assignedTripId + "."); GPSFactUpdater.UpdateRawGPS(carId, assignedTripId); Console.WriteLine("Number of facts: " + factObjs.Count); Console.WriteLine("Updating trip " + assignedTripId + "."); TripFactUpdater.UpdateTrip(carId, assignedTripId); Console.WriteLine("Update on trip " + assignedTripId + " completed."); Car car = dbc.GetCarByCarId(carId); if (car.Username.ToLower().StartsWith("lb")) { Console.WriteLine("User is a member of the LB competition"); Console.WriteLine("Updating this tripscore in the competition"); AddTripToCompetition(1, carId, assignedTripId); Console.WriteLine("Update complete."); } } catch (Exception e) { Console.WriteLine(e.ToString()); DBController dbc = new DBController(); dbc.AddLog("AddFacts", (Int16)carIdLog, tripIdLog, null, e.ToString().Substring(0, Math.Min(e.ToString().Count(), 254)), facts.ToString().Substring(0, Math.Min(e.ToString().Count(), 499))); dbc.Close(); return "failed"; } return "succes"; }