/**** 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);
        }
示例#3
0
 public CommandLinkedList(SimpleFirebase _firebase, FirebaseCommand _command, string _param, object _obj = null)
 {
     firebase = _firebase;
     command  = _command;
     param    = _param;
     obj      = _obj;
     next     = null;
 }
示例#4
0
        /// <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);
        }
示例#5
0
 public CommandLinkedList(SimpleFirebase _firebase, FirebaseCommand _command, SimpleFirebaseParam firebaseParam, object _obj = null)
 {
     firebase = _firebase;
     command  = _command;
     param    = firebaseParam.Parameter;
     obj      = _obj;
     next     = null;
 }
示例#6
0
        /// <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);
        }
示例#7
0
        /// <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);
        }
示例#8
0
        /// <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);
        }
示例#9
0
        /// <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);
        }
示例#10
0
        /// <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);
        }
示例#12
0
        /// <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;
 }
示例#15
0
 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;
 }
示例#16
0
        /// <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));
            }
        }
示例#17
0
        /// <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;
        }
示例#19
0
        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;
        }
示例#20
0
 protected void OnFailed(SimpleFirebase sender, SimpleFirebaseError err)
 {
     --count;
     StartNextCommand();
     ClearCallbacks(sender);
 }
 internal SimpleFirebase()
 {
     parent = null;
     key    = string.Empty;
     root   = null;
 }
示例#22
0
 /// <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);
 }
示例#23
0
        /// <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");
        }
示例#24
0
 protected void OnSuccess(SimpleFirebase sender, SimpleDataSnapshot snapshot)
 {
     --count;
     StartNextCommand();
     ClearCallbacks(sender);
 }