Exemplo n.º 1
0
        public virtual List <T> Search <T>(SearchFilter filter) where T : IHasId
        {
            Condition.Requires(filter).IsNotNull();
            List <T> list = new List <T>();

            this.JSONObject.WithEach(x =>
            {
                try
                {
                    //get the store item
                    SerializedIHasId item = JsonSerializer.DeserializeFromString <SerializedIHasId>(x.Value);

                    //test the nested object
                    if (item != null)
                    {
                        T t = (T)item.GetStoredItem();

                        if (filter.Filter(t))
                        {
                            list.Add(t);
                        }
                    }
                }
                catch { }
            });
            return(list);
        }
Exemplo n.º 2
0
        public virtual void Commit(ICommitBag bag)
        {
            Condition.Requires(bag).IsNotNull();

            //lock the store
            lock (this._stateLock)
            {
                bag.ItemsToDelete.WithEach(x =>
                {
                    this.JSONObject.Remove(x.ToString());
                });
                bag.ItemsToSave.WithEach(x =>
                {
                    SerializedIHasId item = SerializedIHasId.New(x);
                    this.JSONObject[item.Id.ToString()] = JsonSerializer.SerializeToString <SerializedIHasId>(item);
                });
            }
        }
Exemplo n.º 3
0
        public virtual List <IHasId> GetAll()
        {
            List <IHasId> list = new List <IHasId>();

            this.JSONObject.WithEach(x =>
            {
                try
                {
                    //get the store item
                    SerializedIHasId item = JsonSerializer.DeserializeFromString <SerializedIHasId>(x.Value);

                    //test the nested object
                    if (item != null)
                    {
                        list.Add(item.GetStoredItem());
                    }
                }
                catch { }
            });
            return(list);
        }