Esempio n. 1
0
        public static Trip FromXElement(XElement tEle)
        {
            Trip t = new Trip();
            t.TripID = Convert.ToInt32(tEle.Attribute("id").Value);
            t.Name = tEle.Element("name").Value;
            t.UserID = Convert.ToInt32(tEle.Element("user").Attribute("id").Value);
            t.UserName = tEle.Element("user").Value;

            t.TripActivity = new Activity();
            t.TripActivity.ID = Convert.ToInt32(tEle.Element("activity").Attribute("id").Value);
            t.TripActivity.Name = tEle.Element("activity").Value;

            t.Description = tEle.Element("description").Value.Trim();
            t.Tips = tEle.Element("tips").Value.Trim();

            t.TripDate = DateTime.Parse(tEle.Element("date").Value);

            if (tEle.Element("updated_date") != null)
            {
                DateTime updatedDate = DateTime.MinValue;
                DateTime.TryParse(tEle.Element("updated_date").Value, out updatedDate);
                t.TripUpdatedDate = updatedDate;
            }

            t.Length = new Length();
            t.Length.Amount = double.Parse(tEle.Element("length").Value);
            // if this changes at some point this will need to actually check
            t.Length.Units = Length.LengthUnits.Metric;

            t.Duration = new TimeSpan(0, 0, Convert.ToInt32(tEle.Element("duration").Value));

            if (tEle.Element("visibility") != null)
            {
                t.Visible = Convert.ToBoolean(Convert.ToInt32(tEle.Element("visibility").Value));
            }

            t.Rating = new TripRating();
            t.Rating.NumberVotes = Convert.ToInt32(tEle.Element("rating").Attribute("votes").Value);
            t.Rating.OverallRating = double.Parse(tEle.Element("rating").Value);

            t.TripLocation = new Location();
            t.TripLocation.Description = tEle.Element("location").Value;
            t.TripLocation.Latitude = double.Parse(tEle.Element("location").Attribute("lat").Value);
            t.TripLocation.Longitude = double.Parse(tEle.Element("location").Attribute("lon").Value);

            t.GPXLocation = tEle.Element("gpx").Value;

            if (tEle.Element("kml") != null)
            {
                t.Kml = tEle.Element("kml").Value;
            }
            return t;
        }
        public Trip SingleTrip(int tripId)
        {
            Trip result = new Trip();

            List<EveryTrailRequestParameter> requestParams = new List<EveryTrailRequestParameter>();
            requestParams = new List<EveryTrailRequestParameter>();
            requestParams.Add(new EveryTrailRequestParameter() { Name = "trip_id", Value = tripId });

            EveryTrailResponse response = EveryTrailRequest.MakeRequest(_singleTrip, requestParams);

            if (response.SuccessfulConnection)
            {
                XDocument xResponse = XDocument.Load(response.ResponseStream);

                XElement tripEle = xResponse.Element("etTripResponse").Element("trip");

                if (tripEle != null)
                {
                    result = Trip.FromXElement(xResponse.Element("etTripResponse").Element("trip"));
                }
            }
            return result;
        }