/**** CONSTRUCTOR ****/ /// <summary> /// Create new Firebase endpoint /// </summary> /// <param name="_parent">Parent Firebase pointer</param> /// <param name="_key">Key under parent Firebase</param> /// <param name="_root">Root Firebase pointer</param> /// <param name="inheritCallback">If set to <c>true</c> inherit callback.</param> internal SimpleFirebase(SimpleFirebase _parent, string _key, SimpleFirebaseRoot _root, bool inheritCallback = false) { parent = _parent; key = _key; root = _root; fullKey = parent.FullKey + "/" + key; if (inheritCallback) { OnGetSuccess = parent.OnGetSuccess; OnGetFailed = parent.OnGetFailed; OnSetSuccess = parent.OnSetSuccess; OnSetFailed = parent.OnSetFailed; OnUpdateSuccess = parent.OnUpdateSuccess; OnUpdateFailed = parent.OnUpdateFailed; OnPushSuccess = parent.OnPushSuccess; OnPushFailed = parent.OnPushFailed; OnDeleteSuccess = parent.OnDeleteSuccess; OnDeleteFailed = parent.OnDeleteFailed; } }
/// <summary> /// Get a fresh copy of this Firebase object /// </summary> /// <param name="inheritCallback">If set to <c>true</c> inherit callback.</param> public SimpleFirebase Copy(bool inheritCallback = false) { SimpleFirebase temp; if (parent == null) { temp = root.Copy(); } else { temp = new SimpleFirebase(parent, key, root); } if (inheritCallback) { temp.OnGetSuccess = OnGetSuccess; temp.OnGetFailed = OnGetFailed; temp.OnSetSuccess = OnSetSuccess; temp.OnSetFailed = OnSetFailed; temp.OnUpdateSuccess = OnUpdateSuccess; temp.OnUpdateFailed = OnUpdateFailed; temp.OnPushSuccess = OnPushSuccess; temp.OnPushFailed = OnPushFailed; temp.OnDeleteSuccess = OnDeleteSuccess; temp.OnDeleteFailed = OnDeleteFailed; } return(temp); }
public CommandLinkedList(SimpleFirebase _firebase, FirebaseCommand _command, string _param, object _obj = null) { firebase = _firebase; command = _command; param = _param; obj = _obj; next = null; }
/// <summary> /// Adds Firebase Update request to queue. /// </summary> /// <param name="firebase">Firebase.</param> /// <param name="val">Value.</param> /// <param name="param">Parameter.</param> public void AddQueueUpdate(SimpleFirebase firebase, object val, SimpleFirebaseParam param) { SimpleFirebase temp = firebase.Copy(true); temp.OnUpdateSuccess += OnSuccess; temp.OnUpdateFailed += OnFailed; AddQueue(temp, FirebaseCommand.Update, param.Parameter, val); }
public CommandLinkedList(SimpleFirebase _firebase, FirebaseCommand _command, SimpleFirebaseParam firebaseParam, object _obj = null) { firebase = _firebase; command = _command; param = firebaseParam.Parameter; obj = _obj; next = null; }
/// <summary> /// Adds Firebase Set request to queue. /// </summary> /// <param name="firebase">Firebase.</param> /// <param name="val">Value.</param> /// <param name="param">Parameter.</param> public void AddQueueSet(SimpleFirebase firebase, object val, string param = "") { SimpleFirebase temp = firebase.Copy(true); temp.OnSetSuccess += OnSuccess; temp.OnSetFailed += OnFailed; AddQueue(temp, FirebaseCommand.Set, param, val); }
/// <summary> /// Adds Firebase Get request to queue. /// </summary> /// <param name="firebase">Firebase.</param> /// <param name="param">Parameter.</param> public void AddQueueGet(SimpleFirebase firebase, SimpleFirebaseParam param) { SimpleFirebase temp = firebase.Copy(true); temp.OnGetSuccess += OnSuccess; temp.OnGetFailed += OnFailed; AddQueue(temp, FirebaseCommand.Get, param.Parameter); }
/// <summary> /// Adds Firebase Get request to queue. /// </summary> /// <param name="firebase">Firebase.</param> /// <param name="param">Parameter.</param> public void AddQueueGet(SimpleFirebase firebase, string param = "") { SimpleFirebase temp = firebase.Copy(true); temp.OnGetSuccess += OnSuccess; temp.OnGetFailed += OnFailed; AddQueue(temp, FirebaseCommand.Get, param); }
/// <summary> /// Adds Firebase Push request to queue. /// </summary> /// <param name="firebase">Firebase.</param> /// <param name="val">Value.</param> /// <param name="param">Parameter.</param> public void AddQueuePush(SimpleFirebase firebase, object val, SimpleFirebaseParam param) { SimpleFirebase temp = firebase.Copy(true); temp.OnPushSuccess += OnSuccess; temp.OnPushFailed += OnFailed; AddQueue(temp, FirebaseCommand.Push, param.Parameter, val); }
/// <summary> /// Adds Firebase Delete request to queue. /// </summary> /// <param name="firebase">Firebase.</param> /// <param name="param">Parameter.</param> public void AddQueueDelete(SimpleFirebase firebase, SimpleFirebaseParam param) { SimpleFirebase temp = firebase.Copy(true); temp.OnDeleteSuccess += OnSuccess; temp.OnDeleteFailed += OnFailed; AddQueue(temp, FirebaseCommand.Delete, param.Parameter); }
/// <summary> /// Sets the time stamp with the time since UNIX epoch by server value (in milliseconds). /// </summary> /// <param name="keyName">Key name.</param> /// <param name="OnSuccess">On success callback.</param> /// <param name="OnFailed">On fail callback.</param> public void SetTimeStamp(string keyName, Action <SimpleFirebase, SimpleDataSnapshot> OnSuccess, Action <SimpleFirebase, SimpleFirebaseError> OnFailed) { SimpleFirebase temp = Child(keyName); temp.OnSetSuccess += OnSuccess; temp.OnSetFailed += OnFailed; temp.SetValue(SERVER_VALUE_TIMESTAMP, true); }
/// <summary> /// Adds Firebase Set Time Stamp request with callback to queue. /// </summary> /// <param name="firebase">Firebase.</param> /// <param name="keyName">Key name.</param> /// <param name="_OnSuccess">On success callback.</param> /// <param name="_OnFailed">On fail callback.</param> public void AddQueueSetTimeStamp(SimpleFirebase firebase, string keyName, Action <SimpleFirebase, SimpleDataSnapshot> _OnSuccess, Action <SimpleFirebase, SimpleFirebaseError> _OnFailed) { SimpleFirebase temp = firebase.Child(keyName); temp.OnSetSuccess += _OnSuccess; temp.OnSetFailed += _OnFailed; AddQueueSet(temp, SERVER_VALUE_TIMESTAMP, true); }
/// <summary> /// Creates an Observer that calls GetValue request at the given refresh rate (in seconds) and checks whether the value has changed. /// </summary> /// <param name="firebase">Firebase.</param> /// <param name="refreshRate">Refresh rate (in seconds).</param> /// <param name="getParam">Parameter value for the Get request that will be called periodically.</param> public SimpleFirebaseObserver(SimpleFirebase _firebase, float _refreshRate, SimpleFirebaseParam _getParam) { active = false; lastSnapshot = null; firebase = _firebase; refreshRate = _refreshRate; getParam = _getParam.Parameter; target = _firebase.Copy(); }
/// <summary> /// Creates an Observer that calls GetValue request at the given refresh rate (in seconds) and checks whether the value has changed. /// </summary> /// <param name="firebase">Firebase.</param> /// <param name="refreshRate">Refresh rate (in seconds).</param> /// <param name="getParam">Parameter value for the Get request that will be called periodically.</param> public SimpleFirebaseObserver(SimpleFirebase _firebase, float _refreshRate, string _getParam = "") { active = false; lastSnapshot = null; firebase = _firebase; refreshRate = _refreshRate; getParam = _getParam; target = _firebase.Copy(); routine = null; }
protected void ClearCallbacks(SimpleFirebase sender) { sender.OnGetSuccess -= OnSuccess; sender.OnGetFailed -= OnFailed; sender.OnUpdateSuccess -= OnSuccess; sender.OnUpdateFailed -= OnFailed; sender.OnPushSuccess -= OnSuccess; sender.OnPushFailed -= OnFailed; sender.OnDeleteSuccess -= OnSuccess; sender.OnDeleteFailed -= OnFailed; }
/// <summary> /// Adds Firebase Update request to queue. /// </summary> /// <param name="firebase">Firebase.</param> /// <param name="json">Json.</param> /// <param name="isJson">If set to <c>true</c> is json.</param> /// <param name="param">Parameter.</param> public void AddQueueUpdate(SimpleFirebase firebase, string json, bool isJson, string param = "") { SimpleFirebase temp = firebase.Copy(true); temp.OnUpdateSuccess += OnSuccess; temp.OnUpdateFailed += OnFailed; if (!isJson) { AddQueue(temp, FirebaseCommand.Update, param, json); } else { AddQueue(temp, FirebaseCommand.Update, param, Json.Deserialize(json)); } }
/// <summary> /// Adds Firebase Push request to queue. /// </summary> /// <param name="firebase">Firebase.</param> /// <param name="json">Json.</param> /// <param name="isJson">If set to <c>true</c> is json.</param> /// <param name="param">Parameter.</param> public void AddQueuePush(SimpleFirebase firebase, string json, bool isJson, SimpleFirebaseParam param) { SimpleFirebase temp = firebase.Copy(true); temp.OnPushSuccess += OnSuccess; temp.OnPushFailed += OnFailed; if (!isJson) { AddQueue(temp, FirebaseCommand.Push, param.Parameter, json); } else { AddQueue(temp, FirebaseCommand.Push, param.Parameter, Json.Deserialize(json)); } }
void CompareSnapshot(SimpleFirebase target, SimpleDataSnapshot snapshot) { if (firstTime) { firstTime = false; lastSnapshot = snapshot; return; } if (!snapshot.RawJson.Equals(lastSnapshot.RawJson)) { if (OnChange != null) { OnChange(firebase, snapshot); } } lastSnapshot = snapshot; }
protected void AddQueue(SimpleFirebase firebase, FirebaseCommand command, string param, object obj = null) { CommandLinkedList commandNode = new CommandLinkedList(firebase, command, param, obj); if (head == null) { head = commandNode; tail = commandNode; if (autoStart) { head.DoCommand(); } } else { tail.next = commandNode; tail = commandNode; } ++count; }
protected void OnFailed(SimpleFirebase sender, SimpleFirebaseError err) { --count; StartNextCommand(); ClearCallbacks(sender); }
internal SimpleFirebase() { parent = null; key = string.Empty; root = null; }
/// <summary> /// Adds Firebase Update request to queue. /// </summary> /// <param name="firebase">Firebase.</param> /// <param name="val">Value.</param> /// <param name="param">Parameter.</param> public void AddQueueUpdate(SimpleFirebase firebase, object val, string param = "") { firebase.OnUpdateSuccess += OnSuccess; firebase.OnUpdateFailed += OnFailed; AddQueue(firebase, FirebaseCommand.Update, param, val); }
/// <summary> /// Adds Firebase Set Time Stamp request to queue. /// </summary> /// <param name="firebase">Firebase.</param> /// <param name="keyName">Time stamp key name.</param> public void AddQueueSetTimeStamp(SimpleFirebase firebase, string keyName) { SimpleFirebase temp = firebase.Child(keyName, false); AddQueueSet(temp, SERVER_VALUE_TIMESTAMP, true, "print=silent"); }
protected void OnSuccess(SimpleFirebase sender, SimpleDataSnapshot snapshot) { --count; StartNextCommand(); ClearCallbacks(sender); }