Пример #1
0
        /// <summary>        
        /// </summary>
        /// <param name="user"></param>
        /// <param name="trip"></param>
        /// <param name="tripChain"></param>
        /// <returns></returns>
        public string UpdateTripDataREST(long id, UserLegitimation user, Person person, TripJson trip)
        {
            string statusMessage = null;
            Trip tripData = new Trip();
            List<TripChainJson> locations = new List<TripChainJson>();
            List<TransportModeJson> modes = new List<TransportModeJson>();

            try
            {
                statusMessage = ExtractTripData(id, user, person, trip, out tripData, out locations, out modes, out statusMessage);
                if (statusMessage == null)
                {
                    InsertTripData(_dbName, _userName, _passWord, user, person, tripData, locations, modes, false, out statusMessage);
                    if (statusMessage == null)
                        statusMessage = "ok";
                }
            }
            catch (Exception e)
            {
                statusMessage += "An exception has occured in UpdateTripDataREST method. " + e.Message;
            }
            //if (statusMessage != null)
            //    File.AppendAllText(@"C:\logs.txt", Environment.NewLine + "<statusMessage - " + DateTime.Now + ">: " + statusMessage);
            return statusMessage;
        }
Пример #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;
        }