ApplicationHost.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. using MediaBrowser.Api;
  2. using MediaBrowser.Common;
  3. using MediaBrowser.Common.Configuration;
  4. using MediaBrowser.Common.Constants;
  5. using MediaBrowser.Common.Extensions;
  6. using MediaBrowser.Common.Implementations;
  7. using MediaBrowser.Common.Implementations.ScheduledTasks;
  8. using MediaBrowser.Common.IO;
  9. using MediaBrowser.Common.MediaInfo;
  10. using MediaBrowser.Common.Net;
  11. using MediaBrowser.Controller;
  12. using MediaBrowser.Controller.Configuration;
  13. using MediaBrowser.Controller.Drawing;
  14. using MediaBrowser.Controller.Entities;
  15. using MediaBrowser.Controller.IO;
  16. using MediaBrowser.Controller.Library;
  17. using MediaBrowser.Controller.Localization;
  18. using MediaBrowser.Controller.MediaInfo;
  19. using MediaBrowser.Controller.Persistence;
  20. using MediaBrowser.Controller.Plugins;
  21. using MediaBrowser.Controller.Providers;
  22. using MediaBrowser.Controller.Resolvers;
  23. using MediaBrowser.Controller.Session;
  24. using MediaBrowser.Controller.Sorting;
  25. using MediaBrowser.Controller.Updates;
  26. using MediaBrowser.Controller.Weather;
  27. using MediaBrowser.IsoMounter;
  28. using MediaBrowser.Model.IO;
  29. using MediaBrowser.Model.MediaInfo;
  30. using MediaBrowser.Model.System;
  31. using MediaBrowser.Model.Updates;
  32. using MediaBrowser.Server.Implementations;
  33. using MediaBrowser.Server.Implementations.BdInfo;
  34. using MediaBrowser.Server.Implementations.Configuration;
  35. using MediaBrowser.Server.Implementations.HttpServer;
  36. using MediaBrowser.Server.Implementations.IO;
  37. using MediaBrowser.Server.Implementations.Library;
  38. using MediaBrowser.Server.Implementations.MediaEncoder;
  39. using MediaBrowser.Server.Implementations.Providers;
  40. using MediaBrowser.Server.Implementations.ServerManager;
  41. using MediaBrowser.Server.Implementations.Session;
  42. using MediaBrowser.Server.Implementations.Sqlite;
  43. using MediaBrowser.Server.Implementations.Updates;
  44. using MediaBrowser.Server.Implementations.WebSocket;
  45. using MediaBrowser.ServerApplication.Implementations;
  46. using MediaBrowser.WebDashboard.Api;
  47. using System;
  48. using System.Collections.Generic;
  49. using System.Diagnostics;
  50. using System.IO;
  51. using System.Linq;
  52. using System.Reflection;
  53. using System.Threading;
  54. using System.Threading.Tasks;
  55. namespace MediaBrowser.ServerApplication
  56. {
  57. /// <summary>
  58. /// Class CompositionRoot
  59. /// </summary>
  60. public class ApplicationHost : BaseApplicationHost<ServerApplicationPaths>, IServerApplicationHost
  61. {
  62. internal const int UdpServerPort = 7359;
  63. /// <summary>
  64. /// Gets the server kernel.
  65. /// </summary>
  66. /// <value>The server kernel.</value>
  67. protected Kernel ServerKernel { get; set; }
  68. /// <summary>
  69. /// Gets the server configuration manager.
  70. /// </summary>
  71. /// <value>The server configuration manager.</value>
  72. public IServerConfigurationManager ServerConfigurationManager
  73. {
  74. get { return (IServerConfigurationManager)ConfigurationManager; }
  75. }
  76. /// <summary>
  77. /// Gets the name of the log file prefix.
  78. /// </summary>
  79. /// <value>The name of the log file prefix.</value>
  80. protected override string LogFilePrefixName
  81. {
  82. get { return "Server"; }
  83. }
  84. /// <summary>
  85. /// Gets the name of the web application that can be used for url building.
  86. /// All api urls will be of the form {protocol}://{host}:{port}/{appname}/...
  87. /// </summary>
  88. /// <value>The name of the web application.</value>
  89. public string WebApplicationName
  90. {
  91. get { return "mediabrowser"; }
  92. }
  93. /// <summary>
  94. /// Gets the HTTP server URL prefix.
  95. /// </summary>
  96. /// <value>The HTTP server URL prefix.</value>
  97. public string HttpServerUrlPrefix
  98. {
  99. get
  100. {
  101. return "http://+:" + ServerConfigurationManager.Configuration.HttpServerPortNumber + "/" + WebApplicationName + "/";
  102. }
  103. }
  104. /// <summary>
  105. /// Gets the configuration manager.
  106. /// </summary>
  107. /// <returns>IConfigurationManager.</returns>
  108. protected override IConfigurationManager GetConfigurationManager()
  109. {
  110. return new ServerConfigurationManager(ApplicationPaths, LogManager, XmlSerializer);
  111. }
  112. /// <summary>
  113. /// Gets or sets the installation manager.
  114. /// </summary>
  115. /// <value>The installation manager.</value>
  116. private IInstallationManager InstallationManager { get; set; }
  117. /// <summary>
  118. /// Gets or sets the server manager.
  119. /// </summary>
  120. /// <value>The server manager.</value>
  121. private IServerManager ServerManager { get; set; }
  122. /// <summary>
  123. /// Gets or sets the user manager.
  124. /// </summary>
  125. /// <value>The user manager.</value>
  126. public IUserManager UserManager { get; set; }
  127. /// <summary>
  128. /// Gets or sets the library manager.
  129. /// </summary>
  130. /// <value>The library manager.</value>
  131. internal ILibraryManager LibraryManager { get; set; }
  132. /// <summary>
  133. /// Gets or sets the directory watchers.
  134. /// </summary>
  135. /// <value>The directory watchers.</value>
  136. private IDirectoryWatchers DirectoryWatchers { get; set; }
  137. /// <summary>
  138. /// Gets or sets the provider manager.
  139. /// </summary>
  140. /// <value>The provider manager.</value>
  141. private IProviderManager ProviderManager { get; set; }
  142. /// <summary>
  143. /// Gets or sets the zip client.
  144. /// </summary>
  145. /// <value>The zip client.</value>
  146. private IZipClient ZipClient { get; set; }
  147. /// <summary>
  148. /// Gets or sets the HTTP server.
  149. /// </summary>
  150. /// <value>The HTTP server.</value>
  151. private IHttpServer HttpServer { get; set; }
  152. /// <summary>
  153. /// Gets or sets the display preferences manager.
  154. /// </summary>
  155. /// <value>The display preferences manager.</value>
  156. internal IDisplayPreferencesManager DisplayPreferencesManager { get; set; }
  157. /// <summary>
  158. /// Gets or sets the media encoder.
  159. /// </summary>
  160. /// <value>The media encoder.</value>
  161. private IMediaEncoder MediaEncoder { get; set; }
  162. /// <summary>
  163. /// Gets or sets the user data repository.
  164. /// </summary>
  165. /// <value>The user data repository.</value>
  166. private IUserDataRepository UserDataRepository { get; set; }
  167. private IUserRepository UserRepository { get; set; }
  168. private IDisplayPreferencesRepository DisplayPreferencesRepository { get; set; }
  169. private IItemRepository ItemRepository { get; set; }
  170. /// <summary>
  171. /// The full path to our startmenu shortcut
  172. /// </summary>
  173. protected override string ProductShortcutPath
  174. {
  175. get { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Media Browser 3", "Media Browser Server.lnk"); }
  176. }
  177. private Task<IHttpServer> _httpServerCreationTask;
  178. /// <summary>
  179. /// Runs the startup tasks.
  180. /// </summary>
  181. /// <returns>Task.</returns>
  182. public override async Task RunStartupTasks()
  183. {
  184. await base.RunStartupTasks().ConfigureAwait(false);
  185. DirectoryWatchers.Start();
  186. Logger.Info("Core startup complete");
  187. Parallel.ForEach(GetExports<IServerEntryPoint>(), entryPoint => entryPoint.Run());
  188. }
  189. /// <summary>
  190. /// Called when [logger loaded].
  191. /// </summary>
  192. protected override void OnLoggerLoaded()
  193. {
  194. base.OnLoggerLoaded();
  195. _httpServerCreationTask = Task.Run(() => ServerFactory.CreateServer(this, LogManager, "Media Browser", "dashboard/index.html"));
  196. }
  197. /// <summary>
  198. /// Registers resources that classes will depend on
  199. /// </summary>
  200. /// <returns>Task.</returns>
  201. protected override async Task RegisterResources()
  202. {
  203. ServerKernel = new Kernel();
  204. await base.RegisterResources().ConfigureAwait(false);
  205. RegisterSingleInstance<IHttpResultFactory>(new HttpResultFactory(LogManager));
  206. RegisterSingleInstance<IServerApplicationHost>(this);
  207. RegisterSingleInstance<IServerApplicationPaths>(ApplicationPaths);
  208. RegisterSingleInstance(ServerKernel);
  209. RegisterSingleInstance(ServerConfigurationManager);
  210. RegisterSingleInstance<IWebSocketServer>(() => new AlchemyServer(Logger));
  211. RegisterSingleInstance<IIsoManager>(() => new PismoIsoManager(Logger));
  212. RegisterSingleInstance<IBlurayExaminer>(() => new BdInfoExaminer());
  213. ZipClient = new DotNetZipClient();
  214. RegisterSingleInstance(ZipClient);
  215. UserDataRepository = new SQLiteUserDataRepository(ApplicationPaths, JsonSerializer, LogManager);
  216. RegisterSingleInstance(UserDataRepository);
  217. UserRepository = new SQLiteUserRepository(ApplicationPaths, JsonSerializer, LogManager);
  218. RegisterSingleInstance(UserRepository);
  219. DisplayPreferencesRepository = new SQLiteDisplayPreferencesRepository(ApplicationPaths, JsonSerializer, LogManager);
  220. RegisterSingleInstance(DisplayPreferencesRepository);
  221. ItemRepository = new SQLiteItemRepository(ApplicationPaths, JsonSerializer, LogManager);
  222. RegisterSingleInstance(ItemRepository);
  223. UserManager = new UserManager(Logger, ServerConfigurationManager);
  224. RegisterSingleInstance(UserManager);
  225. LibraryManager = new LibraryManager(Logger, TaskManager, UserManager, ServerConfigurationManager, UserDataRepository);
  226. RegisterSingleInstance(LibraryManager);
  227. InstallationManager = new InstallationManager(HttpClient, PackageManager, JsonSerializer, Logger, this);
  228. RegisterSingleInstance(InstallationManager);
  229. DirectoryWatchers = new DirectoryWatchers(LogManager, TaskManager, LibraryManager, ServerConfigurationManager);
  230. RegisterSingleInstance(DirectoryWatchers);
  231. ProviderManager = new ProviderManager(HttpClient, ServerConfigurationManager, DirectoryWatchers, LogManager);
  232. RegisterSingleInstance(ProviderManager);
  233. DisplayPreferencesManager = new DisplayPreferencesManager(LogManager.GetLogger("DisplayPreferencesManager"));
  234. RegisterSingleInstance(DisplayPreferencesManager);
  235. RegisterSingleInstance<ILibrarySearchEngine>(() => new LuceneSearchEngine(ApplicationPaths, LogManager, LibraryManager));
  236. MediaEncoder = new MediaEncoder(LogManager.GetLogger("MediaEncoder"), ZipClient, ApplicationPaths, JsonSerializer);
  237. RegisterSingleInstance(MediaEncoder);
  238. var clientConnectionManager = new SessionManager(UserDataRepository, ServerConfigurationManager, Logger, UserRepository);
  239. RegisterSingleInstance<ISessionManager>(clientConnectionManager);
  240. HttpServer = await _httpServerCreationTask.ConfigureAwait(false);
  241. RegisterSingleInstance(HttpServer, false);
  242. ServerManager = new ServerManager(this, JsonSerializer, Logger, ServerConfigurationManager);
  243. RegisterSingleInstance(ServerManager);
  244. var displayPreferencesTask = Task.Run(async () => await ConfigureDisplayPreferencesRepositories().ConfigureAwait(false));
  245. var itemsTask = Task.Run(async () => await ConfigureItemRepositories().ConfigureAwait(false));
  246. var userdataTask = Task.Run(async () => await ConfigureUserDataRepositories().ConfigureAwait(false));
  247. var userTask = Task.Run(async () => await ConfigureUserRepositories().ConfigureAwait(false));
  248. await Task.WhenAll(itemsTask, userTask, displayPreferencesTask, userdataTask).ConfigureAwait(false);
  249. SetKernelProperties();
  250. }
  251. /// <summary>
  252. /// Sets the kernel properties.
  253. /// </summary>
  254. private void SetKernelProperties()
  255. {
  256. ServerKernel.ImageManager = new ImageManager(ServerKernel, LogManager.GetLogger("ImageManager"),
  257. ApplicationPaths);
  258. Parallel.Invoke(
  259. () => ServerKernel.FFMpegManager = new FFMpegManager(ApplicationPaths, MediaEncoder, LibraryManager, Logger),
  260. () => ServerKernel.WeatherProviders = GetExports<IWeatherProvider>(),
  261. () => ServerKernel.ImageManager.ImageEnhancers = GetExports<IImageEnhancer>().OrderBy(e => e.Priority).ToArray(),
  262. () => LocalizedStrings.StringFiles = GetExports<LocalizedStringData>(),
  263. SetStaticProperties
  264. );
  265. }
  266. /// <summary>
  267. /// Configures the repositories.
  268. /// </summary>
  269. /// <returns>Task.</returns>
  270. private async Task ConfigureDisplayPreferencesRepositories()
  271. {
  272. await DisplayPreferencesRepository.Initialize().ConfigureAwait(false);
  273. ((DisplayPreferencesManager)DisplayPreferencesManager).Repository = DisplayPreferencesRepository;
  274. }
  275. /// <summary>
  276. /// Configures the item repositories.
  277. /// </summary>
  278. /// <returns>Task.</returns>
  279. private async Task ConfigureItemRepositories()
  280. {
  281. await ItemRepository.Initialize().ConfigureAwait(false);
  282. ((LibraryManager)LibraryManager).ItemRepository = ItemRepository;
  283. }
  284. /// <summary>
  285. /// Configures the user data repositories.
  286. /// </summary>
  287. /// <returns>Task.</returns>
  288. private Task ConfigureUserDataRepositories()
  289. {
  290. return UserDataRepository.Initialize();
  291. }
  292. /// <summary>
  293. /// Configures the user repositories.
  294. /// </summary>
  295. /// <returns>Task.</returns>
  296. private async Task ConfigureUserRepositories()
  297. {
  298. await UserRepository.Initialize().ConfigureAwait(false);
  299. ((UserManager)UserManager).UserRepository = UserRepository;
  300. }
  301. /// <summary>
  302. /// Dirty hacks
  303. /// </summary>
  304. private void SetStaticProperties()
  305. {
  306. // For now there's no real way to inject these properly
  307. BaseItem.Logger = LogManager.GetLogger("BaseItem");
  308. BaseItem.ConfigurationManager = ServerConfigurationManager;
  309. BaseItem.LibraryManager = LibraryManager;
  310. BaseItem.ProviderManager = ProviderManager;
  311. User.XmlSerializer = XmlSerializer;
  312. User.UserManager = UserManager;
  313. Ratings.ConfigurationManager = ServerConfigurationManager;
  314. LocalizedStrings.ApplicationPaths = ApplicationPaths;
  315. }
  316. /// <summary>
  317. /// Finds the parts.
  318. /// </summary>
  319. protected override void FindParts()
  320. {
  321. if (IsFirstRun)
  322. {
  323. RegisterServerWithAdministratorAccess();
  324. }
  325. base.FindParts();
  326. HttpServer.Init(GetExports<IRestfulService>(false));
  327. ServerManager.AddWebSocketListeners(GetExports<IWebSocketListener>(false));
  328. StartServer(true);
  329. LibraryManager.AddParts(GetExports<IResolverIgnoreRule>(),
  330. GetExports<IVirtualFolderCreator>(),
  331. GetExports<IItemResolver>(),
  332. GetExports<IIntroProvider>(),
  333. GetExports<IBaseItemComparer>(),
  334. GetExports<ILibraryPrescanTask>(),
  335. GetExports<ILibraryPostScanTask>());
  336. ProviderManager.AddMetadataProviders(GetExports<BaseMetadataProvider>().ToArray());
  337. }
  338. /// <summary>
  339. /// Starts the server.
  340. /// </summary>
  341. /// <param name="retryOnFailure">if set to <c>true</c> [retry on failure].</param>
  342. private void StartServer(bool retryOnFailure)
  343. {
  344. try
  345. {
  346. ServerManager.Start();
  347. }
  348. catch
  349. {
  350. if (retryOnFailure)
  351. {
  352. RegisterServerWithAdministratorAccess();
  353. StartServer(false);
  354. }
  355. else
  356. {
  357. throw;
  358. }
  359. }
  360. }
  361. /// <summary>
  362. /// Called when [configuration updated].
  363. /// </summary>
  364. /// <param name="sender">The sender.</param>
  365. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  366. protected override void OnConfigurationUpdated(object sender, EventArgs e)
  367. {
  368. base.OnConfigurationUpdated(sender, e);
  369. if (!string.Equals(HttpServer.UrlPrefix, HttpServerUrlPrefix, StringComparison.OrdinalIgnoreCase))
  370. {
  371. NotifyPendingRestart();
  372. }
  373. else if (!ServerManager.SupportsNativeWebSocket && ServerManager.WebSocketPortNumber != ServerConfigurationManager.Configuration.LegacyWebSocketPortNumber)
  374. {
  375. NotifyPendingRestart();
  376. }
  377. }
  378. /// <summary>
  379. /// Restarts this instance.
  380. /// </summary>
  381. public override void Restart()
  382. {
  383. App.Instance.Restart();
  384. }
  385. /// <summary>
  386. /// Gets or sets a value indicating whether this instance can self update.
  387. /// </summary>
  388. /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value>
  389. public override bool CanSelfUpdate
  390. {
  391. get { return ConfigurationManager.CommonConfiguration.EnableAutoUpdate; }
  392. }
  393. /// <summary>
  394. /// Checks for update.
  395. /// </summary>
  396. /// <param name="cancellationToken">The cancellation token.</param>
  397. /// <param name="progress">The progress.</param>
  398. /// <returns>Task{CheckForUpdateResult}.</returns>
  399. public async override Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress<double> progress)
  400. {
  401. var availablePackages = await PackageManager.GetAvailablePackages(CancellationToken.None).ConfigureAwait(false);
  402. var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, Constants.MbServerPkgName, ConfigurationManager.CommonConfiguration.SystemUpdateLevel);
  403. return version != null ? new CheckForUpdateResult { AvailableVersion = version.version, IsUpdateAvailable = version.version > ApplicationVersion, Package = version } :
  404. new CheckForUpdateResult { AvailableVersion = ApplicationVersion, IsUpdateAvailable = false };
  405. }
  406. /// <summary>
  407. /// Gets the composable part assemblies.
  408. /// </summary>
  409. /// <returns>IEnumerable{Assembly}.</returns>
  410. protected override IEnumerable<Assembly> GetComposablePartAssemblies()
  411. {
  412. // Gets all plugin assemblies by first reading all bytes of the .dll and calling Assembly.Load against that
  413. // This will prevent the .dll file from getting locked, and allow us to replace it when needed
  414. foreach (var pluginAssembly in Directory
  415. .EnumerateFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.TopDirectoryOnly)
  416. .Select(LoadAssembly).Where(a => a != null))
  417. {
  418. yield return pluginAssembly;
  419. }
  420. // Include composable parts in the Api assembly
  421. yield return typeof(ApiEntryPoint).Assembly;
  422. // Include composable parts in the Dashboard assembly
  423. yield return typeof(DashboardInfo).Assembly;
  424. // Include composable parts in the Model assembly
  425. yield return typeof(SystemInfo).Assembly;
  426. // Include composable parts in the Common assembly
  427. yield return typeof(IApplicationHost).Assembly;
  428. // Include composable parts in the Controller assembly
  429. yield return typeof(Kernel).Assembly;
  430. // Common implementations
  431. yield return typeof(TaskManager).Assembly;
  432. // Server implementations
  433. yield return typeof(ServerApplicationPaths).Assembly;
  434. // Include composable parts in the running assembly
  435. yield return GetType().Assembly;
  436. }
  437. private readonly string _systemId = Environment.MachineName.GetMD5().ToString();
  438. /// <summary>
  439. /// Gets the system status.
  440. /// </summary>
  441. /// <returns>SystemInfo.</returns>
  442. public virtual SystemInfo GetSystemInfo()
  443. {
  444. return new SystemInfo
  445. {
  446. HasPendingRestart = HasPendingRestart,
  447. Version = ApplicationVersion.ToString(),
  448. IsNetworkDeployed = CanSelfUpdate,
  449. WebSocketPortNumber = ServerManager.WebSocketPortNumber,
  450. SupportsNativeWebSocket = ServerManager.SupportsNativeWebSocket,
  451. FailedPluginAssemblies = FailedAssemblies.ToArray(),
  452. InProgressInstallations = InstallationManager.CurrentInstallations.Select(i => i.Item1).ToArray(),
  453. CompletedInstallations = InstallationManager.CompletedInstallations.ToArray(),
  454. Id = _systemId,
  455. ProgramDataPath = ApplicationPaths.ProgramDataPath
  456. };
  457. }
  458. /// <summary>
  459. /// Shuts down.
  460. /// </summary>
  461. public override void Shutdown()
  462. {
  463. App.Instance.Dispatcher.Invoke(App.Instance.Shutdown);
  464. }
  465. /// <summary>
  466. /// Registers the server with administrator access.
  467. /// </summary>
  468. private void RegisterServerWithAdministratorAccess()
  469. {
  470. Logger.Info("Requesting administrative access to authorize http server");
  471. // Create a temp file path to extract the bat file to
  472. var tmpFile = Path.Combine(ConfigurationManager.CommonApplicationPaths.TempDirectory, Guid.NewGuid() + ".bat");
  473. // Extract the bat file
  474. using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MediaBrowser.ServerApplication.RegisterServer.bat"))
  475. {
  476. using (var fileStream = File.Create(tmpFile))
  477. {
  478. stream.CopyTo(fileStream);
  479. }
  480. }
  481. var startInfo = new ProcessStartInfo
  482. {
  483. FileName = tmpFile,
  484. Arguments = string.Format("{0} {1} {2} {3}", ServerConfigurationManager.Configuration.HttpServerPortNumber,
  485. HttpServerUrlPrefix,
  486. UdpServerPort,
  487. ServerConfigurationManager.Configuration.LegacyWebSocketPortNumber),
  488. CreateNoWindow = true,
  489. WindowStyle = ProcessWindowStyle.Hidden,
  490. Verb = "runas",
  491. ErrorDialog = false
  492. };
  493. using (var process = Process.Start(startInfo))
  494. {
  495. process.WaitForExit();
  496. }
  497. }
  498. }
  499. }