public void OnDataChange(DataSnapshot snapshot) { if (!snapshot.Exists()) { return; } string ride_id = snapshot.Child("ride_id").Value.ToString(); if (ride_id != "waiting" && ride_id != "timeout" && ride_id != "cancelled") { //Ride Assigned RideAssigned?.Invoke(this, new RideAssignedIDEventArgs { RideId = ride_id }); } else if (ride_id == "timeout") { // Ride Timeout RideTimedOut?.Invoke(this, new TimeoutMessageArgs { Message = "Ride timeout" }); } else if (ride_id == "cancelled") { //ride cancelled RideCancelled?.Invoke(this, new RideCancelledArgs { ShowWhy = null }); } }
public void Create(CLLocationCoordinate2D location) { var locationCordinate = new NSDictionary ( "latitude", location.Latitude.ToString(), "longitude", location.Longitude.ToString() ); var driverInfo = new NSDictionary ( "location", locationCordinate, "ride_id", "waiting" ); driverAvailableRef = Database.DefaultInstance.GetRootReference().GetChild("driversAvailable/" + AppDataHelper.GetDriverID()); driverAvailableRef.SetValue <NSDictionary>(driverInfo); driverAvailableRef.ObserveEvent(DataEventType.Value, (DataSnapshot snapshot) => { if (snapshot.GetValue <NSObject>() != NSNull.Null) { if (snapshot.GetChildSnapshot("ride_id").GetValue <NSObject>() != NSNull.Null) { string ride_id = snapshot.GetChildSnapshot("ride_id").GetValue <NSObject>().ToString(); if (ride_id != "waiting" && ride_id != "timeout" && ride_id != "cancelled") { // Ride has been assigned to us if (!rideAssigned) { GetRideDetails(ride_id); rideAssigned = true; } } else if (ride_id == "timeout") { // timeout RideTimedOut?.Invoke(this, new EventArgs()); rideAssigned = false; ReActivate(); } else if (ride_id == "cancelled") { // cancelled; RideCancelled?.Invoke(this, new EventArgs()); rideAssigned = false; ReActivate(); } } } }); }
public void OnDataChange(DataSnapshot snapshot) { if (snapshot.Value != null) { string rideId = snapshot.Child("ride_id").Value.ToString(); if (rideId != "waiting" && rideId != "timeout" && rideId != "cancelled") { RideAssigned?.Invoke(this, new RideAssignedIdEventArgs { RideId = rideId }); } else if (rideId == "timeout") { RideTimedOut?.Invoke(this, new EventArgs()); } else if (rideId == "cancelled") { RideCancelled?.Invoke(this, new EventArgs()); } } }