예제 #1
0
        private void InitDictionary(Type type, IFireDelegate fireDelegate, List <IFireControl> uiSubscribers, string userId, bool initWithCache = false)
        {
            this.LastKey            = "";
            this.FireDictDelegate   = fireDelegate;
            this.Items              = new Dictionary <string, IFireObject>();
            this.Path               = type.Name;
            this.UISubscriptionList = uiSubscribers;
            this.ObjectType         = type;
            this.UserId             = userId;

            if (initWithCache)
            {
                this.LoadFromCache <CnC.Model.Game>();
            }

            if (this.UserId != null) // UserId = "" = public
            {
                //filter on user //.StartAtKey(lastKey)
                myQuery = fireDelegate.firebaseApp.Child(this.Path).OrderByChild(USERIDKEY).EqualTo(userId).On(FIREEVENTADD, (snap, previous_child, context) => AddOrUpdate(snap));
                fireDelegate.firebaseApp.Child(this.Path).OrderByChild(USERIDKEY).EqualTo(userId).On(FIREEVENTDELETE, (snap, previous_child, context) => Removed(snap, previous_child, context));
            }
            else
            {
                //unfiltered
                myQuery = fireDelegate.firebaseApp.Child(this.Path).StartAtKey(lastKey).On(FIREEVENTADD, (snap, previous_child, context) => AddOrUpdate(snap));
                fireDelegate.firebaseApp.Child(this.Path).On(FIREEVENTDELETE, (snap, previous_child, context) => Removed(snap, previous_child, context));
            }
        }
예제 #2
0
        private void AddOrUpdate(IDataSnapshot snap)
        {
            Debug.Print(snap.Key);
            string previousKey = this.LastKey;

            foreach (IDataSnapshot child in snap.Children)
            {
                IFireObject fireObjectInstance = (IFireObject)JsonConvert.DeserializeObject(child.Value(), this.ObjectType);
                fireObjectInstance.Key = child.Key;
                this.addOrUpdate(fireObjectInstance);
            }

            if (previousKey != this.LastKey)
            {
                myQuery.Off();

                if (this.UserId != null)
                {
                    //filter on user //.StartAtKey(lastKey)
                    myQuery = FireDictDelegate.firebaseApp.Child(this.Path).OrderByChild(USERIDKEY).EqualTo(this.UserId).StartAtKey(lastKey).On(FIREEVENTADD, (snap2, previous_child, context) => AddOrUpdate(snap2));
                }
                else
                {
                    myQuery = FireDictDelegate.firebaseApp.Child(this.Path).StartAtKey(lastKey).On(FIREEVENTADD, (snap2, previous_child, context) => AddOrUpdate(snap2));
                }
            }
        }
예제 #3
0
        public JobQueue(IFirebase jobs, Func <T, bool> callback)
        {
            // create our own copy and ignore filters
            _jobs = jobs.Child("/");

            _query = _jobs
                     .On("child_changed", (snap, child, context) =>
            {
                if (snap.Exists)
                {
                    if (snap["Timestamp"][".sv"].Exists)
                    {
                        // local version
                        return;
                    }

                    T data = snap["Data"].Value <T>();

                    try
                    {
                        if (callback(data))
                        {
                            // remove from the queue
                            snap.Ref().Remove();
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("ERROR: {0}", ex);
                    }
                }
            });
        }