private void OnCreated(object sender, FileSystemEventArgs e) { if (_watchFilter.Contains(Path.GetExtension(e.Name))) { try { if (Log.IsDebugEnabled) { Log.DebugFormat("Processing created file: {0}", e.FullPath); } var mediaItem = _mediaItemFactory.Create(e.FullPath); _indexService.Save(mediaItem); } catch (Exception ex) { Log.Error(string.Format("Error processing created file: {0}", e.FullPath), ex); } } else { var directory = new DirectoryInfo(e.FullPath); if (directory.Exists) { try { if (Log.IsDebugEnabled) { Log.DebugFormat("Processing created directory: {0}", e.FullPath); } //TODO: handle created directory - the whole hierarchy since only event for root of new hierarchy is triggered } catch (Exception ex) { Log.Error(string.Format("Error processing created directory: {0}", e.FullPath), ex); } } } }
public void Import() { Log.Info("Import started..."); _store.ClearCollection("MediaItems"); int succeeded = 0; int failed = 0; using (BulkInsertOperation bulkInsert = _store.BulkInsert()) { var files = DirectoryEx.EnumerateFiles(_watchFolder, _watchExtensions, SearchOption.AllDirectories); foreach (var file in files) { try { var mediaItem = _mediaItemFactory.Create(file); if (mediaItem != null) { bulkInsert.Store(mediaItem); succeeded++; if (Log.IsDebugEnabled) { Log.DebugFormat("File indexed: {0}", file); } } } catch (Exception ex) { failed++; Log.ErrorFormat("Failed indexing file: {0}. {1}", file, ex.Message); } } } Log.InfoFormat("Import finished. Succeeded: {0}. Failed: {1}", succeeded, failed); }