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(); } }); }
// 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); }); }
public async Task dothis() { EventStreamResponse response = await client.OnAsync("DavesTrain/passengers", (sender, args, context) => { if (DataUpdated != null) { DataUpdated.Invoke(this, EventArgs.Empty); } }); }
static void Main(string[] args) { IFirebaseConfig config = new FirebaseConfig { AuthSecret = "YOUR_SECRET", BasePath = "YOUR_FIREBASE_URL" }; client = new FirebaseClient(config); Console.Write("Insert door name: "); door = Console.ReadLine(); Console.WriteLine("***************************************"); Console.WriteLine("MENU:"); Console.WriteLine("1. Simulate Arduino"); Console.WriteLine("2. Clean Log data"); Console.Write("Insert your choose (1/2): "); string izbor = Console.ReadLine(); Console.WriteLine(); if (izbor == "1") { Console.WriteLine("Simulating ....."); Console.WriteLine("Press any key to finish"); Dictionary <string, int> data = new Dictionary <string, int>(); data.Add("unlock", 0); client.UpdateAsync(door + "/State/", data); Task <EventStreamResponse> task = client.OnAsync(door + "/State", null, FirebaseChanged); System.Timers.Timer timer = new System.Timers.Timer(); timer.Elapsed += Timer_Elapsed; timer.Interval = new Random().Next(10000, 50000); timer.Enabled = true; Console.Read(); task.Result.Dispose(); } else if (izbor == "2") { cleanFirebase(); } Console.WriteLine("Program finished"); }
//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()); }); }
async void ListenStream() { await client.OnAsync("rooms", (sender, args, context) => { string[] temp = args.Path.Split('/');// rooms/0 => 0 int id = int.Parse(temp[1]); if (roomDatas.ContainsKey(id)) { roomDatas[id] = args.Data; } else { roomDatas.Add(id, args.Data); } OnRoomDataChangedEvent(id); }); }
private void InitializeData() { _user = new User(); _client = new FirebaseClient(new FirebaseConfig { AuthSecret = "hg3M2mMzq6ABYbevSswjIKC7tdS8vDLArsedRGiT", BasePath = "https://vrsa-5d0b9.firebaseio.com" }); _client.OnAsync("Users/Barcode", (sender, args, context) => { _dataTimer.Stop(); _dataTimer.Start(); }); _dataTimer = new System.Timers.Timer(5000); _dataTimer.Elapsed += _timer_Elapsed; _dataTimer.Start(); }
private async void ListenToStream() { client = new FirebaseClient(config); await client.OnAsync("FireSharp/Name/", (sender, args) => { //Gets the Unique ID and deletes the any other string attached to it string dataFromFB = args.Data; string paths = args.Path; string key = RemoveNameSubstring(paths); string uniqueKey = key.Split('/').Last(); if (keyHolder.ContainsKey(uniqueKey)) { keyHolder[uniqueKey] = dataFromFB; AddToListView(dataFromFB); } else { keyHolder.Add(uniqueKey, dataFromFB); AddToListView(dataFromFB); } }); }
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 }
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"); } }
private async Task InitImpl() { while (initializing) { await Task.Delay(300); } if (config != null) { return; } initializing = true; #if RELEASE || DEBUG_REAL config = new FirebaseConfig() { AuthSecret = Properties.Resources.AuthSecret, BasePath = Properties.Resources.BasePath }; #else config = new FirebaseConfig() { AuthSecret = Properties.Resources.AuthSecret_DEBUG, BasePath = Properties.Resources.BasePath_DEBUG }; #endif client = new FirebaseClient(config); initializing = false; await client.OnAsync(Path, // added (s, e, c) => { this.Invoke(() => { string path = Combine(this.Path, e.Path); this.OnValueAdded(path, e.Data); this.ValueAdded?.Invoke(this, new ValueAddedEventArgs(path, e.Data)); }); }, // changed (s, e, c) => { this.Invoke(() => { string path = Combine(this.Path, e.Path); this.OnValueChanged(path, e.Data); this.ValueChanged?.Invoke(this, new ValueChangedEventArgs(path, e.Data)); }); }, // removed (s, e, c) => { this.Invoke(() => { string path = Combine(this.Path, e.Path); this.OnValueRemoved(path); this.ValueRemoved?.Invoke(this, new ValueRemovedEventArgs(path, null)); }); }); }
public Task <EventStreamResponse> On <T>(string path, ValueAddedEventHandler added = null, ValueChangedEventHandler changed = null, ValueRemovedEventHandler removed = null) { return(_firebaseClient.OnAsync(path, added, changed, removed)); }
public async Task EnsureDataStoreAsync() { mJobsStreamResponse = await mFirebaseClient.OnAsync(JOBS, null, OnJobsChanged); mValvesStreamResponse = await mFirebaseClient.OnAsync(VALVES, null, OnVavlesChanged); }