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