/* * Handle Firebase client */ // Listen to machine branch in firebase private void StartListen() { SignInButton.Visibility = Visibility.Hidden; SignOutButton.Visibility = Visibility.Visible; // create a firebase branch listener for new messages try { if (global._FirebaseClient != null) { subscribtion = global._FirebaseClient.Child("Users/" + global._FirebaseAuth.User.LocalId + "/PC") .AsObservable <string>() .Subscribe(data => { try { HandleServerRequest(data, global._FirebaseClient, global._FirebaseAuth); } catch (Exception) { subscribtion.Dispose(); StartListen(); } }); } else { PushMessage("Listening to other devices requires you to be logged in", ANSWER_STYLE); } } catch { PushMessage("I have to restart. Be right back ;)", ANSWER_STYLE); MarinaLauncher launcher = new MarinaLauncher(); launcher.Show(); this.Close(); } }
private void SignUpButtonClick(object sender, RoutedEventArgs e) { string Username = UsernameBox.Text.ToLower(); string Password = PasswordBox.Password; string DisplayName = NameBox.Text; Task t; bool connected = false; if (Username == "" || Password == "") { MessageBox.Show("Email or password are empty"); return; } if (DisplayName == "") { MessageBox.Show("Username can't be blank"); return; } t = Task.Run(async() => { try { await ConnectToFirebase(Username, Password, DisplayName); connected = true; } catch { connected = false; } }); t.Wait(2000); if (connected) { global._FirebaseClient.Child("Users/" + global._FirebaseAuth.User.LocalId + "/Phone").PutAsync(new MessageToFirebase { message = "false" }); global._FirebaseClient.Child("Users/" + global._FirebaseAuth.User.LocalId + "/PC").PutAsync(new MessageToFirebase { message = "false" }); StreamWriter sr = new StreamWriter(Path.Combine(Directory.GetCurrentDirectory(), "userDetails.txt")); sr.WriteLine(Username); sr.WriteLine(Password); sr.Close(); MarinaLauncher w = new MarinaLauncher(); w.Show(); this.Close(); } else { MessageBox.Show("Failed to sign up"); } }