IApplicationHost.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using MediaBrowser.Common.Events;
  2. using MediaBrowser.Common.Plugins;
  3. using MediaBrowser.Model.Updates;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. namespace MediaBrowser.Common
  9. {
  10. /// <summary>
  11. /// An interface to be implemented by the applications hosting a kernel
  12. /// </summary>
  13. public interface IApplicationHost
  14. {
  15. /// <summary>
  16. /// Gets the name.
  17. /// </summary>
  18. /// <value>The name.</value>
  19. string Name { get; }
  20. /// <summary>
  21. /// Occurs when [application updated].
  22. /// </summary>
  23. event EventHandler<GenericEventArgs<Version>> ApplicationUpdated;
  24. /// <summary>
  25. /// Gets a value indicating whether this instance is running as service.
  26. /// </summary>
  27. /// <value><c>true</c> if this instance is running as service; otherwise, <c>false</c>.</value>
  28. bool IsRunningAsService { get; }
  29. /// <summary>
  30. /// Gets or sets a value indicating whether this instance has pending kernel reload.
  31. /// </summary>
  32. /// <value><c>true</c> if this instance has pending kernel reload; otherwise, <c>false</c>.</value>
  33. bool HasPendingRestart { get; }
  34. /// <summary>
  35. /// Gets a value indicating whether this instance can self restart.
  36. /// </summary>
  37. /// <value><c>true</c> if this instance can self restart; otherwise, <c>false</c>.</value>
  38. bool CanSelfRestart { get; }
  39. /// <summary>
  40. /// Occurs when [has pending restart changed].
  41. /// </summary>
  42. event EventHandler HasPendingRestartChanged;
  43. /// <summary>
  44. /// Notifies the pending restart.
  45. /// </summary>
  46. void NotifyPendingRestart();
  47. /// <summary>
  48. /// Restarts this instance.
  49. /// </summary>
  50. Task Restart();
  51. /// <summary>
  52. /// Gets the application version.
  53. /// </summary>
  54. /// <value>The application version.</value>
  55. Version ApplicationVersion { get; }
  56. /// <summary>
  57. /// Gets or sets a value indicating whether this instance can self update.
  58. /// </summary>
  59. /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value>
  60. bool CanSelfUpdate { get; }
  61. /// <summary>
  62. /// Gets a value indicating whether this instance is first run.
  63. /// </summary>
  64. /// <value><c>true</c> if this instance is first run; otherwise, <c>false</c>.</value>
  65. bool IsFirstRun { get; }
  66. /// <summary>
  67. /// Gets the failed assemblies.
  68. /// </summary>
  69. /// <value>The failed assemblies.</value>
  70. List<string> FailedAssemblies { get; }
  71. /// <summary>
  72. /// Gets all concrete types.
  73. /// </summary>
  74. /// <value>All concrete types.</value>
  75. Type[] AllConcreteTypes { get; }
  76. /// <summary>
  77. /// Gets the exports.
  78. /// </summary>
  79. /// <typeparam name="T"></typeparam>
  80. /// <param name="manageLiftime">if set to <c>true</c> [manage liftime].</param>
  81. /// <returns>IEnumerable{``0}.</returns>
  82. IEnumerable<T> GetExports<T>(bool manageLiftime = true);
  83. /// <summary>
  84. /// Checks for update.
  85. /// </summary>
  86. /// <returns>Task{CheckForUpdateResult}.</returns>
  87. Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress<double> progress);
  88. /// <summary>
  89. /// Updates the application.
  90. /// </summary>
  91. /// <returns>Task.</returns>
  92. Task UpdateApplication(PackageVersionInfo package, CancellationToken cancellationToken, IProgress<double> progress);
  93. /// <summary>
  94. /// Resolves this instance.
  95. /// </summary>
  96. /// <typeparam name="T"></typeparam>
  97. /// <returns>``0.</returns>
  98. T Resolve<T>();
  99. /// <summary>
  100. /// Resolves this instance.
  101. /// </summary>
  102. /// <typeparam name="T"></typeparam>
  103. /// <returns>``0.</returns>
  104. T TryResolve<T>();
  105. /// <summary>
  106. /// Shuts down.
  107. /// </summary>
  108. Task Shutdown();
  109. /// <summary>
  110. /// Gets the plugins.
  111. /// </summary>
  112. /// <value>The plugins.</value>
  113. IEnumerable<IPlugin> Plugins { get; }
  114. /// <summary>
  115. /// Removes the plugin.
  116. /// </summary>
  117. /// <param name="plugin">The plugin.</param>
  118. void RemovePlugin(IPlugin plugin);
  119. /// <summary>
  120. /// Inits this instance.
  121. /// </summary>
  122. /// <param name="progress">The progress.</param>
  123. /// <returns>Task.</returns>
  124. Task Init(IProgress<double> progress);
  125. /// <summary>
  126. /// Creates the instance.
  127. /// </summary>
  128. /// <param name="type">The type.</param>
  129. /// <returns>System.Object.</returns>
  130. object CreateInstance(Type type);
  131. }
  132. public interface IDependencyContainer
  133. {
  134. void RegisterSingleInstance<T>(T obj, bool manageLifetime = true)
  135. where T : class;
  136. void RegisterSingleInstance<T>(Func<T> func)
  137. where T : class;
  138. void Register(Type typeInterface, Type typeImplementation);
  139. }
  140. }