ApplicationHost.cs 47 KB

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