Exemplo n.º 1
0
 private string AddLocation(string dbName, string dbUserName, string dbPassWord, TripChainJson tj, out string statusMessage)
 {
     statusMessage = null;
     string result = null;
     try
     {
         MongoDatabase resultDB = GetMongoDatabase(dbName, dbUserName, dbPassWord);
         if (resultDB == null)
         {
             statusMessage = "Database is null";
             return result;
         }
         MongoCollection<Location> locations = resultDB.GetCollection<Location>("locations");
         string locID = MakeId(tj.latitude.ToString(), tj.longitude.ToString());
         Location newLoc = new Location
         {
             locationID = locID,
             longitude = tj.longitude,
             latitude = tj.latitude
         };
         locations.Insert(newLoc);
         result = locID;
     }
     catch (Exception e)
     {
         result = null;
         statusMessage = "An exception has occured in AddLocation method. " + e.Message;
     }
     return result;
 }
Exemplo n.º 2
0
        public string ExtractTripData(long id, UserLegitimation user, Person person, TripJson trip, out Trip tripData, out List<TripChainJson> locations, out List<TransportModeJson> modes, out string statusMessage)
        {
            statusMessage = null;
            tripData = new Trip();
            locations = new List<TripChainJson>();
            modes = new List<TransportModeJson>();
            try
            {
                tripData.tripID = id.ToString();
                if (trip.meta != null)
                {
                    tripData.tripDate = new DateTime(1970, 1, 1) + new TimeSpan(trip.meta.startTime * 10000);
                    tripData.distance = trip.meta.distance;
                    tripData.tripPurposeId = trip.meta.purpose;
                }
                if (trip.entries != null)
                {
                    foreach (var e in trip.entries)
                    {
                        TripChainJson tcjs = new TripChainJson()
                        {
                            timestamp = e.timestamp,
                            latitude = e.latitude,
                            longitude = e.longitude,
                            altitude = e.altitude,
                            accuracy = e.accuracy,
                            altitudeAccuracy = e.altitudeAccuracy,
                            heading = e.heading,
                            speed = e.speed
                        };
                        locations.Add(tcjs);
                    }
                }

                if (trip.modes != null)
                {
                    foreach (var m in trip.modes)
                    {
                        TransportModeJson tmjs = new TransportModeJson()
                        {
                            time = m.time,
                            mode = m.mode
                        };
                        modes.Add(tmjs);
                    }
                }
            }
            catch (Exception e)
            {
                statusMessage = "An exception has occured in ExtractTripData method. " + e.Message;
            }
            return statusMessage;
        }