示例#1
0
        /// <summary>
        /// Stores the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        public void Save(StorableTaggedFile value)
        {
#if DEBUG
            var sw = Stopwatch.StartNew();
#endif
            var existingFile = fileAdapter.GetFirstById(value.Id);
            if (null != existingFile)
            {
                existingFile = existingFile.LoadReferences(referenceAdapters);
                UpdateConditional(existingFile, value);
                value = existingFile;
                fileAdapter.Delete(existingFile);
            }
            else
            {
                value.Title  = GetTitle(value);
                value.Album  = GetAlbum(value);
                value.Genre  = GetGenre(value);
                value.Artist = GetArtist(value);
                value.Year   = GetYear(value);
            }
            fileAdapter.Save(value);
            CommitToCache(value);
#if DEBUG
            sw.Stop();
            ++persisted;
            totalTime += sw.Elapsed;
            if (DateTime.Now - lastTime < TimeSpan.FromSeconds(2))
            {
                return;
            }
            Trace.WriteLine(string.Format("Persister: ~{0} Items/sec", persisted / totalTime.TotalSeconds));
            lastTime = DateTime.Now;
#endif
        }