BaseKernel.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. using MediaBrowser.Common.Events;
  2. using MediaBrowser.Common.IO;
  3. using MediaBrowser.Common.Localization;
  4. using MediaBrowser.Common.Mef;
  5. using MediaBrowser.Common.Net;
  6. using MediaBrowser.Common.Plugins;
  7. using MediaBrowser.Common.ScheduledTasks;
  8. using MediaBrowser.Common.Serialization;
  9. using MediaBrowser.Model.Configuration;
  10. using MediaBrowser.Model.Logging;
  11. using MediaBrowser.Model.System;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.ComponentModel.Composition;
  15. using System.ComponentModel.Composition.Hosting;
  16. using System.Diagnostics;
  17. using System.IO;
  18. using System.Linq;
  19. using System.Reflection;
  20. using System.Threading;
  21. using System.Threading.Tasks;
  22. namespace MediaBrowser.Common.Kernel
  23. {
  24. /// <summary>
  25. /// Represents a shared base kernel for both the Ui and server apps
  26. /// </summary>
  27. /// <typeparam name="TConfigurationType">The type of the T configuration type.</typeparam>
  28. /// <typeparam name="TApplicationPathsType">The type of the T application paths type.</typeparam>
  29. public abstract class BaseKernel<TConfigurationType, TApplicationPathsType> : IDisposable, IKernel
  30. where TConfigurationType : BaseApplicationConfiguration, new()
  31. where TApplicationPathsType : BaseApplicationPaths, new()
  32. {
  33. /// <summary>
  34. /// Occurs when [has pending restart changed].
  35. /// </summary>
  36. public event EventHandler HasPendingRestartChanged;
  37. #region ConfigurationUpdated Event
  38. /// <summary>
  39. /// Occurs when [configuration updated].
  40. /// </summary>
  41. public event EventHandler<EventArgs> ConfigurationUpdated;
  42. /// <summary>
  43. /// Called when [configuration updated].
  44. /// </summary>
  45. internal void OnConfigurationUpdated()
  46. {
  47. EventHelper.QueueEventIfNotNull(ConfigurationUpdated, this, EventArgs.Empty, Logger);
  48. // Notify connected clients
  49. TcpManager.SendWebSocketMessage("ConfigurationUpdated", Configuration);
  50. }
  51. #endregion
  52. #region LoggerLoaded Event
  53. /// <summary>
  54. /// Fires whenever the logger is loaded
  55. /// </summary>
  56. public event EventHandler LoggerLoaded;
  57. /// <summary>
  58. /// Called when [logger loaded].
  59. /// </summary>
  60. private void OnLoggerLoaded()
  61. {
  62. EventHelper.QueueEventIfNotNull(LoggerLoaded, this, EventArgs.Empty, Logger);
  63. }
  64. #endregion
  65. #region ReloadBeginning Event
  66. /// <summary>
  67. /// Fires whenever the kernel begins reloading
  68. /// </summary>
  69. public event EventHandler<EventArgs> ReloadBeginning;
  70. /// <summary>
  71. /// Called when [reload beginning].
  72. /// </summary>
  73. private void OnReloadBeginning()
  74. {
  75. EventHelper.QueueEventIfNotNull(ReloadBeginning, this, EventArgs.Empty, Logger);
  76. }
  77. #endregion
  78. #region ReloadCompleted Event
  79. /// <summary>
  80. /// Fires whenever the kernel completes reloading
  81. /// </summary>
  82. public event EventHandler<EventArgs> ReloadCompleted;
  83. /// <summary>
  84. /// Called when [reload completed].
  85. /// </summary>
  86. private void OnReloadCompleted()
  87. {
  88. EventHelper.QueueEventIfNotNull(ReloadCompleted, this, EventArgs.Empty, Logger);
  89. }
  90. #endregion
  91. #region ApplicationUpdated Event
  92. /// <summary>
  93. /// Occurs when [application updated].
  94. /// </summary>
  95. public event EventHandler<GenericEventArgs<Version>> ApplicationUpdated;
  96. /// <summary>
  97. /// Called when [application updated].
  98. /// </summary>
  99. /// <param name="newVersion">The new version.</param>
  100. public void OnApplicationUpdated(Version newVersion)
  101. {
  102. EventHelper.QueueEventIfNotNull(ApplicationUpdated, this, new GenericEventArgs<Version> { Argument = newVersion }, Logger);
  103. NotifyPendingRestart();
  104. }
  105. #endregion
  106. /// <summary>
  107. /// The _configuration loaded
  108. /// </summary>
  109. private bool _configurationLoaded;
  110. /// <summary>
  111. /// The _configuration sync lock
  112. /// </summary>
  113. private object _configurationSyncLock = new object();
  114. /// <summary>
  115. /// The _configuration
  116. /// </summary>
  117. private TConfigurationType _configuration;
  118. /// <summary>
  119. /// Gets the system configuration
  120. /// </summary>
  121. /// <value>The configuration.</value>
  122. public TConfigurationType Configuration
  123. {
  124. get
  125. {
  126. // Lazy load
  127. LazyInitializer.EnsureInitialized(ref _configuration, ref _configurationLoaded, ref _configurationSyncLock, () => XmlSerializer.GetXmlConfiguration<TConfigurationType>(ApplicationPaths.SystemConfigurationFilePath, Logger));
  128. return _configuration;
  129. }
  130. protected set
  131. {
  132. _configuration = value;
  133. if (value == null)
  134. {
  135. _configurationLoaded = false;
  136. }
  137. }
  138. }
  139. /// <summary>
  140. /// Gets a value indicating whether this instance is first run.
  141. /// </summary>
  142. /// <value><c>true</c> if this instance is first run; otherwise, <c>false</c>.</value>
  143. public bool IsFirstRun { get; private set; }
  144. /// <summary>
  145. /// Gets or sets a value indicating whether this instance has changes that require the entire application to restart.
  146. /// </summary>
  147. /// <value><c>true</c> if this instance has pending application restart; otherwise, <c>false</c>.</value>
  148. public bool HasPendingRestart { get; private set; }
  149. /// <summary>
  150. /// Gets the application paths.
  151. /// </summary>
  152. /// <value>The application paths.</value>
  153. public TApplicationPathsType ApplicationPaths { get; private set; }
  154. /// <summary>
  155. /// The _failed assembly loads
  156. /// </summary>
  157. private readonly List<string> _failedPluginAssemblies = new List<string>();
  158. /// <summary>
  159. /// Gets the plugin assemblies that failed to load.
  160. /// </summary>
  161. /// <value>The failed assembly loads.</value>
  162. public IEnumerable<string> FailedPluginAssemblies
  163. {
  164. get { return _failedPluginAssemblies; }
  165. }
  166. /// <summary>
  167. /// Gets the list of currently loaded plugins
  168. /// </summary>
  169. /// <value>The plugins.</value>
  170. [ImportMany(typeof(IPlugin))]
  171. public IEnumerable<IPlugin> Plugins { get; protected set; }
  172. /// <summary>
  173. /// Gets the list of Scheduled Tasks
  174. /// </summary>
  175. /// <value>The scheduled tasks.</value>
  176. [ImportMany(typeof(IScheduledTask))]
  177. public IEnumerable<IScheduledTask> ScheduledTasks { get; private set; }
  178. /// <summary>
  179. /// Gets the web socket listeners.
  180. /// </summary>
  181. /// <value>The web socket listeners.</value>
  182. [ImportMany(typeof(IWebSocketListener))]
  183. public IEnumerable<IWebSocketListener> WebSocketListeners { get; private set; }
  184. /// <summary>
  185. /// Gets the list of Localized string files
  186. /// </summary>
  187. /// <value>The string files.</value>
  188. [ImportMany(typeof(LocalizedStringData))]
  189. public IEnumerable<LocalizedStringData> StringFiles { get; private set; }
  190. /// <summary>
  191. /// Gets the MEF CompositionContainer
  192. /// </summary>
  193. /// <value>The composition container.</value>
  194. private CompositionContainer CompositionContainer { get; set; }
  195. /// <summary>
  196. /// The _HTTP manager
  197. /// </summary>
  198. /// <value>The HTTP manager.</value>
  199. public HttpManager HttpManager { get; private set; }
  200. /// <summary>
  201. /// Gets or sets the TCP manager.
  202. /// </summary>
  203. /// <value>The TCP manager.</value>
  204. public TcpManager TcpManager { get; private set; }
  205. /// <summary>
  206. /// Gets the task manager.
  207. /// </summary>
  208. /// <value>The task manager.</value>
  209. public TaskManager TaskManager { get; private set; }
  210. /// <summary>
  211. /// Gets the iso manager.
  212. /// </summary>
  213. /// <value>The iso manager.</value>
  214. public IIsoManager IsoManager { get; private set; }
  215. /// <summary>
  216. /// Gets the rest services.
  217. /// </summary>
  218. /// <value>The rest services.</value>
  219. [ImportMany(typeof(IRestfulService))]
  220. public IEnumerable<IRestfulService> RestServices { get; private set; }
  221. /// <summary>
  222. /// The _protobuf serializer initialized
  223. /// </summary>
  224. private bool _protobufSerializerInitialized;
  225. /// <summary>
  226. /// The _protobuf serializer sync lock
  227. /// </summary>
  228. private object _protobufSerializerSyncLock = new object();
  229. /// <summary>
  230. /// Gets a dynamically compiled generated serializer that can serialize protocontracts without reflection
  231. /// </summary>
  232. private DynamicProtobufSerializer _protobufSerializer;
  233. /// <summary>
  234. /// Gets the protobuf serializer.
  235. /// </summary>
  236. /// <value>The protobuf serializer.</value>
  237. public DynamicProtobufSerializer ProtobufSerializer
  238. {
  239. get
  240. {
  241. // Lazy load
  242. LazyInitializer.EnsureInitialized(ref _protobufSerializer, ref _protobufSerializerInitialized, ref _protobufSerializerSyncLock, () => DynamicProtobufSerializer.Create(Assemblies));
  243. return _protobufSerializer;
  244. }
  245. private set
  246. {
  247. _protobufSerializer = value;
  248. if (value == null)
  249. {
  250. _protobufSerializerInitialized = false;
  251. }
  252. }
  253. }
  254. /// <summary>
  255. /// Gets the UDP server port number.
  256. /// This can't be configurable because then the user would have to configure their client to discover the server.
  257. /// </summary>
  258. /// <value>The UDP server port number.</value>
  259. public abstract int UdpServerPortNumber { get; }
  260. /// <summary>
  261. /// Gets the name of the web application that can be used for url building.
  262. /// All api urls will be of the form {protocol}://{host}:{port}/{appname}/...
  263. /// </summary>
  264. /// <value>The name of the web application.</value>
  265. public string WebApplicationName
  266. {
  267. get { return "mediabrowser"; }
  268. }
  269. /// <summary>
  270. /// Gets the HTTP server URL prefix.
  271. /// </summary>
  272. /// <value>The HTTP server URL prefix.</value>
  273. public virtual string HttpServerUrlPrefix
  274. {
  275. get
  276. {
  277. return "http://+:" + Configuration.HttpServerPortNumber + "/" + WebApplicationName + "/";
  278. }
  279. }
  280. /// <summary>
  281. /// Gets the kernel context. Subclasses will have to override.
  282. /// </summary>
  283. /// <value>The kernel context.</value>
  284. public abstract KernelContext KernelContext { get; }
  285. /// <summary>
  286. /// Gets the log file path.
  287. /// </summary>
  288. /// <value>The log file path.</value>
  289. public string LogFilePath
  290. {
  291. get { return ApplicationHost.LogFilePath; }
  292. }
  293. /// <summary>
  294. /// Gets the logger.
  295. /// </summary>
  296. /// <value>The logger.</value>
  297. protected ILogger Logger { get; private set; }
  298. /// <summary>
  299. /// Gets or sets the application host.
  300. /// </summary>
  301. /// <value>The application host.</value>
  302. protected IApplicationHost ApplicationHost { get; private set; }
  303. /// <summary>
  304. /// Gets the assemblies.
  305. /// </summary>
  306. /// <value>The assemblies.</value>
  307. public Assembly[] Assemblies { get; private set; }
  308. /// <summary>
  309. /// Initializes a new instance of the <see cref="BaseKernel{TApplicationPathsType}" /> class.
  310. /// </summary>
  311. /// <param name="appHost">The app host.</param>
  312. /// <param name="isoManager">The iso manager.</param>
  313. /// <param name="logger">The logger.</param>
  314. /// <exception cref="System.ArgumentNullException">isoManager</exception>
  315. protected BaseKernel(IApplicationHost appHost, IIsoManager isoManager, ILogger logger)
  316. {
  317. if (appHost == null)
  318. {
  319. throw new ArgumentNullException("appHost");
  320. }
  321. if (isoManager == null)
  322. {
  323. throw new ArgumentNullException("isoManager");
  324. }
  325. if (logger == null)
  326. {
  327. throw new ArgumentNullException("logger");
  328. }
  329. ApplicationHost = appHost;
  330. IsoManager = isoManager;
  331. Logger = logger;
  332. }
  333. /// <summary>
  334. /// Initializes the Kernel
  335. /// </summary>
  336. /// <returns>Task.</returns>
  337. public async Task Init()
  338. {
  339. ApplicationPaths = new TApplicationPathsType();
  340. IsFirstRun = !File.Exists(ApplicationPaths.SystemConfigurationFilePath);
  341. // Performs initializations that can be reloaded at anytime
  342. await Reload().ConfigureAwait(false);
  343. }
  344. /// <summary>
  345. /// Performs initializations that can be reloaded at anytime
  346. /// </summary>
  347. /// <returns>Task.</returns>
  348. public async Task Reload()
  349. {
  350. OnReloadBeginning();
  351. await ReloadInternal().ConfigureAwait(false);
  352. OnReloadCompleted();
  353. Logger.Info("Kernel.Reload Complete");
  354. }
  355. /// <summary>
  356. /// Performs initializations that can be reloaded at anytime
  357. /// </summary>
  358. /// <returns>Task.</returns>
  359. protected virtual async Task ReloadInternal()
  360. {
  361. // Set these to null so that they can be lazy loaded again
  362. Configuration = null;
  363. ProtobufSerializer = null;
  364. ReloadLogger();
  365. Logger.Info("Version {0} initializing", ApplicationVersion);
  366. DisposeHttpManager();
  367. HttpManager = new HttpManager(this, Logger);
  368. await OnConfigurationLoaded().ConfigureAwait(false);
  369. DisposeTaskManager();
  370. TaskManager = new TaskManager(this, Logger);
  371. Logger.Info("Loading Plugins");
  372. await ReloadComposableParts().ConfigureAwait(false);
  373. DisposeTcpManager();
  374. TcpManager = new TcpManager(ApplicationHost, this, Logger);
  375. }
  376. /// <summary>
  377. /// Called when [configuration loaded].
  378. /// </summary>
  379. /// <returns>Task.</returns>
  380. protected virtual Task OnConfigurationLoaded()
  381. {
  382. return Task.FromResult<object>(null);
  383. }
  384. /// <summary>
  385. /// Disposes and reloads all loggers
  386. /// </summary>
  387. public void ReloadLogger()
  388. {
  389. ApplicationHost.ReloadLogger();
  390. OnLoggerLoaded();
  391. }
  392. /// <summary>
  393. /// Uses MEF to locate plugins
  394. /// Subclasses can use this to locate types within plugins
  395. /// </summary>
  396. /// <returns>Task.</returns>
  397. private async Task ReloadComposableParts()
  398. {
  399. _failedPluginAssemblies.Clear();
  400. DisposeComposableParts();
  401. Assemblies = GetComposablePartAssemblies().ToArray();
  402. CompositionContainer = MefUtils.GetSafeCompositionContainer(Assemblies.Select(i => new AssemblyCatalog(i)));
  403. ComposeExportedValues(CompositionContainer);
  404. CompositionContainer.ComposeParts(this);
  405. await OnComposablePartsLoaded().ConfigureAwait(false);
  406. CompositionContainer.Catalog.Dispose();
  407. }
  408. /// <summary>
  409. /// Composes the exported values.
  410. /// </summary>
  411. /// <param name="container">The container.</param>
  412. protected virtual void ComposeExportedValues(CompositionContainer container)
  413. {
  414. container.ComposeExportedValue("logger", Logger);
  415. container.ComposeExportedValue("appHost", ApplicationHost);
  416. }
  417. /// <summary>
  418. /// Gets the composable part assemblies.
  419. /// </summary>
  420. /// <returns>IEnumerable{Assembly}.</returns>
  421. protected virtual IEnumerable<Assembly> GetComposablePartAssemblies()
  422. {
  423. // Gets all plugin assemblies by first reading all bytes of the .dll and calling Assembly.Load against that
  424. // This will prevent the .dll file from getting locked, and allow us to replace it when needed
  425. var pluginAssemblies = Directory.EnumerateFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.TopDirectoryOnly)
  426. .Select(file =>
  427. {
  428. try
  429. {
  430. return Assembly.Load(File.ReadAllBytes((file)));
  431. }
  432. catch (Exception ex)
  433. {
  434. _failedPluginAssemblies.Add(file);
  435. Logger.ErrorException("Error loading {0}", ex, file);
  436. return null;
  437. }
  438. }).Where(a => a != null);
  439. foreach (var pluginAssembly in pluginAssemblies)
  440. {
  441. yield return pluginAssembly;
  442. }
  443. var runningDirectory = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
  444. var corePluginDirectory = Path.Combine(runningDirectory, "CorePlugins");
  445. // This will prevent the .dll file from getting locked, and allow us to replace it when needed
  446. pluginAssemblies = Directory.EnumerateFiles(corePluginDirectory, "*.dll", SearchOption.TopDirectoryOnly)
  447. .Select(file =>
  448. {
  449. try
  450. {
  451. return Assembly.Load(File.ReadAllBytes((file)));
  452. }
  453. catch (Exception ex)
  454. {
  455. _failedPluginAssemblies.Add(file);
  456. Logger.ErrorException("Error loading {0}", ex, file);
  457. return null;
  458. }
  459. }).Where(a => a != null);
  460. foreach (var pluginAssembly in pluginAssemblies)
  461. {
  462. yield return pluginAssembly;
  463. }
  464. // Include composable parts in the Model assembly
  465. yield return typeof(SystemInfo).Assembly;
  466. // Include composable parts in the Common assembly
  467. yield return Assembly.GetExecutingAssembly();
  468. // Include composable parts in the subclass assembly
  469. yield return GetType().Assembly;
  470. }
  471. /// <summary>
  472. /// Fires after MEF finishes finding composable parts within plugin assemblies
  473. /// </summary>
  474. /// <returns>Task.</returns>
  475. protected virtual Task OnComposablePartsLoaded()
  476. {
  477. return Task.Run(() =>
  478. {
  479. foreach (var task in ScheduledTasks)
  480. {
  481. task.Initialize(this, Logger);
  482. }
  483. // Start-up each plugin
  484. Parallel.ForEach(Plugins, plugin =>
  485. {
  486. Logger.Info("Initializing {0} {1}", plugin.Name, plugin.Version);
  487. try
  488. {
  489. plugin.Initialize(this, Logger);
  490. Logger.Info("{0} {1} initialized.", plugin.Name, plugin.Version);
  491. }
  492. catch (Exception ex)
  493. {
  494. Logger.ErrorException("Error initializing {0}", ex, plugin.Name);
  495. }
  496. });
  497. });
  498. }
  499. /// <summary>
  500. /// Notifies that the kernel that a change has been made that requires a restart
  501. /// </summary>
  502. public void NotifyPendingRestart()
  503. {
  504. HasPendingRestart = true;
  505. TcpManager.SendWebSocketMessage("HasPendingRestartChanged", GetSystemInfo());
  506. EventHelper.QueueEventIfNotNull(HasPendingRestartChanged, this, EventArgs.Empty, Logger);
  507. }
  508. /// <summary>
  509. /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  510. /// </summary>
  511. public void Dispose()
  512. {
  513. Dispose(true);
  514. GC.SuppressFinalize(this);
  515. }
  516. /// <summary>
  517. /// Releases unmanaged and - optionally - managed resources.
  518. /// </summary>
  519. /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  520. protected virtual void Dispose(bool dispose)
  521. {
  522. if (dispose)
  523. {
  524. DisposeTcpManager();
  525. DisposeTaskManager();
  526. DisposeIsoManager();
  527. DisposeHttpManager();
  528. DisposeComposableParts();
  529. }
  530. }
  531. /// <summary>
  532. /// Disposes the iso manager.
  533. /// </summary>
  534. private void DisposeIsoManager()
  535. {
  536. if (IsoManager != null)
  537. {
  538. IsoManager.Dispose();
  539. IsoManager = null;
  540. }
  541. }
  542. /// <summary>
  543. /// Disposes the TCP manager.
  544. /// </summary>
  545. private void DisposeTcpManager()
  546. {
  547. if (TcpManager != null)
  548. {
  549. TcpManager.Dispose();
  550. TcpManager = null;
  551. }
  552. }
  553. /// <summary>
  554. /// Disposes the task manager.
  555. /// </summary>
  556. private void DisposeTaskManager()
  557. {
  558. if (TaskManager != null)
  559. {
  560. TaskManager.Dispose();
  561. TaskManager = null;
  562. }
  563. }
  564. /// <summary>
  565. /// Disposes the HTTP manager.
  566. /// </summary>
  567. private void DisposeHttpManager()
  568. {
  569. if (HttpManager != null)
  570. {
  571. HttpManager.Dispose();
  572. HttpManager = null;
  573. }
  574. }
  575. /// <summary>
  576. /// Disposes all objects gathered through MEF composable parts
  577. /// </summary>
  578. protected virtual void DisposeComposableParts()
  579. {
  580. if (CompositionContainer != null)
  581. {
  582. CompositionContainer.Dispose();
  583. }
  584. }
  585. /// <summary>
  586. /// Gets the current application version
  587. /// </summary>
  588. /// <value>The application version.</value>
  589. public Version ApplicationVersion
  590. {
  591. get
  592. {
  593. return GetType().Assembly.GetName().Version;
  594. }
  595. }
  596. /// <summary>
  597. /// Performs the pending restart.
  598. /// </summary>
  599. /// <returns>Task.</returns>
  600. public void PerformPendingRestart()
  601. {
  602. if (HasPendingRestart)
  603. {
  604. RestartApplication();
  605. }
  606. else
  607. {
  608. Logger.Info("PerformPendingRestart - not needed");
  609. }
  610. }
  611. /// <summary>
  612. /// Restarts the application.
  613. /// </summary>
  614. protected void RestartApplication()
  615. {
  616. Logger.Info("Restarting the application");
  617. ApplicationHost.Restart();
  618. }
  619. /// <summary>
  620. /// Gets the system status.
  621. /// </summary>
  622. /// <returns>SystemInfo.</returns>
  623. public virtual SystemInfo GetSystemInfo()
  624. {
  625. return new SystemInfo
  626. {
  627. HasPendingRestart = HasPendingRestart,
  628. Version = ApplicationVersion.ToString(),
  629. IsNetworkDeployed = ApplicationHost.CanSelfUpdate,
  630. WebSocketPortNumber = TcpManager.WebSocketPortNumber,
  631. SupportsNativeWebSocket = TcpManager.SupportsNativeWebSocket,
  632. FailedPluginAssemblies = FailedPluginAssemblies.ToArray()
  633. };
  634. }
  635. /// <summary>
  636. /// The _save lock
  637. /// </summary>
  638. private readonly object _configurationSaveLock = new object();
  639. /// <summary>
  640. /// Saves the current configuration
  641. /// </summary>
  642. public void SaveConfiguration()
  643. {
  644. lock (_configurationSaveLock)
  645. {
  646. XmlSerializer.SerializeToFile(Configuration, ApplicationPaths.SystemConfigurationFilePath);
  647. }
  648. OnConfigurationUpdated();
  649. }
  650. /// <summary>
  651. /// Gets the application paths.
  652. /// </summary>
  653. /// <value>The application paths.</value>
  654. BaseApplicationPaths IKernel.ApplicationPaths
  655. {
  656. get { return ApplicationPaths; }
  657. }
  658. /// <summary>
  659. /// Gets the configuration.
  660. /// </summary>
  661. /// <value>The configuration.</value>
  662. BaseApplicationConfiguration IKernel.Configuration
  663. {
  664. get { return Configuration; }
  665. }
  666. }
  667. }