/// <summary> /// Creates instances of available extensions that extend the specified extension point and match the specified filter. /// </summary> /// <param name="extensionPoint">The extension point for which to create extensions.</param> /// <param name="filter">An <see cref="ExtensionFilter"/> used to limit the result set to extensions with particular characteristics.</param> /// <param name="justOne">Indicates whether or not to return only the first matching extension that is found.</param> /// <returns>A set of extension instances.</returns> /// <remarks> /// Available extensions are those which are both enabled and licensed. /// If <paramref name="justOne"/> is true, the first matching extension that is successfully instantiated is returned, /// an no other extensions are instantiated. /// </remarks> public object[] CreateExtensions(ExtensionPoint extensionPoint, ExtensionFilter filter, bool justOne) { // get subset of applicable extensions var extensions = ListExtensionsHelper(extensionPoint, filter); // attempt to instantiate the extension classes var createdObjects = new List <object>(); foreach (var extension in extensions) { if (justOne && createdObjects.Count > 0) { break; } try { // instantiate var o = Activator.CreateInstance(extension.ExtensionClass.Resolve()); createdObjects.Add(o); } catch (Exception e) { // instantiation failed // this should not be considered an exceptional circumstance // instantiation may fail by design in some cases (e.g extension is designed only to run on a particular platform) Platform.Log(LogLevel.Debug, e); } } return(createdObjects.ToArray()); }
private List <ExtensionInfo> ListExtensionsHelper(ExtensionPoint extensionPoint, ExtensionFilter filter) { // ensure extension map has been constructed BuildExtensionMapOnce(); List <ExtensionInfo> extensions; if (_extensionMap.TryGetValue(extensionPoint.GetType(), out extensions)) { return(CollectionUtils.Select(extensions, extension => extension.Enabled && extension.Authorized && (filter == null || filter.Test(extension)))); } return(new List <ExtensionInfo>()); }
/// <summary> /// Lists all available extensions for the specified <paramref name="extensionPoint"/> that match the specified <paramref name="filter"/>. /// </summary> /// <param name="extensionPoint">The extension point for which to retrieve a list of extensions.</param> /// <param name="filter">An <see cref="ExtensionFilter"/> used to limit the result set to extensions with particular characteristics.</param> /// <returns>A list of <see cref="ExtensionInfo"/> objects describing available extensions.</returns> /// <remarks> /// Available extensions are those which are both enabled and licensed. /// </remarks> public ExtensionInfo[] ListExtensions(ExtensionPoint extensionPoint, ExtensionFilter filter) { return(ListExtensionsHelper(extensionPoint, filter).ToArray()); }