Esempio n. 1
0
        public ArtistChangeset Foo(DateTime since)
        {
            using (var context = new Entities.MusixContext())
            {
                var qArtistDelta =
                    from a in context.Artists
                    where a.Touched > since
                    select new ArtistDelta
                {
                    changetype     = a.Deleted ? "D" : "U",
                    idArtist       = a.Id,
                    strArtist      = a.Deleted ? null : a.Name,
                    strBorn        = a.Deleted ? null : a.Born,
                    strFormed      = a.Deleted ? null : a.Formed,
                    strGenres      = a.Deleted ? null : a.Genres,
                    strMoods       = a.Deleted ? null : a.Moods,
                    strStyles      = a.Deleted ? null : a.Styles,
                    strInstruments = a.Deleted ? null : a.Instruments,
                    strBiography   = a.Deleted ? null : a.Biography,
                    strDied        = a.Deleted ? null : a.Died,
                    strDisbanded   = a.Deleted ? null : a.Disbanded,
                    strYearsActive = a.Deleted ? null : a.YearsActive,
                    dtAdded        = a.Deleted ? null : a.Added
                };

                return(new ArtistChangeset
                {
                    From = since,
                    To = context.Now(),
                    Data = qArtistDelta.ToList()
                });
            }
        }
Esempio n. 2
0
        public static void SeedCatalogs()
        {
            using (var c = new MusixContext())
            {
                var mx = new Catalog
                {
                    Guid    = Guid.NewGuid(),
                    Name    = "Musik",
                    Enabled = true
                };
                var hb = new Catalog
                {
                    Guid    = Guid.NewGuid(),
                    Name    = "Hörbücher",
                    Enabled = true
                };
                var hs = new Catalog
                {
                    Guid    = Guid.NewGuid(),
                    Name    = "Hörspiele",
                    Enabled = true
                };

                mx.Paths.Add(new CatalogPath
                {
                    Guid = Guid.NewGuid(),
                    Path = "C:\\Temp\\Musik1"
                });
                mx.Paths.Add(new CatalogPath
                {
                    Guid = Guid.NewGuid(),
                    Path = "C:\\Temp\\Musik2"
                });

                hb.Paths.Add(new CatalogPath
                {
                    Guid = Guid.NewGuid(),
                    Path = "C:\\Temp\\Hörbücher"
                });

                hs.Paths.Add(new CatalogPath
                {
                    Guid = Guid.NewGuid(),
                    Path = "C:\\Temp\\Hörspiele"
                });

                c.Catalogs.Add(mx);
                c.Catalogs.Add(hb);
                c.Catalogs.Add(hs);
                c.SaveChanges();
            }
        }
Esempio n. 3
0
 public void Run()
 {
     using (var context = new MusixContext())
     {
         var catalogs = (from c in context.Catalogs where c.Enabled == true select c).ToList();
         foreach (var catalog in catalogs)
         {
             var catalogpaths = catalog.Paths.ToList();
             foreach (var catalogpath in catalogpaths)
             {
                 Walk(catalogpath.Path);
             }
         }
     }
 }
Esempio n. 4
0
        public static void SeedUsers()
        {
            using (var c = new MusixContext())
            {
                var admin = new User
                {
                    Name     = "Administrator",
                    Login    = "******",
                    Password = "******",
                    Enabled  = true
                };

                c.Users.Add(admin);
                c.SaveChanges();
            }
        }
Esempio n. 5
0
        public void Walk(string path)
        {
            Debug.WriteLine("Process directory: " + path);

            var fileInfo = new FileInfo(path);

            DateTime pathCreated  = new DateTime(fileInfo.CreationTime.Year, fileInfo.CreationTime.Month, fileInfo.CreationTime.Day, fileInfo.CreationTime.Hour, fileInfo.CreationTime.Minute, fileInfo.CreationTime.Second, DateTimeKind.Local);
            DateTime pathModified = new DateTime(fileInfo.LastWriteTime.Year, fileInfo.LastWriteTime.Month, fileInfo.LastWriteTime.Day, fileInfo.LastWriteTime.Hour, fileInfo.LastWriteTime.Minute, fileInfo.LastWriteTime.Second, DateTimeKind.Local);
            DateTime now          = DateTime.Now;

            bool indexFiles       = false;
            bool indexDirectories = false;

            using (var context = new MusixContext())
            {
                var q = from o in context.Paths where o.PathName == path select o;
                var p = q.FirstOrDefault();


                if (p == null)
                {
                    // Directory not listed in database
                    p              = new Path();
                    p.Guid         = Guid.NewGuid();
                    p.PathName     = path;
                    p.PathCreated  = pathCreated;
                    p.PathModified = pathModified;
                    p.RowCreated   = now;
                    p.RowModified  = new DateTime?(now);
                    p.RowDeleted   = new DateTime?();

                    context.Paths.Add(p);
                    context.SaveChanges();

                    indexFiles       = true;
                    indexDirectories = true;
                }
                else
                {
                    // Directory exists in database

//                    if (!pathCreated.Equals(p.PathCreated) || !pathModified.Equals(p.PathModified))
//                    {
                    p.PathCreated  = pathCreated;
                    p.PathModified = pathModified;
                    p.RowModified  = new DateTime?(now);

                    context.SaveChanges();

                    indexFiles       = true;
                    indexDirectories = true;
//                    }
//                    else
//                    {
//                        // No changes within directory
//                        indexFiles = false;
//                        indexDirectories = false;
//                    }
                }
            }


            if (indexFiles)
            {
                foreach (string file in Directory.EnumerateFiles(path))
                {
                    Process(file);
                }
            }
            if (indexDirectories)
            {
                foreach (string directory in Directory.EnumerateDirectories(path))
                {
                    Walk(directory);
                }
            }
        }
Esempio n. 6
0
        public void Process(string path)
        {
            Debug.WriteLine("Process file: " + path);

            FileInfo fileInfo = new FileInfo(path);


            if (fileInfo.Extension.ToLower() != ".mp3")
            {
                return;
            }

            DateTime fileCreated  = new DateTime(fileInfo.CreationTime.Year, fileInfo.CreationTime.Month, fileInfo.CreationTime.Day, fileInfo.CreationTime.Hour, fileInfo.CreationTime.Minute, fileInfo.CreationTime.Second, DateTimeKind.Local);
            DateTime fileModified = new DateTime(fileInfo.LastWriteTime.Year, fileInfo.LastWriteTime.Month, fileInfo.LastWriteTime.Day, fileInfo.LastWriteTime.Hour, fileInfo.LastWriteTime.Minute, fileInfo.LastWriteTime.Second, DateTimeKind.Local);
            DateTime now          = DateTime.Now;
            long     fileSize     = fileInfo.Length;

            string directoryName = fileInfo.DirectoryName;
            string fileName      = fileInfo.Name;

            bool updateMetadata = false;
            bool saveChanges    = false;


            using (var db = new MusixContext())
            {
                var pathQuery = from o in db.Paths where o.PathName == directoryName select o;
                int pathId    = pathQuery.First().Id;

                var songQuery = from o in db.Songs where o.PathId == pathId && o.Filename == fileName select o;
                var song      = songQuery.FirstOrDefault();

                if (song == null)
                {
                    // File is new
                    song      = new Song();
                    song.Guid = Guid.NewGuid();

                    song.PathId       = pathId;
                    song.Filename     = fileName;
                    song.FileCreated  = fileCreated;
                    song.FileModified = fileModified;
                    song.FileSize     = fileSize;

                    song.RowCreated  = now;
                    song.RowModified = new DateTime?(now);
                    song.RowDeleted  = new DateTime?();

                    db.Songs.Add(song);

                    updateMetadata = true;
                    saveChanges    = true;
                }
                else
                {
                    if (fileSize != song.FileSize || !fileCreated.Equals(song.FileCreated) || !fileModified.Equals(song.FileModified))
                    {
                        // File has been modified

                        song.PathId       = pathId;
                        song.Filename     = fileName;
                        song.FileCreated  = fileCreated;
                        song.FileModified = fileModified;
                        song.FileSize     = fileSize;

                        song.RowModified = new DateTime?(now);
                        song.RowDeleted  = new DateTime?();

                        updateMetadata = true;
                        saveChanges    = true;
                    }
                    else
                    {
                        // File is unchanged
                        updateMetadata = false;
                        saveChanges    = false;
                    }
                }



                if (updateMetadata)
                {
                    saveChanges = true;

                    TagLib.File f = TagLib.File.Create(path);
                    Console.WriteLine("Title: " + f.Tag.Title);
                    Console.WriteLine("Performer: " + f.Tag.FirstPerformer);

                    //string s = f.Tag.FirstPerformer;


                    var artistList = new List <Artist>();
                    foreach (var artist in f.Tag.Performers)
                    {
                        Artist artistObj = null;
                        if (db.Artists.Any(o => o.Name == artist))
                        {
                            artistObj = (from x in db.Artists where x.Name == artist select x).First();
                        }
                        else
                        {
                            artistObj = new Artist
                            {
                                Guid = Guid.NewGuid(),
                                Name = artist
                            };
                            db.Artists.Add(artistObj);
                        }
                        artistList.Add(artistObj);
                    }



                    var genreList = new List <Genre>();
                    foreach (var genre in f.Tag.Genres)
                    {
                        Genre genreObj = null;
                        if (db.Genres.Any(o => o.Name == genre))
                        {
                            genreObj = (from x in db.Genres where x.Name == genre select x).First();
                        }
                        else
                        {
                            genreObj = new Genre
                            {
                                Guid = Guid.NewGuid(),
                                Name = genre
                            };
                            db.Genres.Add(genreObj);
                        }
                        genreList.Add(genreObj);
                    }


                    //var album = null;
                    //if (!db.Albums.Any(o => o.Name == f.Tag.Album))
                    //{
                    //    db
                    //}

                    //if (!db)
                    //foreach (var album in f.Tag.Album)


                    song.Title = f.Tag.Title;
                }

                if (saveChanges)
                {
                    db.SaveChanges();
                }
            }
        }