Example #1
0
 public void Add(T item)
 {
     if (_items.Contains(item))
     {
         //let's not overwrite -- this will be determined by
         //item.Equals()
         this.Update(item);
     }
     else
     {
         this.Model.Insert(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);
     }
 }
Example #2
0
 protected void FireSavedEvents()
 {
     if (this.Saved != null)
     {
         var args = new BiggyEventArgs <T>();
         args.Items = _items;
         this.Saved.Invoke(this, args);
     }
 }
Example #3
0
 protected void FireInsertedEvents(T item)
 {
     if (this.ItemAdded != null)
     {
         var args = new BiggyEventArgs <T>();
         args.Item = item;
         this.ItemAdded.Invoke(this, args);
     }
 }
Example #4
0
 public void Clear()
 {
     _items.Clear();
     this.Model.DeleteWhere("");
     if (this.Changed != null)
     {
         var args = new BiggyEventArgs <T>();
         this.Changed.Invoke(this, args);
     }
 }
Example #5
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));
 }
Example #6
0
        public List <T> TryLoadFileData(string path)
        {
            List <T> result = new List <T>();

            if (File.Exists(path))
            {
                //format for the deserializer...
                var json = "[" + File.ReadAllText(path).Replace(Environment.NewLine, ",") + "]";
                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);
        }
Example #7
0
        public SQLServerList(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 SQLServerTable <T>(connectionStringName, this.TableName, primaryKeyName);
            this.Reload();

            if (this.Loaded != null)
            {
                var args = new BiggyEventArgs <T>();
                args.Items = _items;
                this.Loaded.Invoke(this, args);
            }
        }
Example #8
0
    // FOR SQLITE:
    //public void DropCreateAll() {
    //  const string SQL_TRACKS_TABLE = ""
    //    + "CREATE TABLE Track ( TrackId INTEGER PRIMARY KEY AUTOINCREMENT, AlbumId INT NOT NULL, Name text NOT NULL, Composer TEXT );";
    //  const string SQL_ARTISTS_TABLE = ""
    //    + "CREATE TABLE Artist ( ArtistId INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, Name TEXT NOT NULL );";
    //  const string SQL_ALBUMS_TABLE = ""
    //    + "CREATE TABLE Album ( AlbumId INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, ArtistId INT NOT NULL, Title text NOT NULL );";

    //  _db.TryDropTable("Artist");
    //  _db.TryDropTable("Album");
    //  _db.TryDropTable("Track");
    //  _db.TryDropTable("artistdocuments");

    //  int result = _db.TransactDDL(SQL_ARTISTS_TABLE + SQL_ALBUMS_TABLE + SQL_TRACKS_TABLE);
    //}


    //// FOR POSTGRES:
    //public void DropCreateAll() {
    //  const string SQL_TRACKS_TABLE = ""
    //    + "CREATE TABLE track ( track_id SERIAL PRIMARY KEY, album_id INTEGER NOT NULL, name text NOT NULL, composer TEXT );";
    //  const string SQL_ARTISTS_TABLE = ""
    //    + "CREATE TABLE artist ( artist_id SERIAL PRIMARY KEY NOT NULL, name text NOT NULL );";
    //  const string SQL_ALBUMS_TABLE = ""
    //    + "CREATE TABLE album ( album_id SERIAL PRIMARY KEY NOT NULL, artist_id integer NOT NULL, title text NOT NULL );";

    //  _db.TryDropTable("artist");
    //  _db.TryDropTable("album");
    //  _db.TryDropTable("track");
    //  _db.TryDropTable("artistdocuments");

    //  int result = _db.TransactDDL(SQL_ARTISTS_TABLE + SQL_ALBUMS_TABLE + SQL_TRACKS_TABLE);
    //}


    void memoryArtists_ItemAdded(object sender, BiggyEventArgs<Artist> e) {
      Console.WriteLine(e.Item.Name);
    }
Example #9
0
        // FOR SQLITE:
        //public void DropCreateAll() {
        //  const string SQL_TRACKS_TABLE = ""
        //    + "CREATE TABLE Track ( TrackId INTEGER PRIMARY KEY AUTOINCREMENT, AlbumId INT NOT NULL, Name text NOT NULL, Composer TEXT );";
        //  const string SQL_ARTISTS_TABLE = ""
        //    + "CREATE TABLE Artist ( ArtistId INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, Name TEXT NOT NULL );";
        //  const string SQL_ALBUMS_TABLE = ""
        //    + "CREATE TABLE Album ( AlbumId INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, ArtistId INT NOT NULL, Title text NOT NULL );";

        //  _db.TryDropTable("Artist");
        //  _db.TryDropTable("Album");
        //  _db.TryDropTable("Track");
        //  _db.TryDropTable("artistdocuments");

        //  int result = _db.TransactDDL(SQL_ARTISTS_TABLE + SQL_ALBUMS_TABLE + SQL_TRACKS_TABLE);
        //}


        //// FOR POSTGRES:
        //public void DropCreateAll() {
        //  const string SQL_TRACKS_TABLE = ""
        //    + "CREATE TABLE track ( track_id SERIAL PRIMARY KEY, album_id INTEGER NOT NULL, name text NOT NULL, composer TEXT );";
        //  const string SQL_ARTISTS_TABLE = ""
        //    + "CREATE TABLE artist ( artist_id SERIAL PRIMARY KEY NOT NULL, name text NOT NULL );";
        //  const string SQL_ALBUMS_TABLE = ""
        //    + "CREATE TABLE album ( album_id SERIAL PRIMARY KEY NOT NULL, artist_id integer NOT NULL, title text NOT NULL );";

        //  _db.TryDropTable("artist");
        //  _db.TryDropTable("album");
        //  _db.TryDropTable("track");
        //  _db.TryDropTable("artistdocuments");

        //  int result = _db.TransactDDL(SQL_ARTISTS_TABLE + SQL_ALBUMS_TABLE + SQL_TRACKS_TABLE);
        //}


        void memoryArtists_ItemAdded(object sender, BiggyEventArgs <Artist> e)
        {
            Console.WriteLine(e.Item.Name);
        }