internal void Merge(CDEntry slave)
 {
     if (slave != null)
     {
         Artist       = StringUtils.TakeValid(Artist, slave.Artist);
         ExtendedData = StringUtils.TakeValid(ExtendedData, slave.ExtendedData);
         Genre        = StringUtils.TakeValid(Genre, slave.Genre);
         PlayOrder    = StringUtils.TakeValid(PlayOrder, slave.PlayOrder);
         Title        = StringUtils.TakeValid(Title, slave.Title);
         Year         = StringUtils.TakeValid(Year, slave.Year);
         Tracks       = MergeTracks(Tracks, slave.Tracks);
     }
 }
示例#2
0
        /// <summary>
        /// Read Entry from the database.
        /// </summary>
        /// <param name="qr">A QueryResult object that is created by performing a query</param>
        /// <param name="cdEntry">out parameter - CDEntry object</param>
        /// <returns></returns>
        public string Read(QueryResult qr, out CDEntry cdEntry)
        {
            StringBuilder builder = new StringBuilder(FreedbHelper.Commands.CMD_READ);

            builder.Append(" ");
            builder.Append(qr.Category);
            builder.Append(" ");
            builder.Append(qr.Discid);

            cdEntry = null;

            try
            {
                string        request = builder.ToString();
                List <string> reply   = SendRequest(request);

                if (reply.Count <= 0)
                {
                    string    msg = "No results returned from cddb query.";
                    Exception ex  = new Exception(msg, null);
                    throw ex;
                }

                string code = GetReplyCode(reply, request);

                switch (code)
                {
                case ResponseCodes.CODE_210:
                case ResponseCodes.CODE_211:
                {
                    //remove first line, this one has code 210 or 211
                    reply.RemoveAt(0);
                    cdEntry = new CDEntry(reply);
                }
                break;
                }

                return(code);
            }
            catch (Exception ex)
            {
                string    msg   = "Unable to perform cddb query.";
                Exception newex = new Exception(msg, ex);
                throw newex;
            }
        }
示例#3
0
        public void RefreshDisk()
        {
            string rootPath = System.IO.Path.GetPathRoot(this.Path);
            if (!string.IsNullOrEmpty(rootPath))
            {
                char letter = rootPath.ToUpperInvariant()[0];
                {
                    using (CDDrive cd = new CDDrive())
                    {
                        if (cd.Open(letter) && cd.Refresh())
                        {
                            switch (ProTONEConfig.AudioCdInfoSource)
                            {
                                case CddaInfoSource.CdText:
                                    _cdEntry = BuildCdEntryByCdText(cd, _discId);
                                    break;

                                case CddaInfoSource.Cddb:
                                    _cdEntry = BuildCdEntryByCddb(cd, _discId);
                                    break;

                                case CddaInfoSource.CdText_Cddb:
                                    {
                                        _cdEntry = BuildCdEntryByCdText(cd, _discId);
                                        CDEntry cde = BuildCdEntryByCddb(cd, _discId);
                                        _cdEntry = Merge(_cdEntry, cde);
                                    }
                                    break;

                                case CddaInfoSource.Cddb_CdText:
                                    {
                                        _cdEntry = BuildCdEntryByCddb(cd, _discId);
                                        CDEntry cde = BuildCdEntryByCdText(cd, _discId);
                                        _cdEntry = Merge(_cdEntry, cde);
                                    }
                                    break;

                                default:
                                    break;
                            }

                            if (_cdEntry != null)
                            {
                                _cdEntry.PersistDisc();
                            }
                        }
                    }
                }
            }
        }
示例#4
0
        public static CDEntry Merge(CDEntry master, CDEntry slave)
        {
            if (master == null)
                return slave;

            master.Merge(slave);

            return master;
        }
示例#5
0
        public static CDEntry BuildCdEntryByCdText(CDDrive cd, string diskId)
        {
            List<Track> tracks = null;
            if (cd.ReadCDText(out tracks))
            {
                CDEntry cdEntry = new CDEntry(diskId);
                cdEntry.Tracks.AddRange(tracks);

                return cdEntry;
            }

            return null;
        }
示例#6
0
        public CDAFileInfo(string path, bool deepLoad)
            : base(path, false)
        {
            try
            {
                string rootPath = System.IO.Path.GetPathRoot(path);
                if (!string.IsNullOrEmpty(rootPath))
                {
                    char letter = rootPath.ToUpperInvariant()[0];
                    using (CDDrive cd = new CDDrive())
                    {
                        if (cd.Open(letter) && cd.Refresh())
                        {
                            string trackStr = path.Replace(rootPath, "").ToLowerInvariant().Replace("track", "").Replace(".cda", "");
                            _track = -1;
                            if (int.TryParse(trackStr, out _track) && _track > 0)
                            {
                                if (cd.IsAudioTrack(_track))
                                {
                                    _duration = cd.GetSeconds(_track);

                                    _discId = cd.GetCDDBDiskID();

                                    // Check whether the disc is already added to our FreeDb lite database
                                    _cdEntry = CDEntry.LoadPersistentDisc(_discId);
                                    if (_cdEntry == null)
                                    {
                                        RefreshDisk();
                                    }

                                    return;
                                }
                            }
                        }
                    }

                    _cdEntry = null;
                }
            }
            catch(Exception ex) 
            {
                Logger.LogException(ex);
                _cdEntry = null;
            }
        }
示例#7
0
        public override void Rebuild()
        {
            if (!string.IsNullOrEmpty(_discId))
            {
                CDEntry cde = CDEntry.LoadPersistentDisc(_discId);
                if (cde != null)
                {
                    _cdEntry = cde;
                    return;
                }
            }

            RefreshDisk();
        }
示例#8
0
		/// <summary>
		/// Read Entry from the database. 
		/// </summary>
		/// <param name="qr">A QueryResult object that is created by performing a query</param>
		/// <param name="cdEntry">out parameter - CDEntry object</param>
		/// <returns></returns>
		public string Read(QueryResult qr, out CDEntry cdEntry)
		{
            StringBuilder builder = new StringBuilder(FreedbHelper.Commands.CMD_READ);
            builder.Append(" ");
            builder.Append(qr.Category);
            builder.Append(" ");
            builder.Append(qr.Discid);

            cdEntry = null;

            try
            {
                string request = builder.ToString();
                List<string> reply = SendRequest(request);

                if (reply.Count <= 0)
                {
                    string msg = "No results returned from cddb query.";
                    Exception ex = new Exception(msg, null);
                    throw ex;
                }

                string code = GetReplyCode(reply, request);
                
                switch (code)
                {
                    case ResponseCodes.CODE_210:
                    case ResponseCodes.CODE_211:
                        {
                            //remove first line, this one has code 210 or 211
                            reply.RemoveAt(0);
                            cdEntry = new CDEntry(reply);
                        }
                        break;
                }

                return code;
            }
            catch (Exception ex)
            {
                string msg = "Unable to perform cddb query.";
                Exception newex = new Exception(msg, ex);
                throw newex;
            }
		}
示例#9
0
 internal void Merge(CDEntry slave)
 {
     if (slave != null)
     {
         Artist = StringUtils.TakeValid(Artist, slave.Artist);
         ExtendedData = StringUtils.TakeValid(ExtendedData, slave.ExtendedData);
         Genre = StringUtils.TakeValid(Genre, slave.Genre);
         PlayOrder = StringUtils.TakeValid(PlayOrder, slave.PlayOrder);
         Title = StringUtils.TakeValid(Title, slave.Title);
         Year = StringUtils.TakeValid(Year, slave.Year);
         Tracks = MergeTracks(Tracks, slave.Tracks);
     }
 }