//----------------------------------------------------------------------------------------------------------------------------------------------// public void GetUserInfo() { print(DateTime.Now.ToString("MMMM") + " " + DateTime.Now.Day.ToString() + " at " + DateTime.Now.ToString("hh") + ":" + DateTime.Now.Minute.ToString() + " " + DateTime.Now.ToString("tt")); //debug.message = "Process Starting (Get User Info)"; debug.message = FirebaseDatabase.DefaultInstance.RootReference.ToString(); DataRef.CurrentUser().GetValueAsync().ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsCanceled || task.IsFaulted) { return; } DataSnapshot snapshot = task.Result; username.text = snapshot.Child("Username").Value.ToString(); currentUsername = snapshot.Child("Username").Value.ToString(); DateTime tempDate = Convert.ToDateTime(snapshot.Child("CreatedDate").Value.ToString()); string month = tempDate.ToString("MMMM"); string year = tempDate.Year.ToString(); createdDate.text = "Member Since " + month + " " + year; userPermissions = snapshot.Child("Permissions").Value.ToString(); menuNav.SetComingSoon(userPermissions); topUp.target = (int.Parse(snapshot.Child("Balance").Value.ToString())) / 100; topUp.balance = (int.Parse(snapshot.Child("Balance").Value.ToString())) / 100; pictureManager.DisplayPicture(snapshot.Child("PictureID").Value.ToString()); pictureManager.RevealProfileInfo(); transform.GetComponent <UserAuthentication> ().loading = false; GetGroupInfo(snapshot); activityManager.StartActivityProcess(); circlesManager.StartCircleProcess(); }); }
//----------------------------------------------------------------------------------------------------------------------------------------------// private void HandleValueChanged(object sender, ValueChangedEventArgs args) { if (args.DatabaseError != null) { confirmation.transform.GetChild(1).GetChild(1).GetComponent <Text> ().text = "An error has been encountered (#1)."; confirmation.transform.GetChild(2).gameObject.SetActive(false); return; } // Do stuff string status = args.Snapshot.Child("status").Value.ToString(); if (status == "inProgress" || status == null) { return; } else { DataRef.CurrentUser().Child("stripe").Child("charges").Child(activePushID).ValueChanged -= HandleValueChanged; } if (status == "error") { confirmation.transform.GetChild(1).GetChild(1).GetComponent <Text> ().text = "An error has been encountered (#2)."; confirmation.transform.GetChild(2).gameObject.SetActive(false); } else if (status == "succeeded") { confirmation.transform.GetChild(2).gameObject.SetActive(false); ConfirmationBox(false); t = 0; start = balance; target = balance + topup; } }
//----------------------------------------------------------------------------------------------------------------------------------------------// public void PopulateCircleList(int index) { StartCoroutine(FadeLoad(1.0f, true, 1.0f)); loading = true; if (circlesContent.childCount > 0) { foreach (Transform child in circlesContent) { Destroy(child.gameObject); } } DataRef.CurrentUser().Child("Circles").GetValueAsync().ContinueWith(async(task) => { await new WaitForUpdate(); DataSnapshot snapshot = task.Result; foreach (DataSnapshot circle in snapshot.Children) { string circleRef = circle.Value.ToString(); InstantiateCircle(circleRef); } OrganiseCirclesList(); foreach (Transform child in circlesContent) { child.GetComponent <Button> ().interactable = true; } circlesContent.GetChild(index).GetComponent <Button> ().interactable = false; GetCircleInformation(circlesContent.GetChild(index).gameObject.name); }); }
//----------------------------------------------------------------------------------------------------------------------------------------------// public void SetOnboardStatus() { DataRef.CurrentUser().Child("Onboarded").Child("Bucket Circle New Zealand").SetValueAsync("true").ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsCanceled || task.IsFaulted) { return; } this.gameObject.SetActive(false); }); }
//----------------------------------------------------------------------------------------------------------------------------------------------// private void AddToUserTotal(int value) { DataRef.CurrentUser().Child("DonationTotal").SetValueAsync(value.ToString()).ContinueWith(async(task) => { if (task.IsFaulted || task.IsCanceled) { await new WaitForUpdate(); print(task.Exception); return; } await new WaitForUpdate(); }); }
//----------------------------------------------------------------------------------------------------------------------------------------------// public void SetNewPictureID() { DataRef.CurrentUser().Child("PictureID").SetValueAsync(selectedPicture.gameObject.name).ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsCanceled || task.IsFaulted) { return; } Sprite image = Resources.Load <Sprite> ("2D/Animals/" + selectedPicture.gameObject.name); profilePicture.sprite = image; }); }
//----------------------------------------------------------------------------------------------------------------------------------------------// public void SetInfoSingle(string target, string value) { debug.message = "Process Starting (Set Info Single)"; DataRef.CurrentUser().Child(target).SetValueAsync(value).ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsCanceled || task.IsFaulted) { debug.message = "Process Error (Set Info Single)"; return; } debug.message = "Process Completed (Set Info Single)"; }); }
//----------------------------------------------------------------------------------------------------------------------------------------------// private void GetInstance() { pushKey = DataRef.Circles(circlesManager.activeCircleRef).Child("Comments").Push().Key; date = DateTime.Now.ToString("MMMM") + " " + DateTime.Now.Day.ToString() + " at " + DateTime.Now.ToString("hh") + ":" + DateTime.Now.Minute.ToString() + " " + DateTime.Now.ToString("tt"); timestamp = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond).ToString(); comment = displayText.text; user = DataRef.CurrentUser().Key.ToString(); SetValue("User", user); SetValue("Date", date); SetValue("Timestamp", timestamp); SetValue("Comment", comment); inputField.text = ""; }
//----------------------------------------------------------------------------------------------------------------------------------------------// public void StartInboxCheck() { DataRef.CurrentUser().Child("Inbox").GetValueAsync().ContinueWith(async(task) => { await new WaitForUpdate(); DataSnapshot snapshot = task.Result; if (int.Parse(snapshot.ChildrenCount.ToString()) != (content.childCount)) { PopulateReCheck(); } else { StartCoroutine(CheckForNewMessage(0.1f)); } }); }
//----------------------------------------------------------------------------------------------------------------------------------------------// private void OpenCirclePage(string circleRef) { DataRef.CurrentUser().Child("Circles").GetValueAsync().ContinueWith(async(task) => { await new WaitForUpdate(); DataSnapshot snapshot = task.Result; List <string> circles = new List <string> (); foreach (DataSnapshot child in snapshot.Children) { circles.Add(child.Value.ToString()); } int index = circles.IndexOf(circleRef); circlesManager.PopulateCircleList(index); }); }
//----------------------------------------------------------------------------------------------------------------------------------------------// public void JoinCircle(string circleRef) { string userRef = userAuth.transform.GetComponent <DataGetSet> ().currentUserID; DataRef.CurrentUser().Child("Circles").Child(circleRef).SetValueAsync(circleRef).ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsFaulted || task.IsCanceled) { print(task.Exception); return; } }); DataRef.Circles(circleRef).Child("Members").Child(userRef).SetValueAsync(userRef).ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsFaulted || task.IsCanceled) { print(task.Exception); return; } }); DataRef.Circles(circleRef).Child("TotalMembers").GetValueAsync().ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsFaulted || task.IsCanceled) { print(task.Exception); return; } DataSnapshot snapshot = task.Result; int totalMembers = int.Parse(snapshot.Value.ToString()); int newTotal = totalMembers + 1; SetTotalMembers(circleRef, newTotal); List <string> circles = new List <string> (); foreach (Transform circle in circlesContent) { circles.Add(circle.gameObject.name); } circles.Add(circleRef); circles.Sort(); PopulateCircleList(circles.IndexOf(circleRef)); }); }
//----------------------------------------------------------------------------------------------------------------------------------------------// public void AddReferenceToAllUserCircles(string uid, int donation, string projectRef) { DataRef.CurrentUser().Child("Circles").GetValueAsync().ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsFaulted || task.IsCanceled) { print(task.Exception); return; } DataSnapshot snapshot = task.Result; foreach (DataSnapshot snap in snapshot.Children) { string circleRef = snap.Value.ToString(); GetCircle(circleRef, projectRef, donation, uid); } }); }
//----------------------------------------------------------------------------------------------------------------------------------------------// private void CheckMembership() { DataRef.CurrentUser().GetValueAsync().ContinueWith(async(task) => { await new WaitForUpdate(); DataSnapshot snapshot = task.Result; if (snapshot.Child("Circles").HasChild(activeCircle)) { circlePreview.transform.GetChild(1).GetChild(3).gameObject.SetActive(false); circlePreview.transform.GetChild(1).GetChild(4).gameObject.SetActive(true); } else { circlePreview.transform.GetChild(1).GetChild(3).gameObject.SetActive(true); circlePreview.transform.GetChild(1).GetChild(4).gameObject.SetActive(false); } }); }
//----------------------------------------------------------------------------------------------------------------------------------------------// public void GetOnboardStatus() { DataRef.CurrentUser().Child("Onboarded").Child("Bucket Circle New Zealand").GetValueAsync().ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsCanceled || task.IsFaulted) { return; } DataSnapshot snapshot = task.Result; if (snapshot.Value.ToString() == "true") { this.gameObject.SetActive(false); } else { this.gameObject.SetActive(true); } }); }
//----------------------------------------------------------------------------------------------------------------------------------------------// private void AddReferenceForCreator(string circleRef, string userRef) { DataRef.Circles(circleRef).Child("Members").Child(userRef).SetValueAsync(userRef).ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsFaulted || task.IsCanceled) { print(task.Exception); return; } }); DataRef.CurrentUser().Child("Circles").Child(circleRef).SetValueAsync(circleRef).ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsFaulted || task.IsCanceled) { print(task.Exception); return; } }); }
//----------------------------------------------------------------------------------------------------------------------------------------------// public void TopUp() { DataRef.CurrentUser().Child("stripe").Child("customerID").GetValueAsync().ContinueWith(async(task) => { if (task.IsFaulted || task.IsCanceled) { await new WaitForUpdate(); return; } await new WaitForUpdate(); DataSnapshot snapshot = task.Result; string stripeID; stripeID = snapshot.Value.ToString(); StartStripe(stripeID, this.gameObject.name, "Confirm"); }); /*if (balance == target) { * t = 0; * start = balance; * target = balance + topup; * dataGetSet.SetInfoSingle ("Balance", (target * 100).ToString()); * }*/ }
//----------------------------------------------------------------------------------------------------------------------------------------------// public void StartCircleProcess() { DataRef.CurrentUser().Child("Circles").GetValueAsync().ContinueWith(async(task) => { await new WaitForUpdate(); DataSnapshot snapshot = task.Result; if (snapshot.HasChild("Bucket Circle New Zealand")) { List <string> circles = new List <string> (); foreach (DataSnapshot circle in snapshot.Children) { circles.Add(circle.Value.ToString()); } circles.Sort(); PopulateCircleList(circles.IndexOf("Bucket Circle New Zealand")); } else { PopulateCircleList(0); } }); }
//----------------------------------------------------------------------------------------------------------------------------------------------// private void MakeCharge() { confirmation.transform.GetChild(2).gameObject.SetActive(true); int tempTarget = balance + topup; string balanceCents = (tempTarget * 100).ToString(); activePushID = DataRef.CurrentUser().Child("stripe").Child("charges").Push().Key; StripeCharge charge = new StripeCharge(balanceCents, activeCardID); string json = JsonUtility.ToJson(charge); DataRef.CurrentUser().Child("stripe").Child("charges").Child(activePushID).SetRawJsonValueAsync(json).ContinueWith(async(task) => { if (task.IsFaulted || task.IsCanceled) { await new WaitForUpdate(); confirmation.transform.GetChild(2).gameObject.SetActive(false); return; } await new WaitForUpdate(); ListenForCharge(); }); }
//----------------------------------------------------------------------------------------------------------------------------------------------// public void Create() { creating = true; string uid = auth.CurrentUser.UserId.ToString(); DataRef.CurrentUser().GetValueAsync().ContinueWith(async(task) => { await new WaitForUpdate(); DataSnapshot snapshot = task.Result; SetReference("Group" + (snapshot.Child("Groups").ChildrenCount + 1).ToString(), groupName.text); snap = snapshot; }); DataRef.Groups(groupName.text).Child("GroupName").SetValueAsync(groupName.text).ContinueWith(async(task) => { await new WaitForUpdate(); }); DataRef.Groups(groupName.text).Child("GroupDescription").SetValueAsync(groupDescription.text).ContinueWith(async(task) => { await new WaitForUpdate(); }); DataRef.Groups(groupName.text).Child("Contact").SetValueAsync(contact.text).ContinueWith(async(task) => { await new WaitForUpdate(); }); DataRef.Groups(groupName.text).Child("Administrator").SetValueAsync(uid).ContinueWith(async(task) => { await new WaitForUpdate(); ResetFields(); dataGetSet.GetGroupInfo(snap); canvas.ToggleDoerSub(false); creating = false; }); }
//----------------------------------------------------------------------------------------------------------------------------------------------// public void ConfirmationBox(bool val) { confirmation.SetActive(val); if (val == true) { confirmation.transform.GetChild(1).GetChild(1).GetComponent <Text> ().text = "Accessing PIN"; DataRef.CurrentUser().Child("stripe").Child("pin").GetValueAsync().ContinueWith(async(task) => { if (task.IsFaulted || task.IsCanceled) { await new WaitForUpdate(); confirmation.transform.GetChild(1).GetChild(1).GetComponent <Text> ().text = "Failed to get PIN"; return; } await new WaitForUpdate(); DataSnapshot snapshot = task.Result; userPIN = snapshot.Value.ToString(); confirmation.transform.GetChild(1).GetChild(1).GetComponent <Text> ().text = "PIN accessed"; }); } else { userPIN = ""; } }
//----------------------------------------------------------------------------------------------------------------------------------------------// private void AddToTotalGet(int donation) { DataRef.CurrentUser().Child("DonationTotal").GetValueAsync().ContinueWith(async(task) => { if (task.IsFaulted || task.IsCanceled) { await new WaitForUpdate(); print(task.Exception); return; } await new WaitForUpdate(); DataSnapshot snapshot = task.Result; int totalAmount = int.Parse(snapshot.Value.ToString()); int newTotal = totalAmount + donation; AddToUserTotal(newTotal); }); DataRef.General().GetValueAsync().ContinueWith(async(task) => { if (task.IsFaulted || task.IsCanceled) { await new WaitForUpdate(); print(task.Exception); return; } await new WaitForUpdate(); DataSnapshot snapshot = task.Result; int totalAmount = int.Parse(snapshot.Child("TotalDonationsAmount").Value.ToString()); int totalMade = int.Parse(snapshot.Child("TotalDonationsMade").Value.ToString()); int newAmount = totalAmount + donation; int newMade = totalMade + 1; AddToTotalSet("TotalDonationsAmount", newAmount); AddToTotalSet("TotalDonationsMade", newMade); }); }
//----------------------------------------------------------------------------------------------------------------------------------------------// public void DismissMessage() { DataRef.CurrentUser().Child("Inbox").Child(transform.gameObject.name).RemoveValueAsync().ContinueWith(async(task) => { await new WaitForUpdate(); }); Destroy(this.gameObject); }
//----------------------------------------------------------------------------------------------------------------------------------------------// private void SetReference(string refTitle, string refValue) { DataRef.CurrentUser().Child("Groups").Child(refTitle).SetValueAsync(refValue).ContinueWith(async(task) => { await new WaitForUpdate(); }); }
//----------------------------------------------------------------------------------------------------------------------------------------------// public void SaveNewUserData(string userID) { DataRef.CurrentUser().Child("Username").SetValueAsync(username.text).ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsCanceled || task.IsFaulted) { return; } }); DataRef.CurrentUser().Child("CreatedDate").SetValueAsync(DateTime.Now.ToString()).ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsCanceled || task.IsFaulted) { return; } }); DataRef.CurrentUser().Child("Balance").SetValueAsync("0").ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsCanceled || task.IsFaulted) { return; } }); DataRef.CurrentUser().Child("stripe").Child("pin").SetValueAsync(pinNumber.text).ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsCanceled || task.IsFaulted) { return; } }); DataRef.CurrentUser().Child("PictureID").SetValueAsync("Animal_Kiwi").ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsCanceled || task.IsFaulted) { return; } }); DataRef.CurrentUser().Child("Permissions").SetValueAsync("Default").ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsCanceled || task.IsFaulted) { return; } }); DataRef.CurrentUser().Child("DonationTotal").SetValueAsync("0").ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsCanceled || task.IsFaulted) { return; } }); DataRef.CurrentUser().Child("Circles").Child("Bucket Circle New Zealand").SetValueAsync("Bucket Circle New Zealand").ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsCanceled || task.IsFaulted) { return; } }); DataRef.CurrentUser().Child("Onboarded").Child("Bucket Circle New Zealand").SetValueAsync("false").ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsCanceled || task.IsFaulted) { return; } }); DataRef.Circles("Bucket Circle New Zealand").Child("Members").Child(userID.ToString()).SetValueAsync(userID.ToString()).ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsCanceled || task.IsFaulted) { return; } }); DataRef.Circles("Bucket Circle New Zealand").Child("TotalMembers").GetValueAsync().ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsCanceled || task.IsFaulted) { return; } DataSnapshot snapshot = task.Result; int totalMembers = int.Parse(snapshot.Value.ToString()); int newTotal = totalMembers + 1; AddToCircleTotal(newTotal); }); DataRef.General().Child("TotalDonors").GetValueAsync().ContinueWith(async(task) => { await new WaitForUpdate(); if (task.IsCanceled || task.IsFaulted) { return; } DataSnapshot snapshot = task.Result; int totalusers = int.Parse(snapshot.Value.ToString()); int newUsers = totalusers + 1; AddToTotalSet("TotalDonors", newUsers); }); GetComponent <DataGetSet> ().GetUserInfo(); activityManager.SetAlertNewDonor(username.text, userID); activityManager.StartActivityProcess(); circlesManager.StartCircleProcess(); }
//----------------------------------------------------------------------------------------------------------------------------------------------// private void SetValue(string child, string value) { DataRef.CurrentUser().Child("Inbox").Child(pushKey).Child(child).SetValueAsync(value).ContinueWith(async(taskSet) => { await new WaitForUpdate(); }); }
//----------------------------------------------------------------------------------------------------------------------------------------------// private void ListenForCharge() { DataRef.CurrentUser().Child("stripe").Child("charges").Child(activePushID).ValueChanged += HandleValueChanged; }