Beispiel #1
0
 private void Thumbnail()
 {
     if (_store != null)
     {
         lock (pendingFiles) {
             DebugFormat("Passing {0} files to background cacher", pendingFiles.Count);
             BackgroundCacher.AddFiles(_store, pendingFiles);
         }
     }
     ClearPending();
 }
Beispiel #2
0
 private void Thumbnail()
 {
     try {
         if (store == null)
         {
             return;
         }
         DebugFormat(
             "Passing {0} files to background cacher", pendingFiles.Count);
         BackgroundCacher.AddFiles(store, pendingFiles);
     }
     finally {
         Interlocked.Exchange(ref pendingFiles, new ConcurrentQueue <WeakReference>());
     }
 }
Beispiel #3
0
 private void Thumbnail()
 {
     if (store == null)
     {
         lock (this) {
             pendingFiles.Clear();
         }
         return;
     }
     lock (this) {
         DebugFormat(
             "Passing {0} files to background cacher", pendingFiles.Count);
         BackgroundCacher.AddFiles(store, pendingFiles);
         pendingFiles.Clear();
     }
 }
Beispiel #4
0
        private void OnChanged(object source, FileSystemEventArgs e)
        {
            try {
                watcherRestartCount = 0;
                if (store != null &&
                    icomparer.Equals(e.FullPath, store.StoreFile.FullName))
                {
                    return;
                }
                var ext = string.Empty;
                if (!string.IsNullOrEmpty(e.FullPath))
                {
                    ext = Path.GetExtension(e.FullPath);
                    ext = string.IsNullOrEmpty(ext) ? string.Empty : ext.Substring(1);
                }
                if (!Filter.Filtered(ext))
                {
                    // Check if this is a meta data filter file and there are files in the same folder
                    if (MetaFilter.Filtered(ext) && e.ChangeType != WatcherChangeTypes.Deleted)
                    {
                        var affectedFiles = Directory.GetFiles(Path.GetDirectoryName(e.FullPath)).Where(f => Filter.Filtered(Path.GetExtension(f).Substring(1)));
                        var refreshFiles  = new ConcurrentQueue <WeakReference>();
                        foreach (var file in affectedFiles)
                        {
                            // Add the files to the pending files list
                            var type = DlnaMaps.Ext2Dlna[Path.GetExtension(file).ToUpperInvariant().Substring(1)];
                            if (store != null)
                            {
                                var item = store.MaybeGetFile(this, new FileInfo(file), type);
                                if (item != null)
                                {
                                    refreshFiles.Enqueue(new WeakReference(item));
                                }
                            }
                        }
                        BackgroundCacher.AddFiles(store, refreshFiles);

                        DebugFormat("Found {0} affected files from metadata file {1}", affectedFiles.Count(), e.FullPath);
                    }
                    else
                    {
                        DebugFormat(
                            "Skipping name {0} {1}",
                            e.Name, Path.GetExtension(e.FullPath));
                    }
                    return;
                }
                DebugFormat(
                    "File System changed ({1}): {0}", e.FullPath, e.ChangeType);
                lock (ids) {
                    var master = ids.GetItemById(Identifiers.GENERAL_ROOT) as VirtualFolder;
                    if (master != null)
                    {
                        switch (e.ChangeType)
                        {
                        case WatcherChangeTypes.Changed:
                            if (HandleFileDeleted(e.FullPath, master) && HandleFileAdded(e.FullPath))
                            {
                                ReaddRoot(master);
                                return;
                            }
                            break;

                        case WatcherChangeTypes.Created:
                            if (HandleFileAdded(e.FullPath))
                            {
                                ReaddRoot(master);
                                return;
                            }
                            break;

                        case WatcherChangeTypes.Deleted:
                            if (HandleFileDeleted(e.FullPath, master))
                            {
                                ReaddRoot(master);
                                return;
                            }
                            break;
                        }
                    }
                }
                DelayedRescan(e.ChangeType);
            }
            catch (Exception ex) {
                Error("OnChanged failed", ex);
            }
        }