Esempio n. 1
0
        public void Transaction <T>(T data, int timeout, Action <Response <DataSnapshot> > OnComplete, Action <OnChangeData <T> > OnChange = null, Dictionary <string, string> requestHeaders = null)
        {
            if (requestHeaders == null)
            {
                requestHeaders = new Dictionary <string, string>()
                {
                    { "X-Firebase-ETag", "true" }
                };
            }
            else if (!requestHeaders.ContainsKey("X-Firebase-ETag"))
            {
                requestHeaders.Add("X-Firebase-ETag", "true");
            }

            GetValueAsync(timeout, res =>
            {
                Dictionary <string, string> setValueRequestHeaders = null;
                if (res.success)
                {
                    res.headers.TryGetValue("ETag", out string etag);

                    if (!string.IsNullOrEmpty(etag))
                    {
                        setValueRequestHeaders = new Dictionary <string, string>()
                        {
                            { "if-match", etag }
                        };
                    }
                }

                var onChangeData = new OnChangeData <T>(data, res.data.Value);
                OnChange?.Invoke(onChangeData);

                SetValueAsync(onChangeData.outputData, timeout, setValueRes =>
                {
                    OnComplete?.Invoke(new Response <DataSnapshot>(setValueRequestHeaders, setValueRes.message, setValueRes.success, setValueRes.code, new FirebaseDataSnapshot(this, Json.Deserialize(setValueRes.data))));
                },
                              setValueRequestHeaders);
            },
                          requestHeaders);
        }
 public void ChangeData()
 {
     SerializedObject?.ApplyModifiedProperties();
     OnChangeData?.Invoke();
 }
Esempio n. 3
0
 public object this[string key] {
     get { var v = get?.Invoke(data, key); OnChangeData?.Invoke(true, key, v); return(v); } set { OnChangeData?.Invoke(false, key, value); set?.Invoke(data, key, value); }
 }