Beispiel #1
0
        public void GetDocument(DocumentSnapshotHandler handler)
        {
            var tcs = new TaskCompletionSource <IDocumentSnapshot>();

            _documentReference.Get().AddOnCompleteListener(new OnCompleteHandlerListener((task) =>
            {
                var snapshot = !task.IsSuccessful ? null : task.Result.JavaCast <DocumentSnapshot>();
                handler?.Invoke(snapshot == null ? null : new DocumentSnapshotWrapper(snapshot),
                                task.IsSuccessful ? null : ExceptionMapper.Map(task.Exception));
            }));
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            // Well, just config with your own name app in manifest.xml
            // and yout own "google-services.json" file config from Firebase. that's all.



            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);

            fireApp       = Firebase.FirebaseApp.InitializeApp(this);
            fireFirestore = Firebase.Firestore.FirebaseFirestore.Instance;
            fireDatabase  = Firebase.Database.FirebaseDatabase.Instance;

            Button btn1 = FindViewById(Resource.Id.Button1) as Button;

            btn1.Click += delegate
            {
                // So here it's crash the App.

                DocumentReference docRef = fireFirestore.Collection("collection1").Document("doc1");
                docRef.Get()
                .AddOnCompleteListener(this)
                .AddOnFailureListener(this);
            };
        }
Beispiel #3
0
        public Task <User> SearchUser(string TempEmail)
        {
            TaskCompletionSource <User> ResultCompletionSource = new TaskCompletionSource <User>();
            DocumentReference           Path = Conn.Collection(usercollection).Document(TempEmail);

            Path.Get().AddOnCompleteListener(new OnCompleteEventHandleListener((Android.Gms.Tasks.Task
                                                                                obj) =>
            {
                if (obj.IsSuccessful)
                {
                    App.searchResult      = new User();
                    DocumentSnapshot temp = (DocumentSnapshot)obj.Result;
                    if (temp.Exists())
                    {
                        var TempDictionary   = temp.Data;
                        var searchUserResult = new User((string)temp.Id, (string)TempDictionary["username"]);
                        ResultCompletionSource.SetResult(searchUserResult);
                    }
                    else
                    {
                        ResultCompletionSource.SetResult(null);
                    }
                }
            }));

            return(ResultCompletionSource.Task);
        }
Beispiel #4
0
        public static Task <T> GetDocumentAsync <T>(this DocumentReference reference) where T : class
        {
            var tcs = new TaskCompletionSource <T>();

            reference
            .Get()
            .AddOnCompleteListener(new OnCompleteEventHandleListener((Android.Gms.Tasks.Task obj) =>
            {
                if (obj.IsSuccessful)
                {
                    var res = obj.GetResult(Class.FromType(typeof(DocumentSnapshot))).JavaCast <DocumentSnapshot>();
                    tcs.SetResult(Cast <T>(res));
                }
                else
                {
                    tcs.SetException(obj.Exception);
                }
            }));

            return(tcs.Task);
        }
Beispiel #5
0
        public async Task <string[]> GetData()
        {
            FirebaseFirestore database;
            string            uid = FirebaseAuth.Instance.CurrentUser.Uid;
            var app = FirebaseApp.Instance;

            database = FirebaseFirestore.GetInstance(app);

            DocumentReference docRef   = database.Collection("utenti").Document(uid);
            DocumentSnapshot  snapshot = (DocumentSnapshot)await docRef.Get();

            String data_name  = snapshot.GetString("nome");
            String data_lName = snapshot.GetString("cognome");
            String data_email = snapshot.GetString("email");

            List <string> list = new List <string>();

            list.Add(data_name);
            list.Add(data_lName);
            list.Add(data_email);
            String[] str = list.ToArray();
            return(str);
        }