WatchDirectory() public method

Watch for changes to your directory (currently just additions). Raise CollectionChanged if you see anything.
public WatchDirectory ( ) : void
return void
コード例 #1
0
 /// <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;
 }
コード例 #2
0
 public void WatchDirectory_CausesNotification_OnAddFile()
 {
     var temp = new TemporaryFolder("BookCollectionWatch");
     var collection = new BookCollection(temp.Path, BookCollection.CollectionType.SourceCollection, null);
     collection.WatchDirectory();
     bool gotNotification = false;
     collection.FolderContentChanged += (sender, args) =>
     {
         gotNotification = true;
     };
     File.WriteAllText(Path.Combine(temp.Path, "somefile"), @"This is some test data");
     // It takes a little time to get the notification. This tells NUnit to try every 20ms for up to 1s.
     Assert.That(() => gotNotification, Is.True.After(1000, 20));
 }