Ejemplo n.º 1
0
        /// <summary>
        /// Quick function to animate the camera to a location
        /// on the map.
        /// </summary>
        /// <param name="lat">Latitude to move to.</param>
        /// <param name="lon">Longitude to move to.</param>
        /// <param name="zoom">Level to zoom to over 100ms.</param>
        public void AnimateCameraTo(double lat, double lon, float zoom = 0)
        {
            try
            {
                if (zoom == 0)
                {
                    zoom = KCApi.Properties.Renderer.NativeMap.CameraPosition.Zoom;
                }

                Device.BeginInvokeOnMainThread(() =>
                {
                    if (KCApi.Properties.MapReady && KCApi.Properties.RenderReady && NativeMap != null)
                    {
                        lock (nativeMapLock)
                        {
                            NativeMap.AnimateCamera(CameraUpdateFactory.NewLatLngZoom(new LatLng(lat, lon), zoom), 100, null);
                        }
                    }
                });
            }
            catch (Exception e)
            {
                KCApi.OutputException(e);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// If the driver already has a ride it sets the ride id to that ride
        /// in case of failure or lost connection.
        /// </summary>
        /// <param name="ride">Ride object to store recovery info in.</param>
        /// <returns>True upon receipt of a success response, false otherwise.</returns>
        public static bool RecoveryCheck(Ride ride)
        {
            string message = "https://" + ip + "/driver/recoveryCheck.php?token=" + Driver_Id.token + "&driverID=" + Driver_Id.driver_Id;
            // Create a request for the URL.
            WebRequest request = WebRequest.Create(message);

            request.Timeout = timeout;

            // Get the response.
            string responseFromServer = "";

            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                // Get the stream containing content returned by the server.
                Stream dataStream = response.GetResponseStream();
                // Open the stream using a StreamReader for easy access.
                StreamReader reader = new StreamReader(dataStream);
                // Read the content.
                responseFromServer = reader.ReadToEnd();
                // Cleanup the streams and the response.
                reader.Close();
                dataStream.Close();
                response.Close();

                dynamic jObject = null;
                if (!responseFromServer.Contains("Failure") && !responseFromServer.Contains("No"))
                {
                    jObject = JObject.Parse(responseFromServer);

                    ride.SetRideID(Int32.Parse((string)jObject.result.rideID));
                    ride.SetRidePhoneNum((string)jObject.result.phone);
                    ride.SetName((string)jObject.result.name);
                    return(true);
                }
                //If the response comes back as Authentication failure then set the driver as not authenticated.
                else if (responseFromServer.Contains("Authentication failure"))
                {
                    Driver_Id.authenticated = false;
                    return(false);
                }

                return(false);
            }
            catch (WebException)
            {
                lock (Properties.NetworkStateLock)
                    KCApi.Properties.NetState = KCProperties.NetworkState.Disconnected;

                return(false);
            }
            catch (Exception e)
            {
                KCApi.OutputException(e);
                return(false);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Attempts to authenticate the user. Returns true if the user
        /// is authenticated with the server, false upon error or rejection.
        /// </summary>
        /// <param name="password">Password to include in the query.</param>
        /// <param name="userName">Username to include in the query.</param>
        /// <returns></returns>
        public static bool Authenticate(string password, string userName)
        {
            string message            = "https://" + ip + "/driver/auth/authenticate.php?username="******"&pwHsh=" + GetHash(password, userName);
            string responseFromServer = "";

            try
            {
                // Create a request for the URL.
                WebRequest request = WebRequest.Create(message);
                request.Timeout = timeout;
                // Get the response.
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                // Get the stream containing content returned by the server.
                Stream dataStream = response.GetResponseStream();
                // Open the stream using a StreamReader for easy access.
                StreamReader reader = new StreamReader(dataStream);
                // Read the content.
                responseFromServer = reader.ReadToEnd();
                // Cleanup the streams and the response.
                reader.Close();
                dataStream.Close();
                response.Close();
                dynamic jObject = null;

                if (!responseFromServer.Contains("Failure"))
                {
                    jObject = JObject.Parse(responseFromServer);

                    Driver_Id.driver_Id     = Int32.Parse((string)jObject.result.driverID);
                    Driver_Id.token         = (string)jObject.result.token;
                    Driver_Id.authenticated = true;

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (WebException)
            {
                lock (Properties.NetworkStateLock)
                    KCApi.Properties.NetState = KCProperties.NetworkState.Disconnected;

                return(false);
            }
            catch (Exception e)
            {
                KCApi.OutputException(e);
                return(false);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Updates the remote server on the current location of the driver without getting ride info.
        /// </summary>
        /// <param name="latitude">Current latitude of the driver.</param>
        /// <param name="longitude">Current longitude of the driver.</param>
        /// <returns></returns>
        public static bool SetDriverLocation(double latitude, double longitude)
        {
            string message = "https://" + ip + "/driver/updateLocation.php?driverID=" + Driver_Id.driver_Id
                             + "&token=" + Driver_Id.token + "&lat=" + latitude + "&lon=" + longitude;
            string responseFromServer = "";

            try
            {
                // Create a request for the URL.
                WebRequest request = WebRequest.Create(message);
                request.Timeout = timeout;
                // Get the response.
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                // Get the stream containing content returned by the server.
                Stream dataStream = response.GetResponseStream();
                // Open the stream using a StreamReader for easy access.
                StreamReader reader = new StreamReader(dataStream);
                // Read the content.
                responseFromServer = reader.ReadToEnd();
                // Cleanup the streams and the response.
                reader.Close();
                dataStream.Close();
                response.Close();
            }
            catch (WebException)
            {
                lock (Properties.NetworkStateLock)
                    KCApi.Properties.NetState = KCProperties.NetworkState.Disconnected;

                return(false);
            }
            catch (Exception e)
            {
                KCApi.OutputException(e);
                return(false);
            }

            //If the response comes back as Authentication failure then set the driver as not authenticated.
            if (responseFromServer.Contains("Authentication failure") || responseFromServer.Contains("Unable to authenticate"))
            {
                Driver_Id.authenticated = false;
                return(false);
            }
            if (!responseFromServer.Contains("error"))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the salt for a user in order to hash their password.
        /// </summary>
        /// <param name="userName">Username from which to get the salt.</param>
        /// <returns>string containing the salt.</returns>
        public static string GetSalt(string userName)
        {
            string message            = "https://" + ip + "/driver/auth/getSalt.php?username="******"";

            try
            {
                // Create a request for the URL.
                WebRequest request = WebRequest.Create(message);
                request.Timeout = timeout;
                // Get the response.
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                // Display the status.
                // Get the stream containing content returned by the server.
                Stream dataStream = response.GetResponseStream();
                // Open the stream using a StreamReader for easy access.
                StreamReader reader = new StreamReader(dataStream);
                // Read the content.
                responseFromServer = reader.ReadToEnd();
                // Display the content.
                // Cleanup the streams and the response.
                reader.Close();
                dataStream.Close();
                response.Close();

                dynamic jObject = null;
                if (!responseFromServer.Contains("Failure"))
                {
                    jObject = JObject.Parse(responseFromServer);
                    return((string)jObject.result.pwSlt);
                }
                else
                {
                    return("error");
                }
            }
            catch (WebException)
            {
                lock (Properties.NetworkStateLock)
                    KCApi.Properties.NetState = KCProperties.NetworkState.Disconnected;

                return("No Internet connection.");
            }
            catch (Exception e)
            {
                KCApi.OutputException(e);
                return("Error Connecting to Server");
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Decouples the driver from the ride and puts the ride back in the queue.
        /// </summary>
        /// <param name="ride">Ride object to cancel.</param>
        /// <returns>True upon receipt of a success response, false otherwise.</returns>
        public static bool CancelRide(Ride ride)
        {
            string message = "https://" + ip + "/driver/decouple.php?" + "rideID=" + ride.RideId + "&token=" + Driver_Id.token +
                             "&driverID=" + Driver_Id.driver_Id;
            string responseFromServer = "";
            // Create a request for the URL.
            WebRequest request = WebRequest.Create(message);

            request.Timeout = timeout;

            try
            {
                // Get the response.
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                // Get the stream containing content returned by the server.
                Stream dataStream = response.GetResponseStream();
                // Open the stream using a StreamReader for easy access.
                StreamReader reader = new StreamReader(dataStream);
                // Read the content.
                responseFromServer = reader.ReadToEnd();
                // Cleanup the streams and the response.
                reader.Close();
                dataStream.Close();
                response.Close();
            }
            catch (WebException)
            {
                lock (Properties.NetworkStateLock)
                    KCApi.Properties.NetState = KCProperties.NetworkState.Disconnected;

                return(false);
            }
            catch (Exception e)
            {
                KCApi.OutputException(e);
                return(false);
            }


            if (!responseFromServer.Contains("error"))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Moves the camera directly to the given coordinates.
 /// </summary>
 /// <param name="lat">Latitude to move to.</param>
 /// <param name="lon">Longitude to move to.</param>
 public void MoveCameraTo(double lat, double lon)
 {
     try
     {
         Device.BeginInvokeOnMainThread(() =>
         {
             if (KCApi.Properties.MapReady && KCApi.Properties.RenderReady && NativeMap != null)
             {
                 lock (nativeMapLock)
                 {
                     NativeMap.MoveCamera(CameraUpdateFactory.NewLatLng(new LatLng(lat, lon)));
                 }
             }
         });
     }
     catch (Exception e)
     {
         KCApi.OutputException(e);
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Function to update the GoogleMap with the new
 /// position of the rider marker.
 /// </summary>
 public void UpdateMarker()
 {
     lock (nativeMapLock)
     {
         Device.BeginInvokeOnMainThread(() =>
         {
             try
             {
                 NativeMap.Clear();
                 riderPin = KCPin.CreateRiderPin(new Position(KCApi.Properties.CurrentRide.ClientLat,
                                                              KCApi.Properties.CurrentRide.ClientLong));
                 MarkerOptions mo = riderPin.CreateMarker();
                 NativeMap.AddMarker(mo);
             }
             catch (Exception e)
             {
                 KCApi.OutputException(e);
             }
         });
     }
 }
Ejemplo n.º 9
0
        //Timer which checks if the driver is still authenticated if they aren't it kicks them back to the login page.
        public void CheckActive(Object source, ElapsedEventArgs e)
        {
            if (KCApi.Properties.State != KCProperties.AppState.Map)
            {
                return;
            }

            Task.Run(() =>
            {
                try
                {
                    bool pop = false;
                    if (!Driver_Id.authenticated && KCApi.Properties.RideStatus == KCProperties.RideStatuses.Active)
                    {
                        pop = true;
                    }
                    //If the ride is inactive then pop back to the Accept page.
                    else if (KCApi.Properties.RideStatus != KCProperties.RideStatuses.Active && KCApi.Properties.RenderReady)
                    {
                        if (KCApi.Properties.RideStatus == KCProperties.RideStatuses.CanceledByRider)
                        {
                            var text = "Rider has cancelled ride.";
                            Device.BeginInvokeOnMainThread(() =>
                            {
                                Toast.MakeText(CrossCurrentActivity.Current.Activity, text, ToastLength.Short).Show();
                            });
                        }


                        pop = true;
                    }
                    else if (KCApi.Properties.NetState == KCProperties.NetworkState.Disconnected)
                    {
                        var text = "Internet connection lost.";
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            Toast.MakeText(CrossCurrentActivity.Current.Activity, text, ToastLength.Short).Show();
                        });

                        pop = true;
                    }

                    if (pop)
                    {
                        KCApi.Stop();
                        activeTimer.Stop();

                        lock (KCApi.Properties.StateLock)
                        {
                            KCApi.Properties.State = KCProperties.AppState.Transitioning;

                            Device.BeginInvokeOnMainThread(async() =>
                            {
                                await Navigation.PopAsync();
                            });
                        }
                    }
                    else
                    {
                        activeTimer.Interval = 100.0f; // Can be optimized
                    }
                }

                catch (Exception ex)
                {
                    KCApi.OutputException(ex);
                }
            });
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Sets the clients postion in the given Ride by querying
        /// the remote server
        /// </summary>
        /// <param name="ride">The ride to store the location retrieved in.</param>
        /// <param name="latitude">Current latitude of the driver.</param>
        /// <param name="longitude">Current longitude of the driver.</param>
        /// <returns>True upon success, false upon failure</returns>
        public static bool SetRideLocation(Ride ride, double latitude = 0, double longitude = 0)
        {
            string message = "https://" + ip + "/driver/rideStatus.php?driverID=" + Driver_Id.driver_Id
                             + "&token=" + Driver_Id.token + "&rideID=" + ride.RideId;

            if (Properties.CurrentPosition.Latitude != 0 ||
                Properties.CurrentPosition.Longitude != 0)
            {
                message += "&lat=" + latitude + "&lon=" + longitude;
            }

            // Create a request for the URL.
            WebRequest request = WebRequest.Create(message);

            request.Timeout = timeout;
            // Get the response.
            string responseFromServer = "";

            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                // Get the stream containing content returned by the server.
                Stream dataStream = response.GetResponseStream();
                // Open the stream using a StreamReader for easy access.
                StreamReader reader = new StreamReader(dataStream);
                // Read the content.
                responseFromServer = reader.ReadToEnd();
                // Cleanup the streams and the response.
                reader.Close();
                dataStream.Close();
                response.Close();
            }
            catch (WebException)
            {
                lock (Properties.NetworkStateLock)
                    KCApi.Properties.NetState = KCProperties.NetworkState.Disconnected;

                return(false);
            }
            catch (Exception e)
            {
                KCApi.OutputException(e);
                return(false);
            }

            //If the response comes back as Authentication failure then set the driver as not authenticated.
            if (responseFromServer.Contains("Authentication failure") || responseFromServer.Contains("Unable to authenticate"))
            {
                Driver_Id.authenticated = false;
                return(false);
            }
            // If the response is "Ride not found", the user has canceled.
            else if (responseFromServer.Contains("Ride not found"))
            {
                Properties.RideStatus = KCProperties.RideStatuses.CanceledByRider;
            }
            //check if there are any other errors
            else if (!responseFromServer.Contains("error"))
            {
                try
                {
                    //If there are no errors add the lat and long to the ride class and return true.\
                    dynamic jObject = JObject.Parse(responseFromServer);

                    double rideLat  = Double.Parse((string)jObject.result.lat);
                    double rideLong = Double.Parse((string)jObject.result.lon);

                    ride.SetPosition(rideLat, rideLong);
                    return(true);
                }
                catch (Exception e)
                {
                    KCApi.OutputException(e);
                    return(false);
                }
            }

            return(false);
        }