Ejemplo n.º 1
0
        /// <summary>
        /// Converts an xml document to a Route object.
        /// </summary>
        /// <param name="xdoc">
        /// The input GPS document.
        /// </param>
        /// <param name="forceName">
        /// If parameter is false, the program will try to extract the name from the uploaded file.
        /// </param>
        /// <returns>
        /// An object of <see cref="Route">Route</see> type.
        /// </returns>
        public Route ConvertXmlDocumentToRoute(XDocument xdoc, bool forceName)
        {
            var resultRoute = new Route(-1);
            _xdoc = xdoc;

            DetermineGpxRouteFormat();

            if (!forceName)
            {
                resultRoute.Name = ExtractName();
            }

            resultRoute.Time = ExtractTime();

            resultRoute.TrackPoints = ExtractTrackPoints();
            resultRoute.GpxData = xdoc.ToString();
            return resultRoute;
        }
        public Route GetById(int routeId, Guid userId)
        {
            Route result = null;
            aspnetdbDataContext aspdb = new aspnetdbDataContext();
            var query = from r in aspdb.RouteLinqs
                           where r.UserId == userId && r.RouteId==routeId
                           select r;
            var first=query.FirstOrDefault();
            if (first != null)
            {
                result = new Route(routeId)
                {
                    Name = first.SourceName,
                    Time = first.CreationTime ?? new DateTime()
                };

                result.TrackPoints = GetTrackPointsForRoute(routeId);
            }
            return result;
        }
        public List<Route> GetAllForUser(Guid userId)
        {
            var result = new List<Route>();
            aspnetdbDataContext aspdb = new aspnetdbDataContext();
            var res = from r in aspdb.RouteLinqs
                          where r.UserId == userId
                          select r;
            foreach (var row in res)
            {
                var routeId = (int)row.RouteId;
                var route = new Route(routeId)
                                {
                                    Name = (string)row.SourceName,
                                    Time = row.CreationTime is DBNull ? new DateTime() : Convert.ToDateTime(row.CreationTime)
                                };

                route.TrackPoints = GetTrackPointsForRoute(routeId);
                result.Add(route);
            }

            return result;
        }
        public int Save(Route route)
        {
            aspnetdbDataContext aspdb = new aspnetdbDataContext();
            RouteLinq rtlq=new RouteLinq();
            rtlq.UserId = route.UserId;
            rtlq.SourceName = route.Name;
            rtlq.GpxData = XElement.Parse(route.GpxData);
            //---------------------------
            rtlq.CreationTime = route.Time;
            aspdb.RouteLinqs.InsertOnSubmit(rtlq);
            aspdb.SubmitChanges();
            //Probieren ob das Einfügen Erfolgreich durchgeführt wurde oder nicht
            int k1;
            System.Data.Linq.ChangeSet cs1 = aspdb.GetChangeSet();
            k1=cs1.Inserts.Count();
            //---Die Suche nach ID
            var res = (from p in aspdb.RouteLinqs
                       orderby p.RouteId descending
                       select p.RouteId).Take(1);
            route.Id =Convert.ToInt32(res.FirstOrDefault());
            //------------------------------------------------------

            foreach (var trackpoint in route.TrackPoints)
            {
                TrackPointlinq trlq = new TrackPointlinq();
                trlq.RouteFK = route.Id;
                trlq.TrackTime = trackpoint.Time;
                trlq.Latitude = (float)trackpoint.Latitude;
                trlq.Longitude = (float)trackpoint.Longitude;
                trlq.Elevation = trackpoint.Elevation;
                aspdb.TrackPointlinqs.InsertOnSubmit(trlq);
                aspdb.SubmitChanges();
            }

            //Probieren ob das Einfügen Erfolgreich durchgeführt wurde oder nicht
            int k2;
            System.Data.Linq.ChangeSet cs2 = aspdb.GetChangeSet();
            k2 = cs2.Inserts.Count();
            //------------------------------------------------------
            if ((k1 == 0) && (k2 == 0))
            {
                return 1;
            }
            else
                return 0;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets all routes for the selected user.
        /// </summary>
        /// <param name="userId">
        /// The user id.
        /// </param>
        /// <returns>
        /// A list of retrieved routes.
        /// </returns>
        public List<Route> GetAllForUser(Guid userId)
        {
            var result = new List<Route>();
            var inputParams = new Dictionary<string, object> { { "UserId", userId } };
            var routesTable = _dbhelper.Select("SELECT [RouteId],[UserId],[SourceName],[CreationTime] FROM [Routes] WHERE UserId=@UserId", inputParams);

            foreach (DataRow row in routesTable.Rows)
            {
                var routeId = (int)row["RouteId"];

                var route = new Route(routeId)
                    {
                        Name = (string)row["SourceName"],
                        Time = row["CreationTime"] is DBNull ? new DateTime() : Convert.ToDateTime(row["CreationTime"]),
                        TrackPoints = this.GetTrackPointsForRoute(routeId)
                    };

                result.Add(route);
            }

            return result;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Saves the route to the data store.
        /// </summary>
        /// <param name="route">
        /// The route.
        /// </param>
        /// <returns>
        /// Numbers of rows affected in the data store.
        /// </returns>
        public int Save(Route route)
        {
            var inputParams = new Dictionary<string, object>
                {
                    { "UserId", route.UserId },
                    { "SourceName", route.Name },
                    { "GpxData", route.GpxData },
                    { "CreationTime", route.Time }
                };

            if (_dbhelper.ExecuteNonQuery("INSERT INTO [Routes] (UserId, SourceName, GpxData, CreationTime) VALUES (@UserId, @SourceName, @GpxData, @CreationTime);", inputParams) > 0)
            {
                route.Id = (int)_dbhelper.ExecuteScalar("SELECT TOP 1 [RouteId] FROM [Routes] ORDER BY [RouteId] DESC");
            }
            else
            {
                throw new InvalidOperationException("New route insertion failed");
            }

            foreach (var trackPoint in route.TrackPoints)
            {
                inputParams = new Dictionary<string, object>
                                  {
                                      {"RouteFK", route.Id},
                                      {"TrackTime", trackPoint.Time},
                                      {"Latitude", trackPoint.Latitude},
                                      {"Longitude", trackPoint.Longitude},
                                      {"Elevation", trackPoint.Elevation}
                                  };

                _dbhelper.ExecuteNonQuery("INSERT INTO [TrackPoints] (RouteFK, TrackTime, Latitude, Longitude, Elevation) VALUES (@RouteFK, @TrackTime, @Latitude, @Longitude, @Elevation)", inputParams);
            }

            return 1;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Get a route for a specified user by id.
        /// </summary>
        /// <param name="routeId">
        /// The route id.
        /// </param>
        /// <param name="userId">
        /// The user id.
        /// </param>
        /// <returns>
        /// Route that belongs to the specified user and corresponds to thre requested route id.
        /// </returns>
        public Route GetById(int routeId, Guid userId)
        {
            Route result = null;
            var inputParams = new Dictionary<string, object>
                                  {
                                      {"UserId", userId},
                                      {"RouteId", routeId}
                                  };

            var routesTable = _dbhelper.Select("SELECT [RouteId],[UserId],[SourceName],[CreationTime] FROM [Routes] WHERE UserId=@UserId AND RouteId=@RouteId", inputParams);

            if (routesTable.Rows.Count == 1)
            {
                result = new Route(routeId)
                {
                    Name = (string)routesTable.Rows[0]["SourceName"],
                    Time = routesTable.Rows[0]["CreationTime"] is DBNull ? new DateTime() : Convert.ToDateTime(routesTable.Rows[0]["CreationTime"])
                };

                result.TrackPoints = GetTrackPointsForRoute(routeId);
            }

            return result;
        }
 public int Save(Route route)
 {
     route.Id = new Random().Next();
        _routesDb.Add(route);
     return 1;
 }
        public void InitializeRoutesManagerTests()
        {
            // Add a route just for test purposes
            var route = new Route(1)
                            {
                                Name = "TestRoute",
                                Time = new DateTime(2012, 06, 01),
                                UserId = _userGuid,
                                TrackPoints = new List<TrackPoint>
                                                  {
                                                      new TrackPoint
                                                          {
                                                              Elevation = 2.45f,
                                                              Id = 1,
                                                              Latitude = 38.56477415,
                                                              Longitude = 40.454678457,
                                                              Time = new DateTime(2012, 06, 01)
                                                          },
                                                      new TrackPoint
                                                          {
                                                              Elevation = 1.94f,
                                                              Id = 2,
                                                              Latitude = 38.52477415,
                                                              Longitude = 41.054678457,
                                                              Time = new DateTime(2012, 06, 01)
                                                          }
                                                  }
                            };

            _routesRepositoryMock.Save(route);

            route = new Route(2)
            {
                Name = "TestRoute",
                Time = DateTime.Now,
                UserId = _userGuid,
                TrackPoints = new List<TrackPoint>
                                                  {
                                                      new TrackPoint
                                                          {
                                                              Elevation = 1.75f,
                                                              Id = 3,
                                                              Latitude = 45.457314474,
                                                              Longitude = 34.2123154,
                                                              Time = DateTime.Now
                                                          },
                                                      new TrackPoint
                                                          {
                                                              Elevation = 1.94f,
                                                              Id = 4,
                                                              Latitude = 50.4232352352,
                                                              Longitude = 32.123534523,
                                                              Time = DateTime.Now
                                                          }
                                                  }
            };

            _routesRepositoryMock.Save(route);

            _routesManager = new RoutesManager(_routesRepositoryMock, _userGuid);
        }