예제 #1
0
        public void GetUsers()
        {
            // Create the manager with the api key
              Route4MeManager route4Me = new Route4MeManager(c_ApiKey);

              GenericParameters parameters = new GenericParameters()
              {
              };

              // Run the query
              string errorString;
              User[] dataObjects = route4Me.GetUsers(parameters, out errorString);

              Console.WriteLine("");

              if (dataObjects != null)
              {
            Console.WriteLine("GetUsers executed successfully, {0} users returned", dataObjects.Length);
            Console.WriteLine("");

            //dataObjects.ForEach(user =>
            //{
            //  Console.WriteLine("User ID: {0}", user.MemberId);
            //});
              }
              else
              {
            Console.WriteLine("GetUsers error: {0}", errorString);
              }
        }
        /// <summary>
        /// Get Device History from Time Range
        /// </summary>
        public void GetDeviceHistoryTimeRange(string routeId)
        {
            // Create the manager with the api key
            Route4MeManager route4Me = new Route4MeManager(c_ApiKey);

            int uStartTime = 0;
            int uEndTime = 0;
            uStartTime = (int)(new DateTime(2016, 10, 20, 0, 0, 0) - (new DateTime(1970, 1, 1, 0, 0, 0))).TotalSeconds;
            uEndTime = (int)(new DateTime(2016, 10, 26, 23, 59, 59) - (new DateTime(1970, 1, 1, 0, 0, 0))).TotalSeconds;

            GPSParameters gpsParameters = new GPSParameters
            {
                Format = "csv",
                RouteId = routeId,
                time_period = "custom",
                start_date = uStartTime,
                end_date = uEndTime
            };

            string errorString = "";
            string response = route4Me.SetGPS(gpsParameters, out errorString);

            if (!string.IsNullOrEmpty(errorString))
            {
                Console.WriteLine("SetGps error: {0}", errorString);
                return;
            }

            Console.WriteLine("SetGps response: {0}", response);

            GenericParameters genericParameters = new GenericParameters();
            genericParameters.ParametersCollection.Add("route_id", routeId);
            genericParameters.ParametersCollection.Add("device_tracking_history", "1");

            var dataObject = route4Me.GetLastLocation(genericParameters, out errorString);

            Console.WriteLine("");

            if (dataObject != null)
            {
                Console.WriteLine("GetDeviceHistoryTimeRange executed successfully");
                Console.WriteLine("");

                Console.WriteLine("Optimization Problem ID: {0}", dataObject.OptimizationProblemId);
                Console.WriteLine("State: {0}", dataObject.State);
                Console.WriteLine("");
                foreach (TrackingHistory th in dataObject.TrackingHistory)
                {
                    Console.WriteLine("Speed: {0}", th.Speed);
                    Console.WriteLine("Longitude: {0}", th.Longitude);
                    Console.WriteLine("Latitude: {0}", th.Latitude);
                    Console.WriteLine("Time Stamp: {0}", th.TimeStampFriendly);
                    Console.WriteLine("");
                }
            }
            else
            {
                Console.WriteLine("GetDeviceHistoryTimeRange error: {0}", errorString);
            }
        }
        public void TrackDeviceLastLocationHistory(string routeId)
        {
            // Create the manager with the api key
              Route4MeManager route4Me = new Route4MeManager(c_ApiKey);

              // Create the gps parametes
              GPSParameters gpsParameters = new GPSParameters()
              {
            Format          = Format.Csv.Description(),
            RouteId         = routeId,
            Latitude        = 33.14384,
            Longitude       = -83.22466,
            Course          = 1,
            Speed           = 120,
            DeviceType      = DeviceType.IPhone.Description(),
            MemberId        = 1,
            DeviceGuid      = "TEST_GPS",
            DeviceTimestamp = "2014-06-14 17:43:35"
              };

              string errorString;
              string response = route4Me.SetGPS(gpsParameters, out errorString);

              if (!string.IsNullOrEmpty(errorString))
              {
            Console.WriteLine("SetGps error: {0}", errorString);
            return;
              }

              Console.WriteLine("SetGps response: {0}", response);

              GenericParameters genericParameters = new GenericParameters();
              genericParameters.ParametersCollection.Add("route_id", routeId);
              genericParameters.ParametersCollection.Add("device_tracking_history", "1");

              var dataObject = route4Me.GetLastLocation(genericParameters, out errorString);

              Console.WriteLine("");

              if (dataObject != null)
              {
            Console.WriteLine("TrackDeviceLastLocationHistory executed successfully");
            Console.WriteLine("");

            Console.WriteLine("Optimization Problem ID: {0}", dataObject.OptimizationProblemId);
            Console.WriteLine("State: {0}", dataObject.State);
            Console.WriteLine("");

            dataObject.TrackingHistory.ForEach(th =>
            {
              Console.WriteLine("Speed: {0}",      th.Speed);
              Console.WriteLine("Longitude: {0}",  th.Longitude);
              Console.WriteLine("Latitude: {0}",   th.Latitude);
              Console.WriteLine("Time Stamp: {0}", th.TimeStampFriendly);
              Console.WriteLine("");
            });
              }
              else
              {
            Console.WriteLine("TrackDeviceLastLocationHistory error: {0}", errorString);
              }
        }