private void OnNewDoorTime(object sender, ValueChangedEventArgs args) { Debug.Log("New door time REMOVE"); string json = args.Snapshot.GetRawJsonValue(); if (string.IsNullOrEmpty(json)) { doorTime = new DoorTime(null, null, false); } else { doorTime = JsonConvert.DeserializeObject <DoorTime>(json); } if (doorTime.HasExpired()) { Debug.Log("Door has expired"); DeleteRequest(); } if (doorTime.unlocked) { Unlock(); } }
//Delete Request void DeleteRequest() { doorTime = new DoorTime(null, null, false); SendDoorTime(doorTime); // ItemManager.instance.RemoveDoorItem(); }
void SendDoorTime(DoorTime doorTime) { string json = JsonConvert.SerializeObject(doorTime); FirebaseCommunicator.instance.SendObject(json, referenceName, (task) => { if (task.IsFaulted) { Debug.LogError("Failed to send door request"); return; } else if (task.IsCompleted) { Debug.Log("Door request sent"); } }); }
void GetDoorTime() { FirebaseCommunicator.instance.GetObject(referenceName, (task) => { if (task.IsFaulted) { Debug.LogError("Failed getting door time"); return; } else if (task.IsCompleted) { string json = task.Result.GetRawJsonValue(); if (string.IsNullOrEmpty(json)) { doorTime = new DoorTime(null, null, false); } else { doorTime = JsonConvert.DeserializeObject <DoorTime>(json); } if (doorTime.HasExpired()) { Debug.Log("Door has expired"); DeleteRequest(); } if (doorTime.unlocked) { Unlock(); } } }); }
void CreateNewRequest() { doorTime = new DoorTime(null, DateTime.Now.ToString(dateFormat)); }