Example #1
0
        private BitmapImage GetCover(TrackEntity t)
        {
            var id = AlbumCoverId(t);

            if (_database.FileStorage.Exists(id))
            {
                using (var stream = new MemoryStream())
                {
                    _database.FileStorage.Download(id, stream);
                    stream.Seek(0, SeekOrigin.Begin);

                    BitmapImage ret = new BitmapImage();
                    ret.BeginInit();
                    ret.StreamSource     = stream;
                    ret.DecodePixelWidth = 300;
                    ret.EndInit();

                    return(ret);
                }
            }
            else
            {
                return(null);
            }
        }
Example #2
0
        private string AlbumCoverId(TrackEntity t)
        {
            var input = t.AlbumArtist + " - " + t.Album;
            var hash  = (new System.Security.Cryptography.SHA1Managed()).ComputeHash(Encoding.UTF8.GetBytes(input));

            return(string.Join("", hash.Select(b => b.ToString("x2")).ToArray()));
        }
Example #3
0
 private void CalculateHash(ref TrackEntity s)
 {
     s.Hash = string.Empty;
     using (var xml = new System.IO.StringWriter())
     {
         var xs = new System.Xml.Serialization.XmlSerializer(typeof(TrackEntity));
         xs.Serialize(xml, s);
         var hash = (new System.Security.Cryptography.SHA1Managed()).ComputeHash(Encoding.UTF8.GetBytes(xml.ToString()));
         s.Hash = string.Join("", hash.Select(b => b.ToString("x2")).ToArray());
     }
 }
Example #4
0
        /// <summary>
        /// Add files to database
        /// </summary>
        /// <param name="filenames">Filenames to add</param>
        public async Task AddFiles(IEnumerable <string> filenames)
        {
            var errors = new StringBuilder();

            foreach (var file in filenames)
            {
                try
                {
                    using (File f = File.Create(file))
                    {
                        var song = new TrackEntity
                        {
                            AddDate     = DateTime.Now,
                            Album       = f.Tag.Album,
                            Artist      = f.Tag.JoinedPerformers,
                            AlbumArtist = f.Tag.FirstAlbumArtist,
                            Comment     = f.Tag.Comment,
                            Disc        = f.Tag.Disc,
                            Track       = f.Tag.Track,
                            FileSize    = f.Length,
                            Generire    = f.Tag.FirstGenre,
                            Length      = f.Properties.Duration.TotalSeconds,
                            LastPlay    = DateTime.MinValue,
                            Path        = file,
                            PlayCounter = 0,
                            Rating      = null,
                            Year        = f.Tag.Year,
                            Title       = f.Tag.Title
                        };
                        CalculateHash(ref song);
                        _tracks.Insert(song);
                        await AddCoverIfNotExist(f.Tag);
                    }
                }
                catch (Exception ex)
                {
                    errors.AppendLine(ex.Message);
                }
            }

            DatabaseCache.Refresh();
            WriteCache();

            if (errors.Length > 0)
            {
                throw new DBException(errors);
            }
        }
Example #5
0
 public void UpdateTrackPlayInfo(TrackEntity selectedTrack)
 {
     selectedTrack.LastPlay     = DateTime.Now;
     selectedTrack.PlayCounter += 1;
     // _tracks.Update(selectedTrack);
 }