public GoogleTokenProviderService(string tokenSecret, string clientId, string clientSecret, MusicLibraryContext context) { this.tokenSecret = tokenSecret; this.clientId = clientId; this.clientSecret = clientSecret; this.context = context; }
public LibraryService(ITrackFileCollector fileCollector, IDriveServiceFactory driveServiceFactory, MusicLibraryContext context, ITrackInfoCollector infoCollector) { this.fileCollector = fileCollector; this.driveServiceFactory = driveServiceFactory; this.context = context; this.infoCollector = infoCollector; }
private void SaveChanges() { using (MusicLibraryContext dbContext = new MusicLibraryContext()) { dbContext.Attach(this.data); dbContext.SaveChanges(); } }
private void LoadSongs() { using (MusicLibraryContext dbContext = new MusicLibraryContext()) { dbContext .Attach(this.data) .Collection(album => album.Songs) .Load(); } }
private void LoadAlbums() { using (MusicLibraryContext dbContext = new MusicLibraryContext()) { dbContext .Attach(this.data) .Collection(artist => artist.Albums) .Load(); } }
private void PopulateDataGridView() { dataGridViewSong.AutoGenerateColumns = false; using (MusicLibraryContext musicLibraryContext = new MusicLibraryContext()) { dataGridViewSong.DataSource = musicLibraryContext.Songs.ToList <Song>(); comboBoxAlbum.DataSource = musicLibraryContext.Albums.ToList <Album>(); comboBoxGenre.DataSource = musicLibraryContext.Genres.ToList <Genre>(); } }
private bool HasAnySongs() { using (MusicLibraryContext dbContext = new MusicLibraryContext()) { return(dbContext .Entry(this.data) .Collection(album => album.Songs) .Query() .Any()); } }
protected override List <Song> GetByPrimaryKeys(List <int> primaryKeyCollection) { using (MusicLibraryContext dbContext = new MusicLibraryContext()) { return(dbContext.Songs .Include(song => song.Album) .Include(song => song.Album.Artist) .Where(song => primaryKeyCollection.Contains(song.SongId)) .ToList()); } }
protected override List <Artist> GetByPrimaryKeys(List <int> primaryKeyCollection) { using (MusicLibraryContext dbContext = new MusicLibraryContext()) { List <Artist> artists = dbContext.Artists .Where(artist => primaryKeyCollection.Contains(artist.ArtistId)) .ToList(); return(artists); } }
private bool LoadFavorite() { using (MusicLibraryContext dbContext = new MusicLibraryContext()) { return(this.anySongs && dbContext .Attach(this.data) .Collection(album => album.Songs) .Query() .All(song => song.Favorite)); } }
protected override List <int> GetItemIdsForSearchTerms(string searchTerm) { using (MusicLibraryContext dbContext = new MusicLibraryContext()) { return(dbContext.Artists .Where( artist => artist.Name.ContainsIgnoreCase(searchTerm)) .OrderBy(artist => artist.Name) .Select(artist => artist.ArtistId) .ToList()); } }
private bool LoadFavorite() { using (MusicLibraryContext dbContext = new MusicLibraryContext()) { return(dbContext .Attach(this.data) .Collection(artist => artist.Albums) .Query() .GroupJoin(dbContext.Songs, album => album.AlbumId, song => song.SongId, (album, songs) => songs) .All(songs => songs.All(song => song.Favorite))); } }
protected override List <Album> GetByPrimaryKeys(List <int> primaryKeyCollection) { using (MusicLibraryContext dbContext = new MusicLibraryContext()) { List <Album> albums = dbContext.Albums .Include(album => album.Artist) .Where(album => primaryKeyCollection.Contains(album.AlbumId)) .ToList(); return(albums); } }
protected override List <int> GetItemIdsForSearchTerms(string searchTerm) { using (MusicLibraryContext dbContext = new MusicLibraryContext()) { return(dbContext.Songs .Include(song => song.Album) .ThenInclude(album => album.Artist) .Where( song => song.Title.ContainsIgnoreCase(searchTerm) || song.Album.Name.ContainsIgnoreCase(searchTerm) || song.Album.Artist.Name.ContainsIgnoreCase(searchTerm)) .OrderBy(song => song.Title) .Select(song => song.SongId) .ToList()); } }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { this.InitializeComponent(); this.Suspending += OnSuspending; using (MusicLibraryContext dbContext = new MusicLibraryContext()) { IServiceProvider serviceProvider = dbContext.GetInfrastructure(); // logging ILoggerFactory loggerFactory = serviceProvider.GetService <ILoggerFactory>(); loggerFactory.AddProvider(new LaaudLoggerProvider()); // database creation and schema update dbContext.Database.Migrate(); } }
public async Task <ImageSource> LoadImageAsync() { if (this.anySongs) { Song firstSong; using (MusicLibraryContext dbContext = new MusicLibraryContext()) { firstSong = dbContext .Songs .Where(song => song.AlbumId == this.data.AlbumId) .First(); } return(await SongImageUtil.LoadImageAsync(firstSong.SongId)); } return(ImageUtil.GetAssetsBitmapImageByFileName("Favor.png")); }
private void FavoriteAllSongs(bool favorite) { this.LoadSongs(); using (MusicLibraryContext dbContext = new MusicLibraryContext()) { foreach (Song song in this.data.Songs) { song.Favorite = favorite; dbContext .Attach(song) .Property(_song => _song.Favorite) .IsModified = true; } dbContext.SaveChanges(); } }
public void GetSearchResults(int firstElement, int range) { Task.Factory.StartNew(() => { //int maxVal = range + firstElement >= this.dbIds.Count ? this.dbIds.Count - 1 : range + firstElement; List <int> idsToFetch = this.dbIds.Skip(firstElement + 1).Take(range).ToList(); using (MusicLibraryContext dbContext = new MusicLibraryContext()) { switch (this.groupType) { case SearchResultsGroupType.Song: foreach (Song song in dbContext.Songs .Where(song => idsToFetch.Contains(song.SongId))) { this.SongReceivedFromDBEvent?.Invoke(song); } break; case SearchResultsGroupType.Album: foreach (Album album in dbContext.Albums .Include(album => album.Songs) .Where(album => idsToFetch.Contains(album.AlbumId))) { this.AlbumReceivedFromDBEvent?.Invoke(album); } break; case SearchResultsGroupType.Artist: foreach (Artist artist in dbContext.Artists .Include(artist => artist.Albums) .Include("Albums.Songs") .Where(artist => idsToFetch.Contains(artist.ArtistId))) { this.ArtistReceivedFromDBEvent?.Invoke(artist); } break; } } }); }
private void FavoriteAllSongs(bool favorite) { this.LoadAlbums(); using (MusicLibraryContext dbContext = new MusicLibraryContext()) { foreach (Album album in this.data.Albums) { List <Song> songs = dbContext.Songs.Where(song => song.AlbumId == album.AlbumId).ToList(); foreach (Song song in songs) { song.Favorite = favorite; dbContext .Attach(song) .Property(_song => _song.Favorite) .IsModified = true; } } dbContext.SaveChanges(); } }
public UploadFilesToAzureWorkflow(MusicLibraryContext context, IDriveServiceFactory driveServiceFactory, LibraryService libraryService) { this.context = context; this.driveServiceFactory = driveServiceFactory; this.libraryService = libraryService; }
public BaseRepository(MusicLibraryContext context) { Context = context; DbSet = context.Set <T>(); }
public static void Initialize() { Database.SetInitializer(new MigrateDatabaseToLatestVersion <MusicLibraryContext, Configuration>()); MusicLibraryContext.Create().Database.CreateIfNotExists(); }
public TrackStreamService(MusicLibraryContext context, IDriveServiceFactory driveServiceFactory, string tokenSecret) { this.context = context; this.driveServiceFactory = driveServiceFactory; this.tokenSecret = tokenSecret; }
public GenreRepository(MusicLibraryContext context) : base(context) { }
protected BaseRepository(MusicLibraryContext context) { this.context = context; }
public ArtistController() { MusicLibraryContext context = new MusicLibraryContext(); this.data = new EfRepository <Artist>(context); }
public AlbumController() { MusicLibraryContext context = new MusicLibraryContext(); this.data = new EfRepository <Album>(context); }
public CompositionRepository(MusicLibraryContext context) : base(context) { }
static void Main(string[] args) { var file = args[0]; Console.WriteLine("Importing records from file: " + file + " ...."); var csv = new CsvHelper.CsvReader(File.OpenText(file)); csv.Configuration.HasHeaderRecord = true; var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot configuration = builder.Build(); csv.Read(); csv.ReadHeader(); var album = String.Empty; var artists = new Dictionary <string, Artist>(); var ctx = new DbContextOptionsBuilder <MusicLibraryContext>(); ctx.UseSqlServer <MusicLibraryContext>(configuration.GetConnectionString("MusicLibraryDB")); using (var db = new MusicLibraryContext(ctx.Options)) { var alb = new Album(); var art = new Artist(); while (csv.Read()) { var r = csv.GetRecord <TrackRecord>(); if (r.Album != album) { album = r.Album; int y; alb = new Album { Title = r.Album, AlbumArtist = r.AlbumArtist, Year = (Int32.TryParse(r.Year, out y) ? (int?)y : null) }; db.Albums.Add(alb); } if (!artists.ContainsKey(r.Artist)) { art = new Artist { Title = r.Artist, }; db.Artists.Add(art); artists.Add(r.Artist, art); } else { art = artists[r.Artist]; } int dn; var t = new Track { Album = alb, Artist = art, Title = r.Title, TrackNum = r.TrackNum, DiscNum = (Int32.TryParse(r.DiscNum, out dn) ? (int?)dn : null) }; db.Tracks.Add(t); } db.SaveChanges(); } Console.WriteLine("Import complete - press any key to exit..."); Console.ReadLine(); }
public LoginRepository() { this._context = new MusicLibraryContext(); }