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); } }
protected void FireRemovedEvents(T item) { if (this.ItemRemoved != null) { var args = new BiggyEventArgs <T>(); args.Item = item; this.ItemRemoved.Invoke(this, args); } }
protected void FireChangedEvents() { if (this.Changed != null) { var args = new BiggyEventArgs <T>(); args.Items = _items; this.Changed.Invoke(this, args); } }
public void Clear() { _items.Clear(); if (this.Changed != null) { var args = new BiggyEventArgs <T>(); this.Changed.Invoke(this, args); } }
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); } }
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)); }
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)); }
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); } }
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); }
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; } }
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); } }
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; } }