Exemplo n.º 1
0
        private void GetDrivers()
        {
            Action <Dictionary <string, DriverModel> > onValueEvent = null;

            onValueEvent = (Dictionary <string, DriverModel> drivers) =>
            {
                try
                {
                    System.Diagnostics.Debug.WriteLine("---> EVENT GetDataFromFirebase ");

                    Action onSetValueSuccess = () =>
                    {
                    };

                    Action <string> onSetValueError = (string errorDesc) =>
                    {
                    };

                    if (drivers == null)
                    {
                        mainmap.Pins.Clear();
                        DriversList.Clear();
                        hailbtn.IsEnabled = false;
                    }
                    else
                    {
                        if (drivers.Count != 0 && drivers.Count != DriversList.Count)
                        {
                            mainmap.Pins.Clear();
                            DriversList.Clear();

                            foreach (KeyValuePair <string, DriverModel> item in drivers.ToList())
                            {
                                if (DriversList.All(d => d.Key != item.Value.Key))
                                {
                                    DriversList.Add(item.Value);
                                }
                            }

                            if (DriversList.Count > 0)
                            {
                                ShowDrivers(DriversList);
                                _ = StartTrackingAsync();
                                hailbtn.IsEnabled = true;
                            }
                            else
                            {
                                hailbtn.IsEnabled = false;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("---> error GetDataFromFirebase " + ex.Message);
                    throw;
                }
            };

            _firebaseDatabase.GetDrivers("drivers", onValueEvent);
        }