コード例 #1
0
 public GoogleTokenProviderService(string tokenSecret, string clientId, string clientSecret, MusicLibraryContext context)
 {
     this.tokenSecret  = tokenSecret;
     this.clientId     = clientId;
     this.clientSecret = clientSecret;
     this.context      = context;
 }
コード例 #2
0
 public LibraryService(ITrackFileCollector fileCollector, IDriveServiceFactory driveServiceFactory, MusicLibraryContext context, ITrackInfoCollector infoCollector)
 {
     this.fileCollector       = fileCollector;
     this.driveServiceFactory = driveServiceFactory;
     this.context             = context;
     this.infoCollector       = infoCollector;
 }
コード例 #3
0
 private void SaveChanges()
 {
     using (MusicLibraryContext dbContext = new MusicLibraryContext())
     {
         dbContext.Attach(this.data);
         dbContext.SaveChanges();
     }
 }
コード例 #4
0
 private void LoadSongs()
 {
     using (MusicLibraryContext dbContext = new MusicLibraryContext())
     {
         dbContext
         .Attach(this.data)
         .Collection(album => album.Songs)
         .Load();
     }
 }
コード例 #5
0
 private void LoadAlbums()
 {
     using (MusicLibraryContext dbContext = new MusicLibraryContext())
     {
         dbContext
         .Attach(this.data)
         .Collection(artist => artist.Albums)
         .Load();
     }
 }
コード例 #6
0
 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>();
     }
 }
コード例 #7
0
 private bool HasAnySongs()
 {
     using (MusicLibraryContext dbContext = new MusicLibraryContext())
     {
         return(dbContext
                .Entry(this.data)
                .Collection(album => album.Songs)
                .Query()
                .Any());
     }
 }
コード例 #8
0
 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());
     }
 }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
 private bool LoadFavorite()
 {
     using (MusicLibraryContext dbContext = new MusicLibraryContext())
     {
         return(this.anySongs &&
                dbContext
                .Attach(this.data)
                .Collection(album => album.Songs)
                .Query()
                .All(song => song.Favorite));
     }
 }
コード例 #11
0
 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());
     }
 }
コード例 #12
0
 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)));
     }
 }
コード例 #13
0
        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);
            }
        }
コード例 #14
0
 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());
     }
 }
コード例 #15
0
ファイル: App.xaml.cs プロジェクト: WesterWest/Laaud-UWP
        /// <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();
            }
        }
コード例 #16
0
        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"));
        }
コード例 #17
0
        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();
            }
        }
コード例 #18
0
        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;
                    }
                }
            });
        }
コード例 #19
0
        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();
            }
        }
コード例 #20
0
 public UploadFilesToAzureWorkflow(MusicLibraryContext context, IDriveServiceFactory driveServiceFactory, LibraryService libraryService)
 {
     this.context             = context;
     this.driveServiceFactory = driveServiceFactory;
     this.libraryService      = libraryService;
 }
コード例 #21
0
 public BaseRepository(MusicLibraryContext context)
 {
     Context = context;
     DbSet   = context.Set <T>();
 }
コード例 #22
0
 public static void Initialize()
 {
     Database.SetInitializer(new MigrateDatabaseToLatestVersion <MusicLibraryContext, Configuration>());
     MusicLibraryContext.Create().Database.CreateIfNotExists();
 }
コード例 #23
0
 public TrackStreamService(MusicLibraryContext context, IDriveServiceFactory driveServiceFactory, string tokenSecret)
 {
     this.context             = context;
     this.driveServiceFactory = driveServiceFactory;
     this.tokenSecret         = tokenSecret;
 }
コード例 #24
0
 public GenreRepository(MusicLibraryContext context) : base(context)
 {
 }
コード例 #25
0
 protected BaseRepository(MusicLibraryContext context)
 {
     this.context = context;
 }
コード例 #26
0
        public ArtistController()
        {
            MusicLibraryContext context = new MusicLibraryContext();

            this.data = new EfRepository <Artist>(context);
        }
コード例 #27
0
        public AlbumController()
        {
            MusicLibraryContext context = new MusicLibraryContext();

            this.data = new EfRepository <Album>(context);
        }
コード例 #28
0
 public CompositionRepository(MusicLibraryContext context) : base(context)
 {
 }
コード例 #29
0
        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();
        }
コード例 #30
0
 public LoginRepository()
 {
     this._context = new MusicLibraryContext();
 }