rlamasb / Firebase.Xamarin

Light weight wrapper for Firebase Realtime Database REST API.
MIT License
149 stars 39 forks source link

Problem with realtime db #14

Open kennyray opened 8 years ago

kennyray commented 8 years ago

I cannot figure out how to get realtime data. I can get one at a time, but there is no notification saying that the data is finished updating. Can anyone show me how to do it so that I'll know when all the data has come in? Or can it give me a collection of items instead of one at a time?

dthall43 commented 8 years ago

If you are having this problem. It is because you do not understand how await and async work in c#. I recommend go learning how they operate.

Example: var firebase = new FirebaseClient("https://you.firebaseio.com/"); var dinos = firebase.Child("your-info");

var query = QueryExtensions.WithAuth(dinos, auth.FirebaseToken).OnceAsync().Result;

Here query contains all of the objects you need. But ONLY because i did not use await. If i had used await. It would have contained nothing UNTIL the request was finished.

kennyray commented 8 years ago

First, let me thank you for responding. You are correct in that I am still learning about await and async.

I think I may not have been clear enough in my question however. I do understand how OnceAsync works. I originally had that working just fine. What I'm trying to figure out is how to setup a subscription. Using the example code provided, I'm able to get one item at a time through the onNext handler, but the problem is that I never know when the data is finished, so if the record set on the server changes, it sends me everything again, and my local collection has everything in it twice.

Again, I acknowledge that this is my own ignorance at work here. I'm just looking for some guidance on how to learn how this stuff works. I looked up Reactive, and I think I understand the principles. I'm just not sure how to apply them in this case.

When I did this in Objective-C, I was given back a collection of all the items at once, not individual items. So it seems that the way it's done in C# is a bit different.

Thanks for any further help you can offer.

Kenny

On Nov 4, 2016, at 3:42 PM, dthall43 notifications@github.com wrote:

If you are having this problem. It is because you do not understand how await and async work in c#. I recommend go learning how they operate.

Example: var firebase = new FirebaseClient("https://you.firebaseio.com/"); var dinos = firebase.Child("your-info"); var query = QueryExtensions.WithAuth(dinos, auth.FirebaseToken).OnceAsync().Result;

Here query contains all of the objects you need. But ONLY because i did not use await. If i had used await. It would have contained nothing UNTIL the request was finished.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

christopheBERNARDPost commented 7 years ago

Hello all,

i'm new to firebase with c# xamarin and i would like to make a sample application. This sample application can just connect to firebase and react with my device on real time.

I can connect to firebase, add, deleve datas, but each time i add on => console firebase a new data my device is not synchronise directly ...

How i can do that ? i read the wiki about subscribe but how i can use it ?

Is there possible to have a little sample or isn't possible to do that actually ?

Thanks for your knowledge you share that's really great to use some project here.

Christophe

KevinSchuddinck commented 7 years ago

You could create an observer which listens to changes made in the database. You can create an observer like this:

var firebase = new FirebaseClient("https://you.firebaseio.com/"); var observer = firebase.Child("<your-folder>").AsObservable<T>();

Later you can subscribe your observer to the database

Observer.Subscribe(next => 
                    { 
                        //do stuff here with every item you collect from the database
                    }, 
                onError => 
                   { 
                       //do stuff here when an error occurs
                   }, 
                onCompleted => 
                    { 
                        //do stuff here when all items are fetched from the database
                    }
                );

I must add that the onError and onCompleted are not called in my project. I have added a post on this page regarding that issue.

pallavbohara commented 7 years ago

@kennyray Thank you for posting this question. I myself getting this error. When i update some data, it returns whole data under that node. Also .Subscribe() called for every item in that particular node.

How you solved this?

navingp commented 7 years ago

@pallavbohara @kennyray you able to solve it?

pbrownTexasDevices commented 7 years ago

Was anyone able to solve this issue? Is there anywhere I can go for better documentation?

kennyray commented 7 years ago

@pallavbohara @navingp @pbrownTexasDevices I didn't solve it, and I ended up moving away from Firebase. Sorry I can't help further...

pbrownTexasDevices commented 7 years ago

@kennyray What did you move to if you don't mind me asking.

kennyray commented 7 years ago

@pbrownTexasDevices I moved to Azure, but couldn't figure out how to do login, so I stopped working on the project and closed my Azure account because it was costing me money each month. I have been working with Xamarin OAuth and once I have that figured out I will be trying AWS for the db next.

codegrue commented 6 years ago

It would be nice if there was a discussion forum where we could talk about how to do stuff without posting as issues. Does that exist? A Slack channel perhaps?

Ganturok commented 6 years ago

I guess that I resolved this problem, changed the way that I subscribed.

FirebaseDataBaseConfig.Suscription.Add(FirebaseDataBaseConfig.RootReference.Child("chats").Child(conversation).OrderByKey().LimitToLast(1).AsObservable().Subscribe( delegate(FirebaseEvent e) { Debug.WriteLine("FirebaseEventIOS : " + e.Key + " " + e.Object.Message); MessageChangeTrigger(e, conversation); }));

If you limit to last item in your subscription, the event "onNext" only once called. I tried with "onCompleted" event, but this never fired.