Exemplo n.º 1
0
 public async void SetAction(Action action, string session, FirebaseAction actionType)
 {
     _response = await _client.OnAsync($"/networkInfo/{session}",
                                       added : (s, args, d) =>
     {
         if (actionType == FirebaseAction.OnAdd)
         {
             action();
         }
     },
                                       changed : (s, args, d) =>
     {
         if (actionType == FirebaseAction.OnChange)
         {
             action();
         }
     },
                                       removed : (s, args, d) =>
     {
         if (actionType == FirebaseAction.OnDelete)
         {
             action();
         }
     });
 }
Exemplo n.º 2
0
        private static async void EventStreaming()
        {
            await _client.DeleteAsync("chat");

            await _client.OnAsync("chat",
                                  added : async(sender, args) =>
            {
                System.Console.WriteLine(args.Data + "-> 1\n");
                await _client.PushAsync("chat/", new
                {
                    name = "someone",
                    text = "Console 1:" + DateTime.Now.ToString("f")
                });
            },
                                  changed : (sender, args) => { System.Console.WriteLine(args.Data); },
                                  removed : (sender, args) => { System.Console.WriteLine(args.Path); });

            EventStreamResponse response = await _client.OnAsync("chat",
                                                                 added : (sender, args) => { System.Console.WriteLine(args.Data + " -> 2\n"); },
                                                                 changed : (sender, args) => { System.Console.WriteLine(args.Data); },
                                                                 removed : (sender, args) => { System.Console.WriteLine(args.Path); });

            //Call dispose to stop listening for events
            //response.Dispose();
        }
Exemplo n.º 3
0
        private async void ContentPage_Appearing(object sender, EventArgs e)
        {
            if (Application.Current.Properties.ContainsKey("modo"))
            {
                var modo = Application.Current.Properties["modo"] as string;

                if (modo == "0")
                {
                    wvPrincipal.Source = new Uri("https://pepeizqdeals.com/classic/?app=true");
                }
                else
                {
                    wvPrincipal.Source = new Uri("https://pepeizqdeals.com/?app=true");
                }
            }
            else
            {
                wvPrincipal.Source = new Uri("https://pepeizqdeals.com/?app=true");
            }

            IFirebaseConfig config = new FirebaseConfig
            {
                AuthSecret = "HtabeaAa9uFa0BN0uBQkBjy82MGcnhlVYVXjs1JM",
                BasePath   = "https://pepeizq-s-deals-android.firebaseio.com"
            };

            IFirebaseClient cliente = new FirebaseClient(config);

            EventStreamResponse response = await cliente.OnAsync("mensajes/", (s, args, context) => {
                CrossLocalNotifications.Current.Show(args.Data, "test");
            });
        }
Exemplo n.º 4
0
 public async void ListenFirebase(DataGridView gridBook)
 {
     EventStreamResponse response = await client.OnAsync("books",
                                                         added : (sender, args, context) => { UpdateDataGridView(gridBook); },
                                                         changed : (sender, args, context) => { UpdateDataGridView(gridBook); },
                                                         removed : (sender, args, context) => { UpdateDataGridView(gridBook); });
 }
Exemplo n.º 5
0
        // class


        // lang nghe co ban dbbarcode khong
        public static async void langnghe(Label lbcapnhatngay, Form ff)
        {
            clientFirebase = new FireSharp.FirebaseClient(configFirebase);
            EventStreamResponse response = await clientFirebase.OnAsync("capnhat/capnhatdbbarcode/phienban",
                                                                        changed :
                                                                        (sender, args, context) => {
                taifiledbbarcode(args.Data, lbcapnhatngay, ff);
            });
        }
Exemplo n.º 6
0
 public async Task dothis()
 {
     EventStreamResponse response = await client.OnAsync("DavesTrain/passengers", (sender, args, context) => {
         if (DataUpdated != null)
         {
             DataUpdated.Invoke(this, EventArgs.Empty);
         }
     });
 }
Exemplo n.º 7
0
        public async Task Listen()
        {
            IFirebaseClient client = new FirebaseClient(config);

            EventStreamResponse response = await client.OnAsync("chat", (sender, args, context) => {
                System.Console.WriteLine(args.Data);
            });

            //Call dispose to stop listening for events
            //response.Dispose();
        }
Exemplo n.º 8
0
 public async void MesajKontrol()
 {
     try
     {
         FirebaseClient      client      = new FirebaseClient(config);
         EventStreamResponse eventStream = await client.OnAsync("Chat/" + Username.ToLower() + "/" + GidicekMesaj.ToLower() + "/RandomNumbers/", MesajGeldiginde);
     }
     catch
     {
     }
 }
Exemplo n.º 9
0
        public async void ListenFirebaseDataGridView(DataGridView dataGridView, TextBox textBox)
        {
            EventStreamResponse response = await client.OnAsync("exchange/" + DataStatic.USERNAME,

                                                                added : (sender, args, context) => {
                List <Data> animals = GetALL();
                dataGridView.BeginInvoke(new MethodInvoker(delegate {
                    dataGridView.DataSource = animals;
                    textBox.Text            = animals[animals.Count - 1].amount;
                }));
            });
        }
        //Receives command from Firebase and relays it to Arduino
        //This is necessary if you have multiple instances of this application, but only one is connected to Arduino serial port
        private async void ListenToFirebaseStream(string child)
        {
            EventStreamResponse response = await firebase_arduino.OnAsync(child, changed : (sender, args, context) =>
            {
                //Since "txtCommands" are being accessed from another thread, it should be invoked like this:
                txtCommands.Invoke(new Action(() => txtCommands.Text          += "[Firebase]: " + child + ":" + args.Data + Environment.NewLine));
                txtCommands.Invoke(new Action(() => txtCommands.SelectionStart = txtCommands.Text.Length));
                txtCommands.Invoke(new Action(() => txtCommands.ScrollToCaret()));

                firebaseToArduino(child, args.Data);
            });

            EventsList.Add(response);
        }
 public async void read()
 {
     respons = await client.OnAsync("pending", (sender, args, context) => {
         //Console.WriteLine(args.Path);
         //Console.WriteLine(args.Data);
         //addToKitchen(args.Path);
         //addItem();
         //Console.WriteLine("changed");
         //Console.WriteLine(args.Path.ToString());
         //String x = args.Path.ToString();
         //String y = x.Remove(x.Length - 3);
         //Console.WriteLine(y);
         getOrderNo(args.Data.ToString());
     });
 }
Exemplo n.º 12
0
        private async void LoadMessages()
        {
            string name   = Chat.User1.Username + "-" + Chat.User2.Username;
            var    client = MessageManager.Instance.GetClient();

            eventResponse = await client.OnAsync("chats/" + name + "/Messages", async (sender, args, context) => {
                var response = await client.GetAsync("chats/" + name);
                Chat chat    = response.ResultAs <Chat>();
                chat.Messages.ForEach(x =>
                {
                    if (!MessageExists(x.Id))
                    {
                        x.SetTextSettings();
                        Messages.Add(x);
                    }
                });
            });
        }
 private async void ListenToFirebase()
 {
     EventStreamResponse response = await _firebaseClient.OnAsync(_firebaseEndpoint,
                                                                  added : (s, args, d) =>
     {
         var id = args.Path.Split('/')[1];
         //form.firebaseStatus.Text = "[" + DateTime.Now.ToString("hh:mm:ss:fff tt") + "] [{id}] Received ADDED updates from Firebase...";
     },
                                                                  changed : (s, args, d) =>
     {
         var id = args.Path.Split('/')[1];
         //firebaseStatus.Text = "[" + DateTime.Now.ToString("hh:mm:ss:fff tt") + "] [{id}] Received CHANGED updates from Firebase...";
     },
                                                                  removed : (s, args, d) =>
     {
         var id = args.Path.Split('/')[1];
         //firebaseStatus.Text = "[" + DateTime.Now.ToString("hh:mm:ss:fff tt") + "] [{id}] Received DELETE updates from Firebase...";
     });
 }
Exemplo n.º 14
0
 /// <summary>
 /// Updates the student if it is changed in the database asyncronisly.
 /// Authors: Eric Dong
 /// </summary>
 private async void  updateStudent()
 {
     // Get response on update asyncronisly.
     EventStreamResponse response = await this.client.OnAsync("Students",
                                                              // if the update is an add event
                                                              added : (s, args, context) =>
     {
         StudentChangedHelperMethod();
     },
                                                              // if the update is a change event, update the student attribute and labels.
                                                              changed : (s, args, context) =>
     {
         StudentChangedHelperMethod();
     },
                                                              // if the update is a remove event.
                                                              removed : (s, args, context) =>
     {
         StudentChangedHelperMethod();
     });
 }
Exemplo n.º 15
0
        public async void OnAddAll <T>(string path, ObservableDictionary <string, T> dict) where T : BaseModel, new()
        {
            ObservableDictionary <string, T> returnDictionary = dict;
            T t;

            eventResponse = await On <T>(path, (sender, args) =>
            {
                string[] tokens = args.Path.Split('/');
                string key      = tokens[1];
                string property = tokens[2];
                if (returnDictionary.ContainsKey(key))
                {
                    t = returnDictionary[key];
                }
                else
                {
                    t = new T();
                    returnDictionary[key] = t;
                }
                t.SetProperty(property, args.Data);
            });
        }
Exemplo n.º 16
0
        private async void Form1_LoadAsync(object sender, EventArgs e)
        {
            config = new FirebaseConfig
            {
                AuthSecret = "aEAl0mjXoKiSwDLSzMxgc1UDitCQevwyANP5hk8C",
                BasePath   = "https://trafficbookapp.firebaseio.com"
            };

            client = new FirebaseClient(config);
            EventStreamResponse response = await client.OnAsync("todos/set"
                                                                //added
                                                                , (_sender, args, contex) => {
                Console.WriteLine(args.ToJson());
                //changed (update)
            }, (_sender, args, contex) => {
                Console.WriteLine(args.ToJson());
                //removed
            }, (_sender, args, contex) => {
                Console.WriteLine(args.ToJson());
            }, obj);

            //Call dispose to stop listening for events
        }
Exemplo n.º 17
0
        public async Task EnsureDataStoreAsync()
        {
            mJobsStreamResponse = await mFirebaseClient.OnAsync(JOBS, null, OnJobsChanged);

            mValvesStreamResponse = await mFirebaseClient.OnAsync(VALVES, null, OnVavlesChanged);
        }
Exemplo n.º 18
0
        public async void ListenFirebaseToken()
        {
            EventStreamResponse response = await client.OnAsync("account/" + DataStatic.USERNAME + "/token",

                                                                changed : (sender, args, context) => { CheckToken(); });
        }
Exemplo n.º 19
0
        public async void ListenFirebaseToken()
        {
            EventStreamResponse response = await client.OnAsync("user/" + DataStatic.user,

                                                                changed : (sender, args, context) => { CheckToken(); });
        }
Exemplo n.º 20
0
        private async void PopulateMessageView()
        {
            //Populate message list
            string msgCountPath = "DemoApp/Messages/" + pathToPairedId + "/msgCount";

            response = await client.GetAsync(msgCountPath);

            if (response.ResultAs <string>() != null)
            {
                int messageCount = response.ResultAs <int>();
                sMessageCount = response.ResultAs <int>();
                for (int i = 0; i < messageCount; i++)
                {
                    string path      = "DemoApp/Messages/" + pathToPairedId + "/messages/" + i.ToString() + "/";
                    var    msgBundle = new
                    {
                        msg = await client.GetAsync(path + "msg"),
                        id  = await client.GetAsync(path + "id"),
                        img = await client.GetAsync(path + "img")
                    };

                    if (!msgBundle.msg.ResultAs <string>().Equals(""))
                    {
                        mdp          = new MessageDisplay();
                        mdp.Message  = msgBundle.msg.ResultAs <string>();
                        mdp.ID       = msgBundle.id.ResultAs <string>();
                        mdp.AutoSize = true;
                        if (msgBundle.id.ResultAs <string>().Equals(Properties.Settings.Default.Email))
                        {
                            mdp.Margin = new Padding(250, 20, 0, 0);
                        }
                        else
                        {
                            mdp.Margin = new Padding(30, 20, 0, 0);
                        }
                        fpMsgs.Controls.Add(mdp);
                    }
                    else
                    {
                        mdp = new MessageDisplay();
                        mdp.PictureProfile = msgBundle.img.ResultAs <string>();
                        mdp.ID             = msgBundle.id.ResultAs <string>();
                        mdp.AutoSize       = true;

                        if (msgBundle.id.ResultAs <string>().Equals(Properties.Settings.Default.Email))
                        {
                            mdp.Margin = new Padding(250, 20, 0, 0);
                        }
                        else
                        {
                            mdp.Margin = new Padding(30, 20, 0, 0);
                        }
                        fpMsgs.Controls.Add(mdp);
                    }
                }
                //
                //Stream event listener
                ESRMsgs = await client.OnAsync("DemoApp/Messages/" + pathToPairedId + "/messages/complete", changed : async(sender, args, context) => {
                    System.Console.WriteLine(args.Data);
                    //sMessageCount++;
                    //response = await client.GetAsync("DemoApp/Messages/" + pathToPairedId + "/messages/" + messageCount.ToString());

                    Invoke(new MethodInvoker(async delegate
                    {
                        if (response.ResultAs <string>() != null)
                        {
                            string path   = "DemoApp/Messages/" + pathToPairedId + "/messages/" + (sMessageCount).ToString() + "/";
                            var msgBundle = new
                            {
                                msg = await client.GetAsync(path + "msg"),
                                id  = await client.GetAsync(path + "id"),
                                img = await client.GetAsync(path + "img")
                            };

                            if (!msgBundle.msg.ResultAs <string>().Equals(""))
                            {
                                mdp          = new MessageDisplay();
                                mdp.Message  = msgBundle.msg.ResultAs <string>();
                                mdp.ID       = msgBundle.id.ResultAs <string>();
                                mdp.AutoSize = true;
                                if (msgBundle.id.ResultAs <string>().Equals(Properties.Settings.Default.Email))
                                {
                                    mdp.Margin = new Padding(250, 20, 0, 0);
                                }
                                else
                                {
                                    mdp.Margin = new Padding(30, 20, 0, 0);
                                }
                                fpMsgs.Controls.Add(mdp);
                                sMessageCount++;
                            }
                            else
                            {
                                mdp = new MessageDisplay();
                                mdp.PictureProfile = msgBundle.img.ResultAs <string>();
                                mdp.ID             = msgBundle.id.ResultAs <string>();
                                mdp.AutoSize       = true;

                                if (msgBundle.id.ResultAs <string>().Equals(Properties.Settings.Default.Email))
                                {
                                    mdp.Margin = new Padding(250, 20, 0, 0);
                                }
                                else
                                {
                                    mdp.Margin = new Padding(30, 20, 0, 0);
                                }
                                fpMsgs.Controls.Add(mdp);
                                sMessageCount++;
                            }
                        }
                    }));
                });
            }
            else
            {
                MessageBox.Show("Has no message");
            }
        }
Exemplo n.º 21
0
        private async void LoadDataToFirebase()
        {
            //Load picture profile.
            response = await client.GetAsync("DemoApp/MessageInfo/ID/" + userEmail + "/picProfile");

            if (response.ResultAs <string>() != "noPic")
            {
                ribPicProfile.Load(response.ResultAs <String>());
            }
            else
            {
                ribPicProfile.Load(noPic);
            }


            //Populate contact list
            string populateContacts = "DemoApp/MessageInfo/Accounts/" + userEmail + "/Contacts";

            response = await client.GetAsync(populateContacts + "/pairedCount");

            int pairedCount = response.ResultAs <int>();

            for (int i = 0; i < pairedCount; i++)
            {
                string contactEmail;
                response = await client.GetAsync(populateContacts + "/pairedId/" + (i + 1).ToString());

                cdp           = new ContactDisplay();
                cdp.Width     = fpContacts.Width - 30;
                cdp.UserEmail = response.ResultAs <string>();
                contactEmail  = response.ResultAs <string>();
                contactEmail  = contactEmail.Replace('.', '_');
                response      = await client.GetAsync(populateContacts + "/pairedInfo/" + contactEmail + "/pairedId");

                cdp.PairedId = response.ResultAs <string>();
                response     = await client.GetAsync("DemoApp/MessageInfo/ID/" + contactEmail + "/name");

                cdp.UserName = response.ResultAs <string>();
                response     = await client.GetAsync("DemoApp/MessageInfo/ID/" + contactEmail + "/picProfile");

                if (response.ResultAs <string>() == "noPic")
                {
                    cdp.PictureProfile = noPic;
                }
                else
                {
                    cdp.PictureProfile = response.ResultAs <string>();
                }

                fpContacts.Controls.Add(cdp);
            }

            //Stream event listener
            EventStreamResponse eventStreamResponse = await client.OnAsync(populateContacts + "/pairedId", added :  async(sender, args, context) => {
                System.Console.WriteLine(args.Data);
                pairedCount++;
                response = await client.GetAsync(populateContacts + "/pairedId/" + pairedCount.ToString());

                Invoke(new MethodInvoker(async delegate
                {
                    //string t = response.ResultAs<string>();
                    if (response.ResultAs <string>() != null)
                    {
                        string contactEmail;
                        cdp           = new ContactDisplay();
                        cdp.Width     = fpContacts.Width - 30;
                        cdp.UserEmail = response.ResultAs <string>();
                        contactEmail  = response.ResultAs <string>();
                        contactEmail  = contactEmail.Replace('.', '_');
                        response      = await client.GetAsync(populateContacts + "/pairedInfo/" + contactEmail + "/pairedId");
                        cdp.PairedId  = response.ResultAs <string>();
                        response      = await client.GetAsync("DemoApp/MessageInfo/ID/" + contactEmail + "/name");
                        cdp.UserName  = response.ResultAs <string>();
                        response      = await client.GetAsync("DemoApp/MessageInfo/ID/" + contactEmail + "/picProfile");
                        if (response.ResultAs <string>() == "noPic")
                        {
                            cdp.PictureProfile = noPic;
                        }
                        else
                        {
                            cdp.PictureProfile = response.ResultAs <string>();
                        }
                        fpContacts.Controls.Add(cdp);
                    }
                }));

                //msg.Invoke(new MethodInvoker(delegate { msg.Message = response.ResultAs<string>(); fpMsgs.Controls.Add(msg); }));
            });

            //eventStreamResponse.Dispose();
        }