Bloom.Collection.BookCollection.WatchDirectory C# (CSharp) Method

WatchDirectory() public method

Watch for changes to your directory (currently just additions). Raise CollectionChanged if you see anything.
public WatchDirectory ( ) : void
return void
        public void WatchDirectory()
        {
            _watcher = new FileSystemWatcher();
            _watcher.Path = PathToDirectory;
            // The default filter, LastWrite|FileName|DirectoryName, is probably OK.
            // Watch everything for now.
            // watcher.Filter = "*.txt";
            _watcher.Created += WatcherOnChange;
            _watcher.Changed += WatcherOnChange;

            // Begin watching.
            _watcher.EnableRaisingEvents = true;
        }

Usage Example

 /// <summary>
 ///
 /// </summary>
 /// <returns>True if the collection should be shown</returns>
 private bool LoadOneCollection(BookCollection collection, FlowLayoutPanel flowLayoutPanel)
 {
     collection.CollectionChanged += OnCollectionChanged;
     bool loadedAtLeastOneBook = false;
     foreach (var bookInfo in collection.GetBookInfos())
     {
         try
         {
             if (!bookInfo.IsExperimental || Settings.Default.ShowExperimentalBooks)
             {
                 loadedAtLeastOneBook = true;
                 AddOneBook(bookInfo, flowLayoutPanel, collection);
             }
         }
         catch (Exception error)
         {
             ErrorReport.NotifyUserOfProblem(error, "Could not load the book at " + bookInfo.FolderPath);
         }
     }
     if (collection.ContainsDownloadedBooks)
     {
         _downloadedBookCollection = collection;
         collection.FolderContentChanged += DownLoadedBooksChanged;
         collection.WatchDirectory(); // In case another instance downloads a book.
         var bloomLibrayLink = new LinkLabel()
         {
             Text =
                 LocalizationManager.GetString("CollectionTab.BloomLibraryLinkLabel",
                                                         "Get more source books at BloomLibrary.org",
                                                         "Shown at the bottom of the list of books. User can click on it and it will attempt to open a browser to show the Bloom Library"),
             Width = 400,
             Margin = new Padding(17, 0, 0, 0),
             LinkColor = Palette.TextAgainstDarkBackground
         };
         bloomLibrayLink.Click += new EventHandler(OnBloomLibrary_Click);
         flowLayoutPanel.Controls.Add(bloomLibrayLink);
         return true;
     }
     return loadedAtLeastOneBook;
 }
All Usage Examples Of Bloom.Collection.BookCollection::WatchDirectory