示例#1
0
        public void Add(T item)
        {
            if (_items.Contains(item))
            {
                //let's not overwrite -- this will be determined by
                //item.Equals()
                Update(item);
            }
            else
            {
                _items.Add(item);
            }

            //_items.Add(item);

            if (this.ItemAdded != null)
            {
                var args = new BiggyEventArgs <T>();
                args.Item = item;
                this.ItemAdded.Invoke(this, args);
            }
            if (this.Changed != null)
            {
                var args = new BiggyEventArgs <T>();
                args.Item = item;
                this.Changed.Invoke(this, args);
            }
        }
示例#2
0
 protected void FireRemovedEvents(T item)
 {
     if (this.ItemRemoved != null)
     {
         var args = new BiggyEventArgs <T>();
         args.Item = item;
         this.ItemRemoved.Invoke(this, args);
     }
 }
示例#3
0
 protected void FireChangedEvents()
 {
     if (this.Changed != null)
     {
         var args = new BiggyEventArgs <T>();
         args.Items = _items;
         this.Changed.Invoke(this, args);
     }
 }
示例#4
0
 public void Clear()
 {
     _items.Clear();
     if (this.Changed != null)
     {
         var args = new BiggyEventArgs <T>();
         this.Changed.Invoke(this, args);
     }
 }
示例#5
0
 protected virtual void Fire(EventHandler <BiggyEventArgs <T> > @event, T item = default(T), IList <T> items = null)
 {
     if (@event != null)
     {
         var args = new BiggyEventArgs <T> {
             Item = item, Items = items
         };
         @event(this, args);
     }
 }
示例#6
0
 public bool Remove(T item)
 {
     if (this.ItemRemoved != null)
     {
         var args = new BiggyEventArgs <T>();
         args.Item = item;
         this.ItemRemoved.Invoke(this, args);
     }
     if (this.Changed != null)
     {
         var args = new BiggyEventArgs <T>();
         args.Item = item;
         this.Changed.Invoke(this, args);
     }
     return(_items.Remove(item));
 }
示例#7
0
 public bool Remove(T item)
 {
     this.Model.Delete(this.Model.GetPrimaryKey(item));
     if (this.ItemRemoved != null)
     {
         var args = new BiggyEventArgs <T>();
         args.Item = item;
         this.ItemRemoved.Invoke(this, args);
     }
     if (this.Changed != null)
     {
         var args = new BiggyEventArgs <T>();
         args.Item = item;
         this.Changed.Invoke(this, args);
     }
     return(_items.Remove(item));
 }
示例#8
0
 public async Task SaveAsync()
 {
     if (!this.InMemory)
     {
         var json = JsonConvert.SerializeObject(this);
         var buff = Encoding.Default.GetBytes(json);
         using (var fs = File.OpenWrite(this.DbPath)) {
             await fs.WriteAsync(buff, 0, buff.Length);
         }
     }
     if (this.Saved != null)
     {
         var args = new BiggyEventArgs <T>();
         args.Items = _items;
         this.Saved.Invoke(this, args);
     }
 }
示例#9
0
        public List <T> TryLoadFileData(string path)
        {
            List <T> result = new List <T>();

            if (File.Exists(path))
            {
                var json = File.ReadAllText(path);
                result = JsonConvert.DeserializeObject <List <T> >(json);
            }

            if (this.Loaded != null)
            {
                var args = new BiggyEventArgs <T>();
                args.Items = result;
                this.Loaded.Invoke(this, args);
            }

            return(result);
        }
示例#10
0
 public bool Save()
 {
     try {
         if (!String.IsNullOrWhiteSpace(this.DbDirectory))
         {
             //write it to disk
             this.JSON = JsonConvert.SerializeObject(this);
             File.WriteAllText(this.DbPath, this.JSON);
         }
         if (this.Saved != null)
         {
             var args = new BiggyEventArgs <T>();
             args.Items = _items;
             this.Saved.Invoke(this, args);
         }
         return(true);
     } catch (Exception x) {
         //log it?
         throw;
     }
 }
示例#11
0
        public MassiveList(string connectionStringName, string tableName = "guess", string primaryKeyName = "id")
        {
            this.ConnectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
            if (tableName != "guess")
            {
                this.TableName = tableName;
            }
            else
            {
                var thingyType = this.GetType().GenericTypeArguments[0].Name;
                this.TableName = Inflector.Inflector.Pluralize(thingyType).ToLower();
            }
            this.Model = new DBTable(connectionStringName, this.TableName, primaryKeyName);
            this.Reload();

            if (this.Loaded != null)
            {
                var args = new BiggyEventArgs <T>();
                args.Items = _items;
                this.Loaded.Invoke(this, args);
            }
        }
示例#12
0
 public bool Save()
 {
     try {
         if (!String.IsNullOrWhiteSpace(this.DbDirectory))
         {
             //write it to disk
             var serializer = new JsonSerializer();
             using (var fs = File.CreateText(this.DbPath)) {
                 serializer.Serialize(fs, this);
             }
         }
         if (this.Saved != null)
         {
             var args = new BiggyEventArgs <T>();
             args.Items = _items;
             this.Saved.Invoke(this, args);
         }
         return(true);
     } catch (Exception x) {
         //log it?
         throw;
     }
 }