Ejemplo n.º 1
0
        public async Task EditWaypointAsync(Waypoint oldWaypoint, Waypoint newWaypoint)
        {
            //Remember the ID
            int id = Database.QueryAsync <DatabasePOI>("SELECT WaypointID FROM \"DatabasePOI\" WHERE \"Latitude\" = ? AND \"Longitude\" = ?", new object[] { oldWaypoint.Latitude, oldWaypoint.Longitude }).Result[0].WaypointID;

            await DeleteWaypoint(oldWaypoint);

            //If the exact coordinates are still in use, disregard. This shouldn't happen, but you'll never be certain
            List <DatabasePOI> exists = await Database.QueryAsync <DatabasePOI>("SELECT \"Latitude\", \"Longitude\" FROM \"DatabasePOI\" WHERE \"Latitude\" = ? AND \"Longitude\" = ?", new object[] { newWaypoint.Latitude, newWaypoint.Longitude });

            if (exists.Count != 0)
            {
                return;
            }
            DatabasePOI forDatabase;

            //Otherwises insert as Point Of Interest (Contains a name)
            if (newWaypoint is PointOfInterest)
            {
                forDatabase = DatabasePOI.ToDatabasePOIIDless(newWaypoint as PointOfInterest, id);
            }
            //Or waypoint (Without metadata)
            else
            {
                forDatabase = DatabasePOI.ToDatabasePOIIDless(newWaypoint, id);
            }
            await Database.InsertAsync(forDatabase);
        }
Ejemplo n.º 2
0
        public async Task <int> SaveWaypoint(Waypoint waypoint)
        {
            //If the exact coordinates are already used, disregard.
            List <DatabasePOI> exists = await Database.QueryAsync <DatabasePOI>("SELECT \"Latitude\", \"Longitude\" FROM \"DatabasePOI\" WHERE \"Latitude\" = ? AND \"Longitude\" = ?", new object[] { waypoint.Latitude, waypoint.Longitude });

            if (exists.Count != 0)
            {
                return(exists[0].WaypointID);
            }
            DatabasePOI forDatabase;

            //Otherwises insert as Point Of Interest (Contains at least a name)
            if (waypoint is PointOfInterest)
            {
                forDatabase = DatabasePOI.ToDatabasePOI(waypoint as PointOfInterest);
            }
            //Or waypoint (Without metadata)
            else
            {
                forDatabase = DatabasePOI.ToDatabasePOI(waypoint);
            }
            await Database.InsertAsync(forDatabase);

            return(forDatabase.WaypointID);
        }
Ejemplo n.º 3
0
 public static Waypoint ToWaypoint(DatabasePOI toConvert)
 {
     if (toConvert.Name != null)
     {
         return(new PointOfInterest(toConvert.Latitude, toConvert.Longitude, false,
                                    toConvert.Name, toConvert.Information, toConvert.ImagePath, toConvert.SoundPath));
     }
     else
     {
         return(new Waypoint(toConvert.Latitude, toConvert.Longitude));
     }
 }
Ejemplo n.º 4
0
        private async Task <List <Waypoint> > getAssociatedWaypointsAsync(string routeName)
        {
            int routeID = Database.ExecuteScalarAsync <int>("SELECT \"RouteID\" FROM \"DatabaseRoute\" WHERE \"Name\" = ?", new object[] { routeName }).Result;
            List <RouteBind> waypointsID = Database.QueryAsync <RouteBind>("SELECT \"WaypointID\" FROM \"RouteBinds\" WHERE \"RouteID\" = ?", new object[] { routeID }).Result;
            List <Waypoint>  retVal      = new List <Waypoint>();

            foreach (RouteBind r in waypointsID)
            {
                List <DatabasePOI> temp = Database.QueryAsync <DatabasePOI>("SELECT * FROM DatabasePOI WHERE WaypointID = ?", new object[] { r.WaypointID }).Result;
                retVal.Add(DatabasePOI.ToWaypoint(temp[0]));
            }
            return(retVal);
        }
Ejemplo n.º 5
0
        public async Task EditRouteAsync(string oldRouteName, Route newRoute)
        {
            //Remember the Database ID of the route
            int id = Database.QueryAsync <DatabaseRoute>("SELECT * FROM \"DatabaseRoute\" WHERE \"Name\" = ? AND RouteID <> 999 AND RouteID <> 998", new object[] { oldRouteName }).Result[0].RouteID;

            //And remove it
            await DeleteRouteAsync(oldRouteName);

            //Now create & insert the new route
            DatabaseRoute forDatabase = DatabaseRoute.ToDatabaseRouteIDless(newRoute, id);
            await Database.InsertAsync(forDatabase);

            //Then bind the waypoints
            foreach (Waypoint newWaypoint in newRoute.WayPoints)
            {
                int existingID = await Database.ExecuteScalarAsync <int>("SELECT WaypointID FROM DatabasePOI WHERE Latitude = ? AND Longitude = ?", new object[] { newWaypoint.Latitude, newWaypoint.Longitude });

                if (existingID == 0)
                {
                    //In the case it's a new waypoint, save and bind to this route
                    int waypointID = await SaveWaypoint(newWaypoint);

                    await Database.ExecuteAsync("INSERT INTO RouteBinds VALUES(?, ?)", new object[] { forDatabase.RouteID, waypointID });
                }
                else
                {
                    //But if it exists, edit waypoint if neccesary, check if the bind persisted and then insert
                    await EditWaypointAsync(DatabasePOI.ToWaypoint(
                                                Database.QueryAsync <DatabasePOI>("SELECT * FROM DatabasePOI WHERE Latitude = ? AND Longitude = ?", new object[] { newWaypoint.Latitude, newWaypoint.Longitude }).Result[0])
                                            , newWaypoint);

                    List <RouteBind> binds = await Database.QueryAsync <RouteBind>("SELECT WaypointID FROM RouteBinds WHERE RouteID = ? AND RouteID <> 999 AND RouteID <> 998 AND WaypointID = ?", new object[] { id, existingID });

                    if (binds.Count == 0)
                    {
                        await Database.ExecuteAsync("INSERT INTO RouteBinds VALUES(?, ?)", new object[] { forDatabase.RouteID, existingID });
                    }
                }
            }
            //In the case this is the active route, replace.
            Route currentRoute = await GetCurrentRoute();

            if (currentRoute != null && currentRoute.Name == oldRouteName)
            {
                await SaveCurrentRouteAsync(newRoute);
            }
        }
Ejemplo n.º 6
0
 public static Waypoint ToWaypoint(DatabasePOI toConvert)
 {
     if (toConvert.Name != null)
         return new PointOfInterest(toConvert.Latitude, toConvert.Longitude, false,
                                    toConvert.Name, toConvert.Information, toConvert.ImagePath,toConvert.SoundPath);
     else
         return new Waypoint(toConvert.Latitude, toConvert.Longitude);
 }