2
0

IApplicationHost.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using System.Threading.Tasks;
  5. namespace MediaBrowser.Common
  6. {
  7. /// <summary>
  8. /// Delegate used with GetExports{T}.
  9. /// </summary>
  10. /// <param name="type">Type to create.</param>
  11. /// <returns>New instance of type <param>type</param>.</returns>
  12. public delegate object? CreationDelegateFactory(Type type);
  13. /// <summary>
  14. /// An interface to be implemented by the applications hosting a kernel.
  15. /// </summary>
  16. public interface IApplicationHost
  17. {
  18. /// <summary>
  19. /// Occurs when [has pending restart changed].
  20. /// </summary>
  21. event EventHandler? HasPendingRestartChanged;
  22. /// <summary>
  23. /// Gets the name.
  24. /// </summary>
  25. /// <value>The name.</value>
  26. string Name { get; }
  27. /// <summary>
  28. /// Gets the device identifier.
  29. /// </summary>
  30. /// <value>The device identifier.</value>
  31. string SystemId { get; }
  32. /// <summary>
  33. /// Gets a value indicating whether this instance has pending kernel reload.
  34. /// </summary>
  35. /// <value><c>true</c> if this instance has pending kernel reload; otherwise, <c>false</c>.</value>
  36. bool HasPendingRestart { get; }
  37. /// <summary>
  38. /// Gets a value indicating whether this instance is currently shutting down.
  39. /// </summary>
  40. /// <value><c>true</c> if this instance is shutting down; otherwise, <c>false</c>.</value>
  41. bool IsShuttingDown { get; }
  42. /// <summary>
  43. /// Gets a value indicating whether this instance can self restart.
  44. /// </summary>
  45. /// <value><c>true</c> if this instance can self restart; otherwise, <c>false</c>.</value>
  46. bool CanSelfRestart { get; }
  47. /// <summary>
  48. /// Gets the application version.
  49. /// </summary>
  50. /// <value>The application version.</value>
  51. Version ApplicationVersion { get; }
  52. /// <summary>
  53. /// Gets or sets the service provider.
  54. /// </summary>
  55. IServiceProvider? ServiceProvider { get; set; }
  56. /// <summary>
  57. /// Gets the application version.
  58. /// </summary>
  59. /// <value>The application version.</value>
  60. string ApplicationVersionString { get; }
  61. /// <summary>
  62. /// Gets the application user agent.
  63. /// </summary>
  64. /// <value>The application user agent.</value>
  65. string ApplicationUserAgent { get; }
  66. /// <summary>
  67. /// Gets the email address for use within a comment section of a user agent field.
  68. /// Presently used to provide contact information to MusicBrainz service.
  69. /// </summary>
  70. string ApplicationUserAgentAddress { get; }
  71. /// <summary>
  72. /// Gets all plugin assemblies which implement a custom rest api.
  73. /// </summary>
  74. /// <returns>An <see cref="IEnumerable{Assembly}"/> containing the plugin assemblies.</returns>
  75. IEnumerable<Assembly> GetApiPluginAssemblies();
  76. /// <summary>
  77. /// Notifies the pending restart.
  78. /// </summary>
  79. void NotifyPendingRestart();
  80. /// <summary>
  81. /// Restarts this instance.
  82. /// </summary>
  83. void Restart();
  84. /// <summary>
  85. /// Gets the exports.
  86. /// </summary>
  87. /// <typeparam name="T">The type.</typeparam>
  88. /// <param name="manageLifetime">If set to <c>true</c> [manage lifetime].</param>
  89. /// <returns><see cref="IReadOnlyCollection{T}" />.</returns>
  90. IReadOnlyCollection<T> GetExports<T>(bool manageLifetime = true);
  91. /// <summary>
  92. /// Gets the exports.
  93. /// </summary>
  94. /// <typeparam name="T">The type.</typeparam>
  95. /// <param name="defaultFunc">Delegate function that gets called to create the object.</param>
  96. /// <param name="manageLifetime">If set to <c>true</c> [manage lifetime].</param>
  97. /// <returns><see cref="IReadOnlyCollection{T}" />.</returns>
  98. IReadOnlyCollection<T> GetExports<T>(CreationDelegateFactory defaultFunc, bool manageLifetime = true);
  99. /// <summary>
  100. /// Gets the export types.
  101. /// </summary>
  102. /// <typeparam name="T">The type.</typeparam>
  103. /// <returns>IEnumerable{Type}.</returns>
  104. IEnumerable<Type> GetExportTypes<T>();
  105. /// <summary>
  106. /// Resolves this instance.
  107. /// </summary>
  108. /// <typeparam name="T">The <c>Type</c>.</typeparam>
  109. /// <returns>``0.</returns>
  110. T Resolve<T>();
  111. /// <summary>
  112. /// Shuts down.
  113. /// </summary>
  114. /// <returns>A task.</returns>
  115. Task Shutdown();
  116. /// <summary>
  117. /// Initializes this instance.
  118. /// </summary>
  119. void Init();
  120. /// <summary>
  121. /// Creates the instance.
  122. /// </summary>
  123. /// <param name="type">The type.</param>
  124. /// <returns>System.Object.</returns>
  125. object CreateInstance(Type type);
  126. }
  127. }