/// <summary> /// 初期化処理を行います。 /// </summary> public void InitDb() { var rootRef = Database.DefaultInstance.GetRootReference(); rootRef.ObserveSingleEvent(DataEventType.Value, (datasnapshot, prevChild) => { //初期値取得 var members = datasnapshot.GetChildSnapshot("members").Children; var states = datasnapshot.GetChildSnapshot("status").Children; //初期値送信 InitializedDb?.Invoke( this, ConvertToMemberModels(members), ConvertToStateModels(states) ); //更新イベントハンドラ登録 var memRef = datasnapshot.GetChildSnapshot("members").Reference; var memUpdateHandle = memRef.ObserveEvent(DataEventType.Value, (memSnapshot, memChild) => { var mems = memSnapshot.Children; //更新 UpdatedMembers?.Invoke( this, ConvertToMemberModels(mems) ); }); }); }
/// <summary> /// 初期化処理を行います。 /// </summary> public void InitDb() { //初期化処理登録 FirebaseDatabase.Instance.Reference.Root.AddValueEventListener(_initDataNotifier); _initDataNotifier.ChangedData.Subscribe(snap => { if (snap == null) { return; } var members = ConvertToMemberModels(snap.Child("members")) ?? new List <MemberModel>(); var states = ConvertToStateModels(snap.Child("status")) ?? new List <StateModel>(); if (members.Any() && states.Any()) { Members.Value = members; States.Value = states; InitializedDb?.Invoke(this, members, states); } }); //更新処理登録 FirebaseDatabase.Instance.GetReference("members").AddValueEventListener(_updateDataNotifier); _updateDataNotifier.ChangedData.Subscribe(snap => { if (snap == null) { return; } var members = ConvertToMemberModels(snap) ?? new List <MemberModel>(); if (members.Any()) { Members.Value = members; UpdatedMembers?.Invoke(this, members); } }); }