ApplicationHost.cs 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211
  1. using MediaBrowser.Api;
  2. using MediaBrowser.Common;
  3. using MediaBrowser.Common.Configuration;
  4. using MediaBrowser.Common.Events;
  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.Net;
  10. using MediaBrowser.Common.Progress;
  11. using MediaBrowser.Controller;
  12. using MediaBrowser.Controller.Channels;
  13. using MediaBrowser.Controller.Chapters;
  14. using MediaBrowser.Controller.Collections;
  15. using MediaBrowser.Controller.Configuration;
  16. using MediaBrowser.Controller.Dlna;
  17. using MediaBrowser.Controller.Drawing;
  18. using MediaBrowser.Controller.Dto;
  19. using MediaBrowser.Controller.Entities;
  20. using MediaBrowser.Controller.FileOrganization;
  21. using MediaBrowser.Controller.Library;
  22. using MediaBrowser.Controller.LiveTv;
  23. using MediaBrowser.Controller.Localization;
  24. using MediaBrowser.Controller.MediaEncoding;
  25. using MediaBrowser.Controller.Net;
  26. using MediaBrowser.Controller.News;
  27. using MediaBrowser.Controller.Notifications;
  28. using MediaBrowser.Controller.Persistence;
  29. using MediaBrowser.Controller.Plugins;
  30. using MediaBrowser.Controller.Providers;
  31. using MediaBrowser.Controller.Resolvers;
  32. using MediaBrowser.Controller.Security;
  33. using MediaBrowser.Controller.Session;
  34. using MediaBrowser.Controller.Sorting;
  35. using MediaBrowser.Controller.Subtitles;
  36. using MediaBrowser.Controller.Sync;
  37. using MediaBrowser.Controller.Themes;
  38. using MediaBrowser.Dlna;
  39. using MediaBrowser.Dlna.ConnectionManager;
  40. using MediaBrowser.Dlna.ContentDirectory;
  41. using MediaBrowser.Dlna.Main;
  42. using MediaBrowser.LocalMetadata.Providers;
  43. using MediaBrowser.MediaEncoding.BdInfo;
  44. using MediaBrowser.MediaEncoding.Encoder;
  45. using MediaBrowser.MediaEncoding.Subtitles;
  46. using MediaBrowser.Model.Logging;
  47. using MediaBrowser.Model.MediaInfo;
  48. using MediaBrowser.Model.System;
  49. using MediaBrowser.Model.Updates;
  50. using MediaBrowser.Providers.Chapters;
  51. using MediaBrowser.Providers.Manager;
  52. using MediaBrowser.Providers.Subtitles;
  53. using MediaBrowser.Server.Implementations;
  54. using MediaBrowser.Server.Implementations.Channels;
  55. using MediaBrowser.Server.Implementations.Collections;
  56. using MediaBrowser.Server.Implementations.Configuration;
  57. using MediaBrowser.Server.Implementations.Drawing;
  58. using MediaBrowser.Server.Implementations.Dto;
  59. using MediaBrowser.Server.Implementations.EntryPoints;
  60. using MediaBrowser.Server.Implementations.FileOrganization;
  61. using MediaBrowser.Server.Implementations.HttpServer;
  62. using MediaBrowser.Server.Implementations.HttpServer.Security;
  63. using MediaBrowser.Server.Implementations.IO;
  64. using MediaBrowser.Server.Implementations.Library;
  65. using MediaBrowser.Server.Implementations.LiveTv;
  66. using MediaBrowser.Server.Implementations.Localization;
  67. using MediaBrowser.Server.Implementations.MediaEncoder;
  68. using MediaBrowser.Server.Implementations.Notifications;
  69. using MediaBrowser.Server.Implementations.Persistence;
  70. using MediaBrowser.Server.Implementations.Security;
  71. using MediaBrowser.Server.Implementations.ServerManager;
  72. using MediaBrowser.Server.Implementations.Session;
  73. using MediaBrowser.Server.Implementations.Sync;
  74. using MediaBrowser.Server.Implementations.Themes;
  75. using MediaBrowser.ServerApplication.EntryPoints;
  76. using MediaBrowser.ServerApplication.FFMpeg;
  77. using MediaBrowser.ServerApplication.IO;
  78. using MediaBrowser.ServerApplication.Native;
  79. using MediaBrowser.ServerApplication.Networking;
  80. using MediaBrowser.WebDashboard.Api;
  81. using MediaBrowser.XbmcMetadata.Providers;
  82. using System;
  83. using System.Collections.Generic;
  84. using System.Globalization;
  85. using System.IO;
  86. using System.Linq;
  87. using System.Reflection;
  88. using System.Threading;
  89. using System.Threading.Tasks;
  90. namespace MediaBrowser.ServerApplication
  91. {
  92. /// <summary>
  93. /// Class CompositionRoot
  94. /// </summary>
  95. public class ApplicationHost : BaseApplicationHost<ServerApplicationPaths>, IServerApplicationHost
  96. {
  97. /// <summary>
  98. /// Gets the server configuration manager.
  99. /// </summary>
  100. /// <value>The server configuration manager.</value>
  101. public IServerConfigurationManager ServerConfigurationManager
  102. {
  103. get { return (IServerConfigurationManager)ConfigurationManager; }
  104. }
  105. /// <summary>
  106. /// Gets the name of the web application that can be used for url building.
  107. /// All api urls will be of the form {protocol}://{host}:{port}/{appname}/...
  108. /// </summary>
  109. /// <value>The name of the web application.</value>
  110. public string WebApplicationName
  111. {
  112. get { return "mediabrowser"; }
  113. }
  114. /// <summary>
  115. /// Gets the HTTP server URL prefix.
  116. /// </summary>
  117. /// <value>The HTTP server URL prefix.</value>
  118. private IEnumerable<string> HttpServerUrlPrefixes
  119. {
  120. get
  121. {
  122. var list = new List<string>
  123. {
  124. "http://+:" + ServerConfigurationManager.Configuration.HttpServerPortNumber + "/" + WebApplicationName + "/"
  125. };
  126. return list;
  127. }
  128. }
  129. /// <summary>
  130. /// Gets the configuration manager.
  131. /// </summary>
  132. /// <returns>IConfigurationManager.</returns>
  133. protected override IConfigurationManager GetConfigurationManager()
  134. {
  135. return new ServerConfigurationManager(ApplicationPaths, LogManager, XmlSerializer);
  136. }
  137. /// <summary>
  138. /// Gets or sets the server manager.
  139. /// </summary>
  140. /// <value>The server manager.</value>
  141. private IServerManager ServerManager { get; set; }
  142. /// <summary>
  143. /// Gets or sets the user manager.
  144. /// </summary>
  145. /// <value>The user manager.</value>
  146. public IUserManager UserManager { get; set; }
  147. /// <summary>
  148. /// Gets or sets the library manager.
  149. /// </summary>
  150. /// <value>The library manager.</value>
  151. internal ILibraryManager LibraryManager { get; set; }
  152. /// <summary>
  153. /// Gets or sets the directory watchers.
  154. /// </summary>
  155. /// <value>The directory watchers.</value>
  156. private ILibraryMonitor LibraryMonitor { get; set; }
  157. /// <summary>
  158. /// Gets or sets the provider manager.
  159. /// </summary>
  160. /// <value>The provider manager.</value>
  161. private IProviderManager ProviderManager { get; set; }
  162. /// <summary>
  163. /// Gets or sets the HTTP server.
  164. /// </summary>
  165. /// <value>The HTTP server.</value>
  166. private IHttpServer HttpServer { get; set; }
  167. private IDtoService DtoService { get; set; }
  168. private IImageProcessor ImageProcessor { get; set; }
  169. private ISeriesOrderManager SeriesOrderManager { get; set; }
  170. /// <summary>
  171. /// Gets or sets the media encoder.
  172. /// </summary>
  173. /// <value>The media encoder.</value>
  174. private IMediaEncoder MediaEncoder { get; set; }
  175. private ISessionManager SessionManager { get; set; }
  176. private ILiveTvManager LiveTvManager { get; set; }
  177. internal ILocalizationManager LocalizationManager { get; set; }
  178. private IEncodingManager EncodingManager { get; set; }
  179. private IChannelManager ChannelManager { get; set; }
  180. private ISyncManager SyncManager { get; set; }
  181. /// <summary>
  182. /// Gets or sets the user data repository.
  183. /// </summary>
  184. /// <value>The user data repository.</value>
  185. private IUserDataManager UserDataManager { get; set; }
  186. private IUserRepository UserRepository { get; set; }
  187. internal IDisplayPreferencesRepository DisplayPreferencesRepository { get; set; }
  188. internal IItemRepository ItemRepository { get; set; }
  189. private INotificationsRepository NotificationsRepository { get; set; }
  190. private IFileOrganizationRepository FileOrganizationRepository { get; set; }
  191. private IProviderRepository ProviderRepository { get; set; }
  192. private INotificationManager NotificationManager { get; set; }
  193. private ISubtitleManager SubtitleManager { get; set; }
  194. private IChapterManager ChapterManager { get; set; }
  195. private IUserViewManager UserViewManager { get; set; }
  196. private IAuthenticationRepository AuthenticationRepository { get; set; }
  197. private ISyncRepository SyncRepository { get; set; }
  198. /// <summary>
  199. /// Initializes a new instance of the <see cref="ApplicationHost" /> class.
  200. /// </summary>
  201. /// <param name="applicationPaths">The application paths.</param>
  202. /// <param name="logManager">The log manager.</param>
  203. /// <param name="isRunningAsService">if set to <c>true</c> [is running as service].</param>
  204. public ApplicationHost(ServerApplicationPaths applicationPaths, ILogManager logManager, bool isRunningAsService)
  205. : base(applicationPaths, logManager)
  206. {
  207. _isRunningAsService = isRunningAsService;
  208. }
  209. private readonly bool _isRunningAsService;
  210. public override bool IsRunningAsService
  211. {
  212. get { return _isRunningAsService; }
  213. }
  214. /// <summary>
  215. /// Gets the name.
  216. /// </summary>
  217. /// <value>The name.</value>
  218. public override string Name
  219. {
  220. get
  221. {
  222. return "Media Browser Server";
  223. }
  224. }
  225. /// <summary>
  226. /// Gets a value indicating whether this instance can self restart.
  227. /// </summary>
  228. /// <value><c>true</c> if this instance can self restart; otherwise, <c>false</c>.</value>
  229. public override bool CanSelfRestart
  230. {
  231. get { return NativeApp.CanSelfRestart; }
  232. }
  233. public bool SupportsAutoRunAtStartup
  234. {
  235. get { return NativeApp.SupportsAutoRunAtStartup; }
  236. }
  237. /// <summary>
  238. /// Runs the startup tasks.
  239. /// </summary>
  240. /// <returns>Task.</returns>
  241. public override async Task RunStartupTasks()
  242. {
  243. await base.RunStartupTasks().ConfigureAwait(false);
  244. Logger.Info("Core startup complete");
  245. Parallel.ForEach(GetExports<IServerEntryPoint>(), entryPoint =>
  246. {
  247. try
  248. {
  249. entryPoint.Run();
  250. }
  251. catch (Exception ex)
  252. {
  253. Logger.ErrorException("Error in {0}", ex, entryPoint.GetType().Name);
  254. }
  255. });
  256. LogManager.RemoveConsoleOutput();
  257. }
  258. public override async Task Init(IProgress<double> progress)
  259. {
  260. PerformVersionMigration();
  261. await base.Init(progress).ConfigureAwait(false);
  262. MigrateModularConfigurations();
  263. }
  264. private void PerformVersionMigration()
  265. {
  266. DeleteDeprecatedModules();
  267. }
  268. private void MigrateModularConfigurations()
  269. {
  270. var saveConfig = false;
  271. if (ServerConfigurationManager.Configuration.DlnaOptions != null)
  272. {
  273. ServerConfigurationManager.SaveConfiguration("dlna", ServerConfigurationManager.Configuration.DlnaOptions);
  274. ServerConfigurationManager.Configuration.DlnaOptions = null;
  275. saveConfig = true;
  276. }
  277. if (ServerConfigurationManager.Configuration.ChapterOptions != null)
  278. {
  279. ServerConfigurationManager.SaveConfiguration("chapters", ServerConfigurationManager.Configuration.ChapterOptions);
  280. ServerConfigurationManager.Configuration.ChapterOptions = null;
  281. saveConfig = true;
  282. }
  283. if (ServerConfigurationManager.Configuration.ChannelOptions != null)
  284. {
  285. ServerConfigurationManager.SaveConfiguration("channels", ServerConfigurationManager.Configuration.ChannelOptions);
  286. ServerConfigurationManager.Configuration.ChannelOptions = null;
  287. saveConfig = true;
  288. }
  289. if (ServerConfigurationManager.Configuration.NotificationOptions != null)
  290. {
  291. ServerConfigurationManager.SaveConfiguration("notifications", ServerConfigurationManager.Configuration.NotificationOptions);
  292. ServerConfigurationManager.Configuration.NotificationOptions = null;
  293. saveConfig = true;
  294. }
  295. if (ServerConfigurationManager.Configuration.LiveTvOptions != null)
  296. {
  297. ServerConfigurationManager.SaveConfiguration("livetv", ServerConfigurationManager.Configuration.LiveTvOptions);
  298. ServerConfigurationManager.Configuration.LiveTvOptions = null;
  299. saveConfig = true;
  300. }
  301. if (saveConfig)
  302. {
  303. ServerConfigurationManager.SaveConfiguration();
  304. }
  305. }
  306. private void DeleteDeprecatedModules()
  307. {
  308. try
  309. {
  310. MigrateUserFolders();
  311. }
  312. catch (IOException)
  313. {
  314. }
  315. try
  316. {
  317. File.Delete(Path.Combine(ApplicationPaths.PluginsPath, "MBPhoto.dll"));
  318. }
  319. catch (IOException)
  320. {
  321. // Not there, no big deal
  322. }
  323. try
  324. {
  325. File.Delete(Path.Combine(ApplicationPaths.PluginsPath, "MediaBrowser.Plugins.XbmcMetadata.dll"));
  326. }
  327. catch (IOException)
  328. {
  329. // Not there, no big deal
  330. }
  331. Task.Run(() =>
  332. {
  333. try
  334. {
  335. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "remote-images"), true);
  336. }
  337. catch (IOException)
  338. {
  339. // Not there, no big deal
  340. }
  341. try
  342. {
  343. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "chapter-images"), true);
  344. }
  345. catch (IOException)
  346. {
  347. // Not there, no big deal
  348. }
  349. try
  350. {
  351. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "extracted-video-images"), true);
  352. }
  353. catch (IOException)
  354. {
  355. // Not there, no big deal
  356. }
  357. try
  358. {
  359. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "extracted-audio-images"), true);
  360. }
  361. catch (IOException)
  362. {
  363. // Not there, no big deal
  364. }
  365. try
  366. {
  367. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "tmdb-tv"), true);
  368. }
  369. catch (IOException)
  370. {
  371. // Not there, no big deal
  372. }
  373. try
  374. {
  375. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "tmdb-collections"), true);
  376. }
  377. catch (IOException)
  378. {
  379. // Not there, no big deal
  380. }
  381. try
  382. {
  383. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "tmdb-movies"), true);
  384. }
  385. catch (IOException)
  386. {
  387. // Not there, no big deal
  388. }
  389. try
  390. {
  391. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "fanart-movies"), true);
  392. }
  393. catch (IOException)
  394. {
  395. // Not there, no big deal
  396. }
  397. try
  398. {
  399. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "fanart-music"), true);
  400. }
  401. catch (IOException)
  402. {
  403. // Not there, no big deal
  404. }
  405. try
  406. {
  407. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "fanart-tv"), true);
  408. }
  409. catch (IOException)
  410. {
  411. // Not there, no big deal
  412. }
  413. try
  414. {
  415. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "tmdb-people"), true);
  416. }
  417. catch (IOException)
  418. {
  419. // Not there, no big deal
  420. }
  421. try
  422. {
  423. Directory.Delete(Path.Combine(ApplicationPaths.DataPath, "tvdb-v3"), true);
  424. }
  425. catch (IOException)
  426. {
  427. // Not there, no big deal
  428. }
  429. });
  430. }
  431. private void MigrateUserFolders()
  432. {
  433. var rootPath = ApplicationPaths.RootFolderPath;
  434. var folders = new DirectoryInfo(rootPath).EnumerateDirectories("*", SearchOption.TopDirectoryOnly).Where(i => !string.Equals(i.Name, "default", StringComparison.OrdinalIgnoreCase))
  435. .ToList();
  436. foreach (var folder in folders)
  437. {
  438. Directory.Delete(folder.FullName, true);
  439. }
  440. }
  441. /// <summary>
  442. /// Registers resources that classes will depend on
  443. /// </summary>
  444. /// <returns>Task.</returns>
  445. protected override async Task RegisterResources(IProgress<double> progress)
  446. {
  447. await base.RegisterResources(progress).ConfigureAwait(false);
  448. RegisterSingleInstance<IHttpResultFactory>(new HttpResultFactory(LogManager, FileSystemManager, JsonSerializer));
  449. RegisterSingleInstance<IServerApplicationHost>(this);
  450. RegisterSingleInstance<IServerApplicationPaths>(ApplicationPaths);
  451. RegisterSingleInstance(ServerConfigurationManager);
  452. LocalizationManager = new LocalizationManager(ServerConfigurationManager, FileSystemManager, JsonSerializer);
  453. RegisterSingleInstance(LocalizationManager);
  454. RegisterSingleInstance<IBlurayExaminer>(() => new BdInfoExaminer());
  455. UserDataManager = new UserDataManager(LogManager);
  456. RegisterSingleInstance(UserDataManager);
  457. UserRepository = await GetUserRepository().ConfigureAwait(false);
  458. RegisterSingleInstance(UserRepository);
  459. DisplayPreferencesRepository = new SqliteDisplayPreferencesRepository(ApplicationPaths, JsonSerializer, LogManager);
  460. RegisterSingleInstance(DisplayPreferencesRepository);
  461. ItemRepository = new SqliteItemRepository(ApplicationPaths, JsonSerializer, LogManager);
  462. RegisterSingleInstance(ItemRepository);
  463. ProviderRepository = new SqliteProviderInfoRepository(ApplicationPaths, LogManager);
  464. RegisterSingleInstance(ProviderRepository);
  465. FileOrganizationRepository = await GetFileOrganizationRepository().ConfigureAwait(false);
  466. RegisterSingleInstance(FileOrganizationRepository);
  467. AuthenticationRepository = await GetAuthenticationRepository().ConfigureAwait(false);
  468. RegisterSingleInstance(AuthenticationRepository);
  469. //SyncRepository = await GetSyncRepository().ConfigureAwait(false);
  470. //RegisterSingleInstance(SyncRepository);
  471. UserManager = new UserManager(LogManager.GetLogger("UserManager"), ServerConfigurationManager, UserRepository, XmlSerializer);
  472. RegisterSingleInstance(UserManager);
  473. LibraryManager = new LibraryManager(Logger, TaskManager, UserManager, ServerConfigurationManager, UserDataManager, () => LibraryMonitor, FileSystemManager, () => ProviderManager);
  474. RegisterSingleInstance(LibraryManager);
  475. var musicManager = new MusicManager(LibraryManager);
  476. RegisterSingleInstance<IMusicManager>(new MusicManager(LibraryManager));
  477. LibraryMonitor = new LibraryMonitor(LogManager, TaskManager, LibraryManager, ServerConfigurationManager, FileSystemManager);
  478. RegisterSingleInstance(LibraryMonitor);
  479. ProviderManager = new ProviderManager(HttpClient, ServerConfigurationManager, LibraryMonitor, LogManager, FileSystemManager);
  480. RegisterSingleInstance(ProviderManager);
  481. SeriesOrderManager = new SeriesOrderManager();
  482. RegisterSingleInstance(SeriesOrderManager);
  483. RegisterSingleInstance<ISearchEngine>(() => new SearchEngine(LogManager, LibraryManager, UserManager));
  484. HttpServer = ServerFactory.CreateServer(this, LogManager, "Media Browser", WebApplicationName, "dashboard/index.html");
  485. RegisterSingleInstance(HttpServer, false);
  486. progress.Report(10);
  487. ServerManager = new ServerManager(this, JsonSerializer, LogManager.GetLogger("ServerManager"), ServerConfigurationManager);
  488. RegisterSingleInstance(ServerManager);
  489. var innerProgress = new ActionableProgress<double>();
  490. innerProgress.RegisterAction(p => progress.Report((.75 * p) + 15));
  491. await RegisterMediaEncoder(innerProgress).ConfigureAwait(false);
  492. progress.Report(90);
  493. ImageProcessor = new ImageProcessor(LogManager.GetLogger("ImageProcessor"), ServerConfigurationManager.ApplicationPaths, FileSystemManager, JsonSerializer, MediaEncoder);
  494. RegisterSingleInstance(ImageProcessor);
  495. SyncManager = new SyncManager(LibraryManager, SyncRepository, ImageProcessor, LogManager.GetLogger("SyncManager"));
  496. RegisterSingleInstance(SyncManager);
  497. DtoService = new DtoService(Logger, LibraryManager, UserDataManager, ItemRepository, ImageProcessor, ServerConfigurationManager, FileSystemManager, ProviderManager, () => ChannelManager, SyncManager);
  498. RegisterSingleInstance(DtoService);
  499. SessionManager = new SessionManager(UserDataManager, ServerConfigurationManager, Logger, UserRepository, LibraryManager, UserManager, musicManager, DtoService, ImageProcessor, ItemRepository, JsonSerializer, this, HttpClient, AuthenticationRepository);
  500. RegisterSingleInstance(SessionManager);
  501. var newsService = new Server.Implementations.News.NewsService(ApplicationPaths, JsonSerializer);
  502. RegisterSingleInstance<INewsService>(newsService);
  503. var fileOrganizationService = new FileOrganizationService(TaskManager, FileOrganizationRepository, LogManager.GetLogger("FileOrganizationService"), LibraryMonitor, LibraryManager, ServerConfigurationManager, FileSystemManager, ProviderManager);
  504. RegisterSingleInstance<IFileOrganizationService>(fileOrganizationService);
  505. progress.Report(15);
  506. ChannelManager = new ChannelManager(UserManager, DtoService, LibraryManager, Logger, ServerConfigurationManager, FileSystemManager, UserDataManager, JsonSerializer, LocalizationManager);
  507. RegisterSingleInstance(ChannelManager);
  508. var appThemeManager = new AppThemeManager(ApplicationPaths, FileSystemManager, JsonSerializer, Logger);
  509. RegisterSingleInstance<IAppThemeManager>(appThemeManager);
  510. var dlnaManager = new DlnaManager(XmlSerializer, FileSystemManager, ApplicationPaths, LogManager.GetLogger("Dlna"), JsonSerializer);
  511. RegisterSingleInstance<IDlnaManager>(dlnaManager);
  512. var connectionManager = new ConnectionManager(dlnaManager, ServerConfigurationManager, LogManager.GetLogger("UpnpConnectionManager"), HttpClient);
  513. RegisterSingleInstance<IConnectionManager>(connectionManager);
  514. var collectionManager = new CollectionManager(LibraryManager, FileSystemManager, LibraryMonitor, LogManager.GetLogger("CollectionManager"));
  515. RegisterSingleInstance<ICollectionManager>(collectionManager);
  516. LiveTvManager = new LiveTvManager(ServerConfigurationManager, FileSystemManager, Logger, ItemRepository, ImageProcessor, UserDataManager, DtoService, UserManager, LibraryManager, TaskManager, LocalizationManager);
  517. RegisterSingleInstance(LiveTvManager);
  518. UserViewManager = new UserViewManager(LibraryManager, LocalizationManager, FileSystemManager, UserManager, ChannelManager, LiveTvManager, ApplicationPaths);
  519. RegisterSingleInstance(UserViewManager);
  520. var contentDirectory = new ContentDirectory(dlnaManager, UserDataManager, ImageProcessor, LibraryManager, ServerConfigurationManager, UserManager, LogManager.GetLogger("UpnpContentDirectory"), HttpClient, UserViewManager, ChannelManager);
  521. RegisterSingleInstance<IContentDirectory>(contentDirectory);
  522. NotificationManager = new NotificationManager(LogManager, UserManager, ServerConfigurationManager);
  523. RegisterSingleInstance(NotificationManager);
  524. RegisterSingleInstance<IEncryptionManager>(new EncryptionManager());
  525. SubtitleManager = new SubtitleManager(LogManager.GetLogger("SubtitleManager"), FileSystemManager, LibraryMonitor, LibraryManager, ItemRepository);
  526. RegisterSingleInstance(SubtitleManager);
  527. ChapterManager = new ChapterManager(LibraryManager, LogManager.GetLogger("ChapterManager"), ServerConfigurationManager, ItemRepository);
  528. RegisterSingleInstance(ChapterManager);
  529. EncodingManager = new EncodingManager(ServerConfigurationManager, FileSystemManager, Logger,
  530. MediaEncoder, ChapterManager);
  531. RegisterSingleInstance(EncodingManager);
  532. var authContext = new AuthorizationContext();
  533. RegisterSingleInstance<IAuthorizationContext>(authContext);
  534. RegisterSingleInstance<ISessionContext>(new SessionContext(UserManager, authContext, SessionManager));
  535. RegisterSingleInstance<IAuthService>(new AuthService(UserManager, SessionManager, authContext, ServerConfigurationManager));
  536. RegisterSingleInstance<ISubtitleEncoder>(new SubtitleEncoder(LibraryManager, LogManager.GetLogger("SubtitleEncoder"), ApplicationPaths, FileSystemManager, MediaEncoder));
  537. var displayPreferencesTask = Task.Run(async () => await ConfigureDisplayPreferencesRepositories().ConfigureAwait(false));
  538. var itemsTask = Task.Run(async () => await ConfigureItemRepositories().ConfigureAwait(false));
  539. var userdataTask = Task.Run(async () => await ConfigureUserDataRepositories().ConfigureAwait(false));
  540. await ConfigureNotificationsRepository().ConfigureAwait(false);
  541. progress.Report(92);
  542. await Task.WhenAll(itemsTask, displayPreferencesTask, userdataTask).ConfigureAwait(false);
  543. progress.Report(100);
  544. SetStaticProperties();
  545. await ((UserManager)UserManager).Initialize().ConfigureAwait(false);
  546. SetKernelProperties();
  547. }
  548. protected override INetworkManager CreateNetworkManager()
  549. {
  550. return new NetworkManager();
  551. }
  552. protected override IFileSystem CreateFileSystemManager()
  553. {
  554. return FileSystemFactory.CreateFileSystemManager(LogManager);
  555. }
  556. /// <summary>
  557. /// Registers the media encoder.
  558. /// </summary>
  559. /// <returns>Task.</returns>
  560. private async Task RegisterMediaEncoder(IProgress<double> progress)
  561. {
  562. var info = await new FFMpegDownloader(Logger, ApplicationPaths, HttpClient, ZipClient, FileSystemManager).GetFFMpegInfo(progress).ConfigureAwait(false);
  563. MediaEncoder = new MediaEncoder(LogManager.GetLogger("MediaEncoder"), JsonSerializer, info.EncoderPath, info.ProbePath, info.Version);
  564. RegisterSingleInstance(MediaEncoder);
  565. }
  566. /// <summary>
  567. /// Sets the kernel properties.
  568. /// </summary>
  569. private void SetKernelProperties()
  570. {
  571. LocalizedStrings.StringFiles = GetExports<LocalizedStringData>();
  572. }
  573. /// <summary>
  574. /// Gets the user repository.
  575. /// </summary>
  576. /// <returns>Task{IUserRepository}.</returns>
  577. private async Task<IUserRepository> GetUserRepository()
  578. {
  579. var repo = new SqliteUserRepository(JsonSerializer, LogManager, ApplicationPaths);
  580. await repo.Initialize().ConfigureAwait(false);
  581. return repo;
  582. }
  583. /// <summary>
  584. /// Gets the file organization repository.
  585. /// </summary>
  586. /// <returns>Task{IUserRepository}.</returns>
  587. private async Task<IFileOrganizationRepository> GetFileOrganizationRepository()
  588. {
  589. var repo = new SqliteFileOrganizationRepository(LogManager, ServerConfigurationManager.ApplicationPaths);
  590. await repo.Initialize().ConfigureAwait(false);
  591. return repo;
  592. }
  593. private async Task<IAuthenticationRepository> GetAuthenticationRepository()
  594. {
  595. var repo = new AuthenticationRepository(LogManager.GetLogger("AuthenticationRepository"), ServerConfigurationManager.ApplicationPaths);
  596. await repo.Initialize().ConfigureAwait(false);
  597. return repo;
  598. }
  599. private async Task<ISyncRepository> GetSyncRepository()
  600. {
  601. var repo = new SyncRepository(LogManager.GetLogger("SyncRepository"), ServerConfigurationManager.ApplicationPaths);
  602. await repo.Initialize().ConfigureAwait(false);
  603. return repo;
  604. }
  605. /// <summary>
  606. /// Configures the repositories.
  607. /// </summary>
  608. /// <returns>Task.</returns>
  609. private async Task ConfigureNotificationsRepository()
  610. {
  611. var repo = new SqliteNotificationsRepository(LogManager, ApplicationPaths);
  612. await repo.Initialize().ConfigureAwait(false);
  613. NotificationsRepository = repo;
  614. RegisterSingleInstance(NotificationsRepository);
  615. }
  616. /// <summary>
  617. /// Configures the repositories.
  618. /// </summary>
  619. /// <returns>Task.</returns>
  620. private async Task ConfigureDisplayPreferencesRepositories()
  621. {
  622. await DisplayPreferencesRepository.Initialize().ConfigureAwait(false);
  623. }
  624. /// <summary>
  625. /// Configures the item repositories.
  626. /// </summary>
  627. /// <returns>Task.</returns>
  628. private async Task ConfigureItemRepositories()
  629. {
  630. await ItemRepository.Initialize().ConfigureAwait(false);
  631. await ProviderRepository.Initialize().ConfigureAwait(false);
  632. ((LibraryManager)LibraryManager).ItemRepository = ItemRepository;
  633. }
  634. /// <summary>
  635. /// Configures the user data repositories.
  636. /// </summary>
  637. /// <returns>Task.</returns>
  638. private async Task ConfigureUserDataRepositories()
  639. {
  640. var repo = new SqliteUserDataRepository(ApplicationPaths, LogManager);
  641. await repo.Initialize().ConfigureAwait(false);
  642. ((UserDataManager)UserDataManager).Repository = repo;
  643. }
  644. /// <summary>
  645. /// Dirty hacks
  646. /// </summary>
  647. private void SetStaticProperties()
  648. {
  649. // For now there's no real way to inject these properly
  650. BaseItem.Logger = LogManager.GetLogger("BaseItem");
  651. BaseItem.ConfigurationManager = ServerConfigurationManager;
  652. BaseItem.LibraryManager = LibraryManager;
  653. BaseItem.ProviderManager = ProviderManager;
  654. BaseItem.LocalizationManager = LocalizationManager;
  655. BaseItem.ItemRepository = ItemRepository;
  656. User.XmlSerializer = XmlSerializer;
  657. User.UserManager = UserManager;
  658. LocalizedStrings.ApplicationPaths = ApplicationPaths;
  659. Folder.UserManager = UserManager;
  660. BaseItem.FileSystem = FileSystemManager;
  661. BaseItem.UserDataManager = UserDataManager;
  662. ChannelVideoItem.ChannelManager = ChannelManager;
  663. }
  664. /// <summary>
  665. /// Finds the parts.
  666. /// </summary>
  667. protected override void FindParts()
  668. {
  669. if (IsFirstRun)
  670. {
  671. RegisterServerWithAdministratorAccess();
  672. }
  673. base.FindParts();
  674. HttpServer.Init(GetExports<IRestfulService>(false));
  675. ServerManager.AddWebSocketListeners(GetExports<IWebSocketListener>(false));
  676. StartServer(true);
  677. LibraryManager.AddParts(GetExports<IResolverIgnoreRule>(),
  678. GetExports<IVirtualFolderCreator>(),
  679. GetExports<IItemResolver>(),
  680. GetExports<IIntroProvider>(),
  681. GetExports<IBaseItemComparer>(),
  682. GetExports<ILibraryPostScanTask>());
  683. ProviderManager.AddParts(GetExports<IImageProvider>(),
  684. GetExports<IMetadataService>(),
  685. GetExports<IItemIdentityProvider>(),
  686. GetExports<IItemIdentityConverter>(),
  687. GetExports<IMetadataProvider>(),
  688. GetExports<IMetadataSaver>(),
  689. GetExports<IImageSaver>(),
  690. GetExports<IExternalId>());
  691. SeriesOrderManager.AddParts(GetExports<ISeriesOrderProvider>());
  692. ImageProcessor.AddParts(GetExports<IImageEnhancer>());
  693. LiveTvManager.AddParts(GetExports<ILiveTvService>());
  694. SubtitleManager.AddParts(GetExports<ISubtitleProvider>());
  695. ChapterManager.AddParts(GetExports<IChapterProvider>());
  696. SessionManager.AddParts(GetExports<ISessionControllerFactory>());
  697. ChannelManager.AddParts(GetExports<IChannel>(), GetExports<IChannelFactory>());
  698. NotificationManager.AddParts(GetExports<INotificationService>(), GetExports<INotificationTypeFactory>());
  699. SyncManager.AddParts(GetExports<ISyncProvider>());
  700. }
  701. /// <summary>
  702. /// Starts the server.
  703. /// </summary>
  704. /// <param name="retryOnFailure">if set to <c>true</c> [retry on failure].</param>
  705. private void StartServer(bool retryOnFailure)
  706. {
  707. try
  708. {
  709. ServerManager.Start(HttpServerUrlPrefixes);
  710. }
  711. catch (Exception ex)
  712. {
  713. Logger.ErrorException("Error starting http server", ex);
  714. if (retryOnFailure)
  715. {
  716. RegisterServerWithAdministratorAccess();
  717. StartServer(false);
  718. }
  719. else
  720. {
  721. throw;
  722. }
  723. }
  724. }
  725. /// <summary>
  726. /// Called when [configuration updated].
  727. /// </summary>
  728. /// <param name="sender">The sender.</param>
  729. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  730. protected override void OnConfigurationUpdated(object sender, EventArgs e)
  731. {
  732. base.OnConfigurationUpdated(sender, e);
  733. if (!HttpServer.UrlPrefixes.SequenceEqual(HttpServerUrlPrefixes, StringComparer.OrdinalIgnoreCase))
  734. {
  735. NotifyPendingRestart();
  736. }
  737. }
  738. /// <summary>
  739. /// Restarts this instance.
  740. /// </summary>
  741. public override async Task Restart()
  742. {
  743. if (!CanSelfRestart)
  744. {
  745. throw new InvalidOperationException("The server is unable to self-restart. Please restart manually.");
  746. }
  747. try
  748. {
  749. await SessionManager.SendServerRestartNotification(CancellationToken.None).ConfigureAwait(false);
  750. }
  751. catch (Exception ex)
  752. {
  753. Logger.ErrorException("Error sending server restart notification", ex);
  754. }
  755. Logger.Debug("Calling NativeApp.Restart");
  756. NativeApp.Restart();
  757. }
  758. /// <summary>
  759. /// Gets or sets a value indicating whether this instance can self update.
  760. /// </summary>
  761. /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value>
  762. public override bool CanSelfUpdate
  763. {
  764. get
  765. {
  766. #if DEBUG
  767. return false;
  768. #endif
  769. #pragma warning disable 162
  770. return NativeApp.CanSelfUpdate;
  771. #pragma warning restore 162
  772. }
  773. }
  774. /// <summary>
  775. /// Gets the composable part assemblies.
  776. /// </summary>
  777. /// <returns>IEnumerable{Assembly}.</returns>
  778. protected override IEnumerable<Assembly> GetComposablePartAssemblies()
  779. {
  780. var list = GetPluginAssemblies()
  781. .ToList();
  782. // Gets all plugin assemblies by first reading all bytes of the .dll and calling Assembly.Load against that
  783. // This will prevent the .dll file from getting locked, and allow us to replace it when needed
  784. // Include composable parts in the Api assembly
  785. list.Add(typeof(ApiEntryPoint).Assembly);
  786. // Include composable parts in the Dashboard assembly
  787. list.Add(typeof(DashboardService).Assembly);
  788. // Include composable parts in the Model assembly
  789. list.Add(typeof(SystemInfo).Assembly);
  790. // Include composable parts in the Common assembly
  791. list.Add(typeof(IApplicationHost).Assembly);
  792. // Include composable parts in the Controller assembly
  793. list.Add(typeof(IServerApplicationHost).Assembly);
  794. // Include composable parts in the Providers assembly
  795. list.Add(typeof(ProviderUtils).Assembly);
  796. // Common implementations
  797. list.Add(typeof(TaskManager).Assembly);
  798. // Server implementations
  799. list.Add(typeof(ServerApplicationPaths).Assembly);
  800. // MediaEncoding
  801. list.Add(typeof(MediaEncoder).Assembly);
  802. // Dlna
  803. list.Add(typeof(DlnaEntryPoint).Assembly);
  804. // Local metadata
  805. list.Add(typeof(AlbumXmlProvider).Assembly);
  806. // Xbmc
  807. list.Add(typeof(ArtistNfoProvider).Assembly);
  808. list.AddRange(Assemblies.GetAssembliesWithParts());
  809. // Include composable parts in the running assembly
  810. list.Add(GetType().Assembly);
  811. return list;
  812. }
  813. /// <summary>
  814. /// Gets the plugin assemblies.
  815. /// </summary>
  816. /// <returns>IEnumerable{Assembly}.</returns>
  817. private IEnumerable<Assembly> GetPluginAssemblies()
  818. {
  819. try
  820. {
  821. return Directory.EnumerateFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.TopDirectoryOnly)
  822. .Select(LoadAssembly)
  823. .Where(a => a != null)
  824. .ToList();
  825. }
  826. catch (DirectoryNotFoundException)
  827. {
  828. return new List<Assembly>();
  829. }
  830. }
  831. private readonly string _systemId = Environment.MachineName.GetMD5().ToString();
  832. public string ServerId
  833. {
  834. get { return _systemId; }
  835. }
  836. /// <summary>
  837. /// Gets the system status.
  838. /// </summary>
  839. /// <returns>SystemInfo.</returns>
  840. public virtual SystemInfo GetSystemInfo()
  841. {
  842. return new SystemInfo
  843. {
  844. HasPendingRestart = HasPendingRestart,
  845. Version = ApplicationVersion.ToString(),
  846. IsNetworkDeployed = CanSelfUpdate,
  847. WebSocketPortNumber = HttpServerPort,
  848. SupportsNativeWebSocket = true,
  849. FailedPluginAssemblies = FailedAssemblies.ToList(),
  850. InProgressInstallations = InstallationManager.CurrentInstallations.Select(i => i.Item1).ToList(),
  851. CompletedInstallations = InstallationManager.CompletedInstallations.ToList(),
  852. Id = ServerId,
  853. ProgramDataPath = ApplicationPaths.ProgramDataPath,
  854. LogPath = ApplicationPaths.LogDirectoryPath,
  855. ItemsByNamePath = ApplicationPaths.ItemsByNamePath,
  856. InternalMetadataPath = ApplicationPaths.InternalMetadataPath,
  857. CachePath = ApplicationPaths.CachePath,
  858. MacAddress = GetMacAddress(),
  859. HttpServerPortNumber = HttpServerPort,
  860. OperatingSystem = Environment.OSVersion.ToString(),
  861. CanSelfRestart = CanSelfRestart,
  862. CanSelfUpdate = CanSelfUpdate,
  863. WanAddress = GetWanAddress(),
  864. HasUpdateAvailable = HasUpdateAvailable,
  865. SupportsAutoRunAtStartup = SupportsAutoRunAtStartup,
  866. TranscodingTempPath = ApplicationPaths.TranscodingTempPath,
  867. IsRunningAsService = IsRunningAsService,
  868. ServerName = string.IsNullOrWhiteSpace(ServerConfigurationManager.Configuration.ServerName) ? Environment.MachineName : ServerConfigurationManager.Configuration.ServerName
  869. };
  870. }
  871. public int HttpServerPort
  872. {
  873. get { return ServerConfigurationManager.Configuration.HttpServerPortNumber; }
  874. }
  875. private readonly CultureInfo _usCulture = new CultureInfo("en-US");
  876. private string GetWanAddress()
  877. {
  878. var ip = ServerConfigurationManager.Configuration.WanDdns;
  879. if (string.IsNullOrWhiteSpace(ip))
  880. {
  881. ip = WanAddressEntryPoint.WanAddress;
  882. }
  883. if (!string.IsNullOrEmpty(ip))
  884. {
  885. if (!ip.StartsWith("http://", StringComparison.OrdinalIgnoreCase) &&
  886. !ip.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
  887. {
  888. ip = "http://" + ip;
  889. }
  890. return ip + ":" + ServerConfigurationManager.Configuration.HttpServerPortNumber.ToString(_usCulture);
  891. }
  892. return null;
  893. }
  894. /// <summary>
  895. /// Gets the mac address.
  896. /// </summary>
  897. /// <returns>System.String.</returns>
  898. private string GetMacAddress()
  899. {
  900. try
  901. {
  902. return NetworkManager.GetMacAddress();
  903. }
  904. catch (Exception ex)
  905. {
  906. Logger.ErrorException("Error getting mac address", ex);
  907. return null;
  908. }
  909. }
  910. /// <summary>
  911. /// Shuts down.
  912. /// </summary>
  913. public override async Task Shutdown()
  914. {
  915. try
  916. {
  917. await SessionManager.SendServerShutdownNotification(CancellationToken.None).ConfigureAwait(false);
  918. }
  919. catch (Exception ex)
  920. {
  921. Logger.ErrorException("Error sending server shutdown notification", ex);
  922. }
  923. NativeApp.Shutdown();
  924. }
  925. /// <summary>
  926. /// Registers the server with administrator access.
  927. /// </summary>
  928. private void RegisterServerWithAdministratorAccess()
  929. {
  930. Logger.Info("Requesting administrative access to authorize http server");
  931. try
  932. {
  933. ServerAuthorization.AuthorizeServer(
  934. ServerConfigurationManager.Configuration.HttpServerPortNumber,
  935. HttpServerUrlPrefixes.First(),
  936. UdpServerEntryPoint.PortNumber,
  937. ConfigurationManager.CommonApplicationPaths.TempDirectory);
  938. }
  939. catch (Exception ex)
  940. {
  941. Logger.ErrorException("Error authorizing server", ex);
  942. }
  943. }
  944. public event EventHandler HasUpdateAvailableChanged;
  945. private bool _hasUpdateAvailable;
  946. public bool HasUpdateAvailable
  947. {
  948. get { return _hasUpdateAvailable; }
  949. set
  950. {
  951. var fireEvent = value && !_hasUpdateAvailable;
  952. _hasUpdateAvailable = value;
  953. if (fireEvent)
  954. {
  955. EventHelper.FireEventIfNotNull(HasUpdateAvailableChanged, this, EventArgs.Empty, Logger);
  956. }
  957. }
  958. }
  959. /// <summary>
  960. /// Checks for update.
  961. /// </summary>
  962. /// <param name="cancellationToken">The cancellation token.</param>
  963. /// <param name="progress">The progress.</param>
  964. /// <returns>Task{CheckForUpdateResult}.</returns>
  965. public override async Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress<double> progress)
  966. {
  967. var availablePackages = await InstallationManager.GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false);
  968. var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, "MBServer", null, ApplicationVersion,
  969. ConfigurationManager.CommonConfiguration.SystemUpdateLevel);
  970. var versionObject = version == null || string.IsNullOrWhiteSpace(version.versionStr) ? null : new Version(version.versionStr);
  971. var isUpdateAvailable = versionObject != null && versionObject > ApplicationVersion;
  972. HasUpdateAvailable = isUpdateAvailable;
  973. if (isUpdateAvailable)
  974. {
  975. Logger.Info("New application version is available: {0}", versionObject);
  976. }
  977. return versionObject != null ?
  978. new CheckForUpdateResult { AvailableVersion = versionObject.ToString(), IsUpdateAvailable = isUpdateAvailable, Package = version } :
  979. new CheckForUpdateResult { AvailableVersion = ApplicationVersion.ToString(), IsUpdateAvailable = false };
  980. }
  981. /// <summary>
  982. /// Updates the application.
  983. /// </summary>
  984. /// <param name="package">The package that contains the update</param>
  985. /// <param name="cancellationToken">The cancellation token.</param>
  986. /// <param name="progress">The progress.</param>
  987. /// <returns>Task.</returns>
  988. public override async Task UpdateApplication(PackageVersionInfo package, CancellationToken cancellationToken, IProgress<double> progress)
  989. {
  990. await InstallationManager.InstallPackage(package, progress, cancellationToken).ConfigureAwait(false);
  991. HasUpdateAvailable = false;
  992. OnApplicationUpdated(package);
  993. }
  994. /// <summary>
  995. /// Configures the automatic run at startup.
  996. /// </summary>
  997. /// <param name="autorun">if set to <c>true</c> [autorun].</param>
  998. protected override void ConfigureAutoRunAtStartup(bool autorun)
  999. {
  1000. if (SupportsAutoRunAtStartup)
  1001. {
  1002. Autorun.Configure(autorun);
  1003. }
  1004. }
  1005. }
  1006. }