LibraryMonitor.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. using MediaBrowser.Common.IO;
  2. using MediaBrowser.Common.ScheduledTasks;
  3. using MediaBrowser.Controller.Configuration;
  4. using MediaBrowser.Controller.Entities;
  5. using MediaBrowser.Controller.Library;
  6. using MediaBrowser.Controller.Plugins;
  7. using MediaBrowser.Model.Configuration;
  8. using MediaBrowser.Model.Logging;
  9. using MediaBrowser.Server.Implementations.ScheduledTasks;
  10. using Microsoft.Win32;
  11. using System;
  12. using System.Collections.Concurrent;
  13. using System.Collections.Generic;
  14. using System.IO;
  15. using System.Linq;
  16. using System.Threading;
  17. using System.Threading.Tasks;
  18. using CommonIO;
  19. using MediaBrowser.Controller;
  20. namespace MediaBrowser.Server.Implementations.IO
  21. {
  22. public class LibraryMonitor : ILibraryMonitor
  23. {
  24. /// <summary>
  25. /// The file system watchers
  26. /// </summary>
  27. private readonly ConcurrentDictionary<string, FileSystemWatcher> _fileSystemWatchers = new ConcurrentDictionary<string, FileSystemWatcher>(StringComparer.OrdinalIgnoreCase);
  28. /// <summary>
  29. /// The update timer
  30. /// </summary>
  31. private Timer _updateTimer;
  32. /// <summary>
  33. /// The affected paths
  34. /// </summary>
  35. private readonly ConcurrentDictionary<string, string> _affectedPaths = new ConcurrentDictionary<string, string>();
  36. /// <summary>
  37. /// A dynamic list of paths that should be ignored. Added to during our own file sytem modifications.
  38. /// </summary>
  39. private readonly ConcurrentDictionary<string, string> _tempIgnoredPaths = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  40. /// <summary>
  41. /// Any file name ending in any of these will be ignored by the watchers
  42. /// </summary>
  43. private readonly IReadOnlyList<string> _alwaysIgnoreFiles = new List<string>
  44. {
  45. "thumbs.db",
  46. "small.jpg",
  47. "albumart.jpg",
  48. // WMC temp recording directories that will constantly be written to
  49. "TempRec",
  50. "TempSBE"
  51. };
  52. /// <summary>
  53. /// The timer lock
  54. /// </summary>
  55. private readonly object _timerLock = new object();
  56. /// <summary>
  57. /// Add the path to our temporary ignore list. Use when writing to a path within our listening scope.
  58. /// </summary>
  59. /// <param name="path">The path.</param>
  60. private void TemporarilyIgnore(string path)
  61. {
  62. _tempIgnoredPaths[path] = path;
  63. }
  64. public void ReportFileSystemChangeBeginning(string path)
  65. {
  66. if (string.IsNullOrEmpty(path))
  67. {
  68. throw new ArgumentNullException("path");
  69. }
  70. TemporarilyIgnore(path);
  71. }
  72. public bool IsPathLocked(string path)
  73. {
  74. var lockedPaths = _tempIgnoredPaths.Keys.ToList();
  75. return lockedPaths.Any(i => string.Equals(i, path, StringComparison.OrdinalIgnoreCase) || _fileSystem.ContainsSubPath(i, path));
  76. }
  77. public async void ReportFileSystemChangeComplete(string path, bool refreshPath)
  78. {
  79. if (string.IsNullOrEmpty(path))
  80. {
  81. throw new ArgumentNullException("path");
  82. }
  83. // This is an arbitraty amount of time, but delay it because file system writes often trigger events long after the file was actually written to.
  84. // Seeing long delays in some situations, especially over the network, sometimes up to 45 seconds
  85. // But if we make this delay too high, we risk missing legitimate changes, such as user adding a new file, or hand-editing metadata
  86. await Task.Delay(25000).ConfigureAwait(false);
  87. string val;
  88. _tempIgnoredPaths.TryRemove(path, out val);
  89. if (refreshPath)
  90. {
  91. ReportFileSystemChanged(path);
  92. }
  93. }
  94. /// <summary>
  95. /// Gets or sets the logger.
  96. /// </summary>
  97. /// <value>The logger.</value>
  98. private ILogger Logger { get; set; }
  99. /// <summary>
  100. /// Gets or sets the task manager.
  101. /// </summary>
  102. /// <value>The task manager.</value>
  103. private ITaskManager TaskManager { get; set; }
  104. private ILibraryManager LibraryManager { get; set; }
  105. private IServerConfigurationManager ConfigurationManager { get; set; }
  106. private readonly IFileSystem _fileSystem;
  107. private readonly IServerApplicationHost _appHost;
  108. /// <summary>
  109. /// Initializes a new instance of the <see cref="LibraryMonitor" /> class.
  110. /// </summary>
  111. public LibraryMonitor(ILogManager logManager, ITaskManager taskManager, ILibraryManager libraryManager, IServerConfigurationManager configurationManager, IFileSystem fileSystem, IServerApplicationHost appHost)
  112. {
  113. if (taskManager == null)
  114. {
  115. throw new ArgumentNullException("taskManager");
  116. }
  117. LibraryManager = libraryManager;
  118. TaskManager = taskManager;
  119. Logger = logManager.GetLogger(GetType().Name);
  120. ConfigurationManager = configurationManager;
  121. _fileSystem = fileSystem;
  122. _appHost = appHost;
  123. SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
  124. }
  125. /// <summary>
  126. /// Handles the PowerModeChanged event of the SystemEvents control.
  127. /// </summary>
  128. /// <param name="sender">The source of the event.</param>
  129. /// <param name="e">The <see cref="PowerModeChangedEventArgs"/> instance containing the event data.</param>
  130. void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
  131. {
  132. Restart();
  133. }
  134. private void Restart()
  135. {
  136. Stop();
  137. Start();
  138. }
  139. private bool EnableLibraryMonitor
  140. {
  141. get
  142. {
  143. switch (ConfigurationManager.Configuration.EnableLibraryMonitor)
  144. {
  145. case AutoOnOff.Auto:
  146. return Environment.OSVersion.Platform == PlatformID.Win32NT;
  147. case AutoOnOff.Enabled:
  148. return true;
  149. default:
  150. return false;
  151. }
  152. }
  153. }
  154. public void Start()
  155. {
  156. if (EnableLibraryMonitor)
  157. {
  158. StartInternal();
  159. }
  160. }
  161. /// <summary>
  162. /// Starts this instance.
  163. /// </summary>
  164. private void StartInternal()
  165. {
  166. LibraryManager.ItemAdded += LibraryManager_ItemAdded;
  167. LibraryManager.ItemRemoved += LibraryManager_ItemRemoved;
  168. var pathsToWatch = new List<string> { LibraryManager.RootFolder.Path };
  169. var paths = LibraryManager
  170. .RootFolder
  171. .Children
  172. .OfType<Folder>()
  173. .SelectMany(f => f.PhysicalLocations)
  174. .Distinct(StringComparer.OrdinalIgnoreCase)
  175. .OrderBy(i => i)
  176. .ToList();
  177. foreach (var path in paths)
  178. {
  179. if (!ContainsParentFolder(pathsToWatch, path))
  180. {
  181. pathsToWatch.Add(path);
  182. }
  183. }
  184. foreach (var path in pathsToWatch)
  185. {
  186. StartWatchingPath(path);
  187. }
  188. }
  189. /// <summary>
  190. /// Handles the ItemRemoved event of the LibraryManager control.
  191. /// </summary>
  192. /// <param name="sender">The source of the event.</param>
  193. /// <param name="e">The <see cref="ItemChangeEventArgs"/> instance containing the event data.</param>
  194. void LibraryManager_ItemRemoved(object sender, ItemChangeEventArgs e)
  195. {
  196. if (e.Item.GetParent() is AggregateFolder)
  197. {
  198. StopWatchingPath(e.Item.Path);
  199. }
  200. }
  201. /// <summary>
  202. /// Handles the ItemAdded event of the LibraryManager control.
  203. /// </summary>
  204. /// <param name="sender">The source of the event.</param>
  205. /// <param name="e">The <see cref="ItemChangeEventArgs"/> instance containing the event data.</param>
  206. void LibraryManager_ItemAdded(object sender, ItemChangeEventArgs e)
  207. {
  208. if (e.Item.GetParent() is AggregateFolder)
  209. {
  210. StartWatchingPath(e.Item.Path);
  211. }
  212. }
  213. /// <summary>
  214. /// Examine a list of strings assumed to be file paths to see if it contains a parent of
  215. /// the provided path.
  216. /// </summary>
  217. /// <param name="lst">The LST.</param>
  218. /// <param name="path">The path.</param>
  219. /// <returns><c>true</c> if [contains parent folder] [the specified LST]; otherwise, <c>false</c>.</returns>
  220. /// <exception cref="System.ArgumentNullException">path</exception>
  221. private static bool ContainsParentFolder(IEnumerable<string> lst, string path)
  222. {
  223. if (string.IsNullOrEmpty(path))
  224. {
  225. throw new ArgumentNullException("path");
  226. }
  227. path = path.TrimEnd(Path.DirectorySeparatorChar);
  228. return lst.Any(str =>
  229. {
  230. //this should be a little quicker than examining each actual parent folder...
  231. var compare = str.TrimEnd(Path.DirectorySeparatorChar);
  232. return (path.Equals(compare, StringComparison.OrdinalIgnoreCase) || (path.StartsWith(compare, StringComparison.OrdinalIgnoreCase) && path[compare.Length] == Path.DirectorySeparatorChar));
  233. });
  234. }
  235. /// <summary>
  236. /// Starts the watching path.
  237. /// </summary>
  238. /// <param name="path">The path.</param>
  239. private void StartWatchingPath(string path)
  240. {
  241. // Creating a FileSystemWatcher over the LAN can take hundreds of milliseconds, so wrap it in a Task to do them all in parallel
  242. Task.Run(() =>
  243. {
  244. try
  245. {
  246. var newWatcher = new FileSystemWatcher(path, "*")
  247. {
  248. IncludeSubdirectories = true
  249. };
  250. if (Environment.OSVersion.Platform == PlatformID.Win32NT)
  251. {
  252. newWatcher.InternalBufferSize = 32767;
  253. }
  254. newWatcher.NotifyFilter = NotifyFilters.CreationTime |
  255. NotifyFilters.DirectoryName |
  256. NotifyFilters.FileName |
  257. NotifyFilters.LastWrite |
  258. NotifyFilters.Size |
  259. NotifyFilters.Attributes;
  260. newWatcher.Created += watcher_Changed;
  261. newWatcher.Deleted += watcher_Changed;
  262. newWatcher.Renamed += watcher_Changed;
  263. newWatcher.Changed += watcher_Changed;
  264. newWatcher.Error += watcher_Error;
  265. if (_fileSystemWatchers.TryAdd(path, newWatcher))
  266. {
  267. newWatcher.EnableRaisingEvents = true;
  268. Logger.Info("Watching directory " + path);
  269. }
  270. else
  271. {
  272. Logger.Info("Unable to add directory watcher for {0}. It already exists in the dictionary.", path);
  273. newWatcher.Dispose();
  274. }
  275. }
  276. catch (Exception ex)
  277. {
  278. Logger.ErrorException("Error watching path: {0}", ex, path);
  279. }
  280. });
  281. }
  282. /// <summary>
  283. /// Stops the watching path.
  284. /// </summary>
  285. /// <param name="path">The path.</param>
  286. private void StopWatchingPath(string path)
  287. {
  288. FileSystemWatcher watcher;
  289. if (_fileSystemWatchers.TryGetValue(path, out watcher))
  290. {
  291. DisposeWatcher(watcher);
  292. }
  293. }
  294. /// <summary>
  295. /// Disposes the watcher.
  296. /// </summary>
  297. /// <param name="watcher">The watcher.</param>
  298. private void DisposeWatcher(FileSystemWatcher watcher)
  299. {
  300. try
  301. {
  302. using (watcher)
  303. {
  304. Logger.Info("Stopping directory watching for path {0}", watcher.Path);
  305. watcher.EnableRaisingEvents = false;
  306. }
  307. }
  308. catch
  309. {
  310. }
  311. finally
  312. {
  313. RemoveWatcherFromList(watcher);
  314. }
  315. }
  316. /// <summary>
  317. /// Removes the watcher from list.
  318. /// </summary>
  319. /// <param name="watcher">The watcher.</param>
  320. private void RemoveWatcherFromList(FileSystemWatcher watcher)
  321. {
  322. FileSystemWatcher removed;
  323. _fileSystemWatchers.TryRemove(watcher.Path, out removed);
  324. }
  325. /// <summary>
  326. /// Handles the Error event of the watcher control.
  327. /// </summary>
  328. /// <param name="sender">The source of the event.</param>
  329. /// <param name="e">The <see cref="ErrorEventArgs" /> instance containing the event data.</param>
  330. void watcher_Error(object sender, ErrorEventArgs e)
  331. {
  332. var ex = e.GetException();
  333. var dw = (FileSystemWatcher)sender;
  334. Logger.ErrorException("Error in Directory watcher for: " + dw.Path, ex);
  335. DisposeWatcher(dw);
  336. if (ConfigurationManager.Configuration.EnableLibraryMonitor == AutoOnOff.Auto)
  337. {
  338. Logger.Info("Disabling realtime monitor to prevent future instability");
  339. ConfigurationManager.Configuration.EnableLibraryMonitor = AutoOnOff.Disabled;
  340. Stop();
  341. }
  342. }
  343. /// <summary>
  344. /// Handles the Changed event of the watcher control.
  345. /// </summary>
  346. /// <param name="sender">The source of the event.</param>
  347. /// <param name="e">The <see cref="FileSystemEventArgs" /> instance containing the event data.</param>
  348. void watcher_Changed(object sender, FileSystemEventArgs e)
  349. {
  350. try
  351. {
  352. Logger.Debug("Changed detected of type " + e.ChangeType + " to " + e.FullPath);
  353. ReportFileSystemChanged(e.FullPath);
  354. }
  355. catch (Exception ex)
  356. {
  357. Logger.ErrorException("Exception in ReportFileSystemChanged. Path: {0}", ex, e.FullPath);
  358. }
  359. }
  360. public void ReportFileSystemChanged(string path)
  361. {
  362. if (string.IsNullOrEmpty(path))
  363. {
  364. throw new ArgumentNullException("path");
  365. }
  366. var filename = Path.GetFileName(path);
  367. var monitorPath = !(!string.IsNullOrEmpty(filename) && _alwaysIgnoreFiles.Contains(filename, StringComparer.OrdinalIgnoreCase));
  368. // Ignore certain files
  369. var tempIgnorePaths = _tempIgnoredPaths.Keys.ToList();
  370. // If the parent of an ignored path has a change event, ignore that too
  371. if (tempIgnorePaths.Any(i =>
  372. {
  373. if (string.Equals(i, path, StringComparison.OrdinalIgnoreCase))
  374. {
  375. Logger.Debug("Ignoring change to {0}", path);
  376. return true;
  377. }
  378. if (_fileSystem.ContainsSubPath(i, path))
  379. {
  380. Logger.Debug("Ignoring change to {0}", path);
  381. return true;
  382. }
  383. // Go up a level
  384. var parent = Path.GetDirectoryName(i);
  385. if (!string.IsNullOrEmpty(parent))
  386. {
  387. if (string.Equals(parent, path, StringComparison.OrdinalIgnoreCase))
  388. {
  389. Logger.Debug("Ignoring change to {0}", path);
  390. return true;
  391. }
  392. }
  393. return false;
  394. }))
  395. {
  396. monitorPath = false;
  397. }
  398. if (monitorPath)
  399. {
  400. // Avoid implicitly captured closure
  401. var affectedPath = path;
  402. _affectedPaths.AddOrUpdate(path, path, (key, oldValue) => affectedPath);
  403. }
  404. RestartTimer();
  405. }
  406. private void RestartTimer()
  407. {
  408. lock (_timerLock)
  409. {
  410. if (_updateTimer == null)
  411. {
  412. _updateTimer = new Timer(TimerStopped, null, TimeSpan.FromSeconds(ConfigurationManager.Configuration.LibraryMonitorDelay), TimeSpan.FromMilliseconds(-1));
  413. }
  414. else
  415. {
  416. _updateTimer.Change(TimeSpan.FromSeconds(ConfigurationManager.Configuration.LibraryMonitorDelay), TimeSpan.FromMilliseconds(-1));
  417. }
  418. }
  419. }
  420. /// <summary>
  421. /// Timers the stopped.
  422. /// </summary>
  423. /// <param name="stateInfo">The state info.</param>
  424. private async void TimerStopped(object stateInfo)
  425. {
  426. // Extend the timer as long as any of the paths are still being written to.
  427. if (_affectedPaths.Any(p => IsFileLocked(p.Key)))
  428. {
  429. Logger.Info("Timer extended.");
  430. RestartTimer();
  431. return;
  432. }
  433. Logger.Debug("Timer stopped.");
  434. DisposeTimer();
  435. var paths = _affectedPaths.Keys.ToList();
  436. _affectedPaths.Clear();
  437. try
  438. {
  439. await ProcessPathChanges(paths).ConfigureAwait(false);
  440. }
  441. catch (Exception ex)
  442. {
  443. Logger.ErrorException("Error processing directory changes", ex);
  444. }
  445. }
  446. private bool IsFileLocked(string path)
  447. {
  448. if (Environment.OSVersion.Platform != PlatformID.Win32NT)
  449. {
  450. // Causing lockups on linux
  451. return false;
  452. }
  453. try
  454. {
  455. var data = _fileSystem.GetFileSystemInfo(path);
  456. if (!data.Exists
  457. || data.IsDirectory
  458. // Opening a writable stream will fail with readonly files
  459. || data.Attributes.HasFlag(FileAttributes.ReadOnly))
  460. {
  461. return false;
  462. }
  463. }
  464. catch (IOException)
  465. {
  466. return false;
  467. }
  468. catch (Exception ex)
  469. {
  470. Logger.ErrorException("Error getting file system info for: {0}", ex, path);
  471. return false;
  472. }
  473. // In order to determine if the file is being written to, we have to request write access
  474. // But if the server only has readonly access, this is going to cause this entire algorithm to fail
  475. // So we'll take a best guess about our access level
  476. var requestedFileAccess = ConfigurationManager.Configuration.SaveLocalMeta
  477. ? FileAccess.ReadWrite
  478. : FileAccess.Read;
  479. try
  480. {
  481. using (_fileSystem.GetFileStream(path, FileMode.Open, requestedFileAccess, FileShare.ReadWrite))
  482. {
  483. if (_updateTimer != null)
  484. {
  485. //file is not locked
  486. return false;
  487. }
  488. }
  489. }
  490. catch (DirectoryNotFoundException)
  491. {
  492. // File may have been deleted
  493. return false;
  494. }
  495. catch (FileNotFoundException)
  496. {
  497. // File may have been deleted
  498. return false;
  499. }
  500. catch (IOException)
  501. {
  502. //the file is unavailable because it is:
  503. //still being written to
  504. //or being processed by another thread
  505. //or does not exist (has already been processed)
  506. Logger.Debug("{0} is locked.", path);
  507. return true;
  508. }
  509. catch (Exception ex)
  510. {
  511. Logger.ErrorException("Error determining if file is locked: {0}", ex, path);
  512. return false;
  513. }
  514. return false;
  515. }
  516. private void DisposeTimer()
  517. {
  518. lock (_timerLock)
  519. {
  520. if (_updateTimer != null)
  521. {
  522. _updateTimer.Dispose();
  523. _updateTimer = null;
  524. }
  525. }
  526. }
  527. /// <summary>
  528. /// Processes the path changes.
  529. /// </summary>
  530. /// <param name="paths">The paths.</param>
  531. /// <returns>Task.</returns>
  532. private async Task ProcessPathChanges(List<string> paths)
  533. {
  534. var itemsToRefresh = paths
  535. .Select(GetAffectedBaseItem)
  536. .Where(item => item != null)
  537. .Distinct()
  538. .ToList();
  539. foreach (var p in paths)
  540. {
  541. Logger.Info(p + " reports change.");
  542. }
  543. // If the root folder changed, run the library task so the user can see it
  544. if (itemsToRefresh.Any(i => i is AggregateFolder))
  545. {
  546. TaskManager.CancelIfRunningAndQueue<RefreshMediaLibraryTask>();
  547. return;
  548. }
  549. foreach (var item in itemsToRefresh)
  550. {
  551. Logger.Info(item.Name + " (" + item.Path + ") will be refreshed.");
  552. try
  553. {
  554. await item.ChangedExternally().ConfigureAwait(false);
  555. }
  556. catch (IOException ex)
  557. {
  558. // For now swallow and log.
  559. // Research item: If an IOException occurs, the item may be in a disconnected state (media unavailable)
  560. // Should we remove it from it's parent?
  561. Logger.ErrorException("Error refreshing {0}", ex, item.Name);
  562. }
  563. catch (Exception ex)
  564. {
  565. Logger.ErrorException("Error refreshing {0}", ex, item.Name);
  566. }
  567. }
  568. }
  569. /// <summary>
  570. /// Gets the affected base item.
  571. /// </summary>
  572. /// <param name="path">The path.</param>
  573. /// <returns>BaseItem.</returns>
  574. private BaseItem GetAffectedBaseItem(string path)
  575. {
  576. BaseItem item = null;
  577. while (item == null && !string.IsNullOrEmpty(path))
  578. {
  579. item = LibraryManager.RootFolder.FindByPath(path);
  580. path = Path.GetDirectoryName(path);
  581. }
  582. if (item != null)
  583. {
  584. // If the item has been deleted find the first valid parent that still exists
  585. while (!_fileSystem.DirectoryExists(item.Path) && !_fileSystem.FileExists(item.Path))
  586. {
  587. item = item.GetParent();
  588. if (item == null)
  589. {
  590. break;
  591. }
  592. }
  593. }
  594. return item;
  595. }
  596. /// <summary>
  597. /// Stops this instance.
  598. /// </summary>
  599. public void Stop()
  600. {
  601. LibraryManager.ItemAdded -= LibraryManager_ItemAdded;
  602. LibraryManager.ItemRemoved -= LibraryManager_ItemRemoved;
  603. foreach (var watcher in _fileSystemWatchers.Values.ToList())
  604. {
  605. watcher.Created -= watcher_Changed;
  606. watcher.Deleted -= watcher_Changed;
  607. watcher.Renamed -= watcher_Changed;
  608. watcher.Changed -= watcher_Changed;
  609. try
  610. {
  611. watcher.EnableRaisingEvents = false;
  612. }
  613. catch (InvalidOperationException)
  614. {
  615. // Seeing this under mono on linux sometimes
  616. // Collection was modified; enumeration operation may not execute.
  617. }
  618. watcher.Dispose();
  619. }
  620. DisposeTimer();
  621. _fileSystemWatchers.Clear();
  622. _affectedPaths.Clear();
  623. }
  624. /// <summary>
  625. /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  626. /// </summary>
  627. public void Dispose()
  628. {
  629. Dispose(true);
  630. GC.SuppressFinalize(this);
  631. }
  632. /// <summary>
  633. /// Releases unmanaged and - optionally - managed resources.
  634. /// </summary>
  635. /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  636. protected virtual void Dispose(bool dispose)
  637. {
  638. if (dispose)
  639. {
  640. Stop();
  641. }
  642. }
  643. }
  644. public class LibraryMonitorStartup : IServerEntryPoint
  645. {
  646. private readonly ILibraryMonitor _monitor;
  647. public LibraryMonitorStartup(ILibraryMonitor monitor)
  648. {
  649. _monitor = monitor;
  650. }
  651. public void Run()
  652. {
  653. _monitor.Start();
  654. }
  655. public void Dispose()
  656. {
  657. }
  658. }
  659. }