private void SafeCopy(IPluginDescriptor plugin, IProgressMonitor progressMonitor) { using (progressMonitor.BeginTask(string.Format("Copying {0} plugin", plugin.PluginId), plugin.FilePaths.Count)) { var sourceFolder = Path.Combine(sourcePluginFolder, plugin.RecommendedInstallationPath); var targetFolder = Path.Combine(targetPluginFolder, plugin.RecommendedInstallationPath); foreach (var file in plugin.FilePaths) { var sourceFileInfo = new FileInfo(Path.Combine(sourceFolder, file)); var destination = new FileInfo(Path.Combine(targetFolder, file)); try { if (fileSystem.DirectoryExists(destination.DirectoryName) == false) fileSystem.CreateDirectory(destination.DirectoryName); fileSystem.CopyFile(sourceFileInfo.FullName, destination.FullName, true); } catch (Exception ex) { exceptionPolicy.Report(string.Format("Error copying file: {0}", file), ex); } } } }
/// <summary> /// Creates a component registration. /// </summary> /// <param name="plugin">The plugin to which the component will belong.</param> /// <param name="service">The service implemented by the component.</param> /// <param name="componentId">The component id.</param> /// <param name="componentTypeName">The component type name, or null to use the default component type specified by the service.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="plugin"/>, <paramref name="service"/>, /// <paramref name="componentId"/> is null.</exception> public ComponentRegistration(IPluginDescriptor plugin, IServiceDescriptor service, string componentId, TypeName componentTypeName) { Plugin = plugin; Service = service; ComponentId = componentId; ComponentTypeName = componentTypeName; }
private static void RegisterServices(IRegistry registry, IList <PluginData> topologicallySortedPlugins, IList <IPluginDescriptor> pluginDescriptors) { for (int i = 0; i < topologicallySortedPlugins.Count; i++) { Plugin plugin = topologicallySortedPlugins[i].Plugin; IPluginDescriptor pluginDescriptor = pluginDescriptors[i]; foreach (Service service in plugin.Services) { try { var serviceRegistration = new ServiceRegistration(pluginDescriptor, service.ServiceId, new TypeName(service.ServiceType)); if (service.DefaultComponentType != null) { serviceRegistration.DefaultComponentTypeName = new TypeName(service.DefaultComponentType); } registry.RegisterService(serviceRegistration); } catch (Exception ex) { throw new RuntimeException(string.Format("Could not register service '{0}' of plugin '{1}'.", service.ServiceId, plugin.PluginId), ex); } } } }
private void SafeCopy(IPluginDescriptor plugin, IProgressMonitor progressMonitor) { using (progressMonitor.BeginTask(string.Format("Copying {0} plugin", plugin.PluginId), plugin.FilePaths.Count)) { var sourceFolder = Path.Combine(sourcePluginFolder, plugin.RecommendedInstallationPath); var targetFolder = Path.Combine(targetPluginFolder, plugin.RecommendedInstallationPath); foreach (var file in plugin.FilePaths) { var sourceFileInfo = new FileInfo(Path.Combine(sourceFolder, file)); var destination = new FileInfo(Path.Combine(targetFolder, file)); try { if (fileSystem.DirectoryExists(destination.DirectoryName) == false) { fileSystem.CreateDirectory(destination.DirectoryName); } fileSystem.CopyFile(sourceFileInfo.FullName, destination.FullName, true); } catch (Exception ex) { exceptionPolicy.Report(string.Format("Error copying file: {0}", file), ex); } } } }
/// <inheritdoc /> public string ResolveResourcePath(Uri resourceUri) { if (resourceUri == null) { throw new ArgumentNullException("resourceUri"); } if (resourceUri.IsFile) { return(Path.GetFullPath(resourceUri.LocalPath)); } if (resourceUri.Scheme == @"plugin") { string pluginId = resourceUri.Host; string relativePath = resourceUri.PathAndQuery; IPluginDescriptor plugin = GenericCollectionUtils.Find(registry.Plugins, p => string.Compare(pluginId, p.PluginId, true) == 0); if (plugin == null) { throw new RuntimeException(String.Format("Could not resolve resource uri '{0}' because no plugin appears to be registered with the requested id.", resourceUri)); } string pluginPath = plugin.BaseDirectory.FullName; if (relativePath.Length == 0 || relativePath == @"/") { return(pluginPath); } string relativeLocalPath = relativePath.Substring(1).Replace('/', Path.DirectorySeparatorChar); return(Path.Combine(pluginPath, relativeLocalPath)); } throw new RuntimeException(String.Format("Could not resolve resource uri '{0}' because the scheme was not recognized. The uri scheme must be 'file' or 'plugin'.", resourceUri)); }
private void RegisterComponentForServices(Assembly assembly, Type type, TypeName typeName, IPluginDescriptor plugin) { var componentId = type.FullName; foreach (var interfaceType in type.GetInterfaces()) { if (false == RelevantInterface(interfaceType, assembly)) { continue; } if (IsOpenGenericType(interfaceType)) { continue; } if (ComponentAlreadyRegisteredForService(interfaceType, typeName)) { continue; } var serviceDescriptor = GetServiceDescriptor(interfaceType, plugin); RegisterComponent(interfaceType, componentId, typeName, plugin, serviceDescriptor); } }
public PluginPoweredProcessHost( [IOC(false)] IPluginDescriptor descriptor, [IOC(true)] IPluginAssemblyFactory assemblyFactory, [IOC(true)] IJobFactory jobFactory) : base(jobFactory) { if (descriptor == null) throw Ex.ArgNull(() => descriptor); if (assemblyFactory == null) throw Ex.ArgNull(() => assemblyFactory); if (jobFactory == null) throw Ex.ArgNull(() => jobFactory); try { if (!descriptor.IsUsable) { throw Ex.Arg(() => descriptor, "Descriptor must be for a usable plugin"); } if (!descriptor.Metadata.InterfaceType.Equals(typeof(IProcess))) { throw Ex.Arg(() => descriptor, "Descriptor must be for a process plugin"); } _pluginDescriptor = descriptor; _pluginAssemblyFactory = assemblyFactory; } catch (Exception ex) { throw new ApplicationException("Failed to create plugin powered process host", ex); } }
private void RegisterComponent(string componentId, TypeName typeName, IPluginDescriptor plugin, IServiceDescriptor serviceDescriptor) { var componentRegistration = new ComponentRegistration(plugin, serviceDescriptor, componentId, typeName); registry.RegisterComponent(componentRegistration); }
void plgItem_Click(object sender, EventArgs e) { ToolStripMenuItem tmi = sender as ToolStripMenuItem; IPluginDescriptor pluginProps = tmi.Tag as IPluginDescriptor; ILuaDebuggerPlugin plugin = pluginProps.CreateInstance(activeState.LuaState); plugin.ShowInState(activeState.LuaState, this); }
public IPluginInstance CreatePluginInstance(IPluginDescriptor descriptor, IPluginAssembly parentAssembly) { return _ioc.Get<IPluginInstance>(new[] { new IOCConstructorArgument("descriptor", descriptor), new IOCConstructorArgument("pluginAssembly", parentAssembly), }); }
/// <summary> /// Initializes a new instance of the <see cref="BasePlugin"/> class. /// </summary> /// <param name="pluginDescriptor">The plugin descriptor.</param> /// <exception cref="System.ArgumentNullException">pluginDescriptor</exception> public BasePlugin(IPluginDescriptor pluginDescriptor) { if (pluginDescriptor == null) { throw new ArgumentNullException("pluginDescriptor"); } descriptor = pluginDescriptor; }
public IPluginInteractionLink CreateInteractionLink(IPluginDescriptor pluginDescriptor, IPlugin pluginRawInstance, IPluginController pluginController, IPluginInstance pluginManagedInstance) { return new StandardPluginInteractionLink(pluginDescriptor, pluginRawInstance, pluginController, pluginManagedInstance); }
/// <summary> /// Initializes a new instance of the <see cref="PluginDependencyTreeNode"/> class. /// </summary> /// <param name="plugin">The plugin.</param> /// <param name="dependants">The dependants.</param> public PluginDependencyTreeNode ( [NotNull] IPluginDescriptor plugin, [CanBeNull, ItemNotNull] List <PluginDependencyTreeNode> dependants = null ) { this.Plugin = plugin; _dependants = dependants ?? new List <PluginDependencyTreeNode>(); }
public PluginNode(IPluginDescriptor plugin) : base(plugin.PluginId) { CheckState = CheckState.Checked; Plugin = plugin; foreach (var dependency in plugin.PluginDependencies) { dependencies.Add(dependency.PluginId); } }
public static InitializePluginResult FromError ( [NotNull] IPluginDescriptor plugin, [NotNull] string errorReason, [CanBeNull] Exception exception = null ) { return(new InitializePluginResult(plugin, errorReason, exception)); }
/// <summary> /// Initializes a new instance of the <see cref="PluginDependencyTreeNode"/> class. /// </summary> /// <param name="plugin">The plugin.</param> /// <param name="dependants">The dependants.</param> public PluginDependencyTreeNode ( IPluginDescriptor plugin, List <PluginDependencyTreeNode>?dependants = null ) { this.Plugin = plugin; _dependants = dependants ?? new List <PluginDependencyTreeNode>(); }
private void RegisterComponentForServices(Type type, IPluginDescriptor plugin) { var componentId = type.FullName; var interfaceTypes = GetDirectInterfaces(type); var typeName = new TypeName(type).ConvertToPartialAssemblyName(); RegisterFirstInterface(interfaceTypes, plugin, componentId, typeName); RegisterEventHandlers(interfaceTypes, plugin, componentId, typeName); }
/// <summary> /// Initializes a new instance of the <see cref="InitializePluginResult"/> class. /// </summary> /// <param name="plugin">The plugin that failed to initialize.</param> /// <param name="errorReason">The reason it failed to initialize.</param> /// <param name="exception">The exception that caused the failure, if any.</param> private InitializePluginResult ( [NotNull] IPluginDescriptor plugin, [CanBeNull] string errorReason, [CanBeNull] Exception exception = null ) : base(errorReason, exception) { this.Plugin = plugin; }
public Res<PluginExclusionReason, object> CheckCoreUsability(IPluginDescriptor descriptor, IPluginAssemblyManager assemblyManager) { var res = PluginExclusionReason.Unknown; object resultAddit = null; bool success = true; if (descriptor == null) throw new ArgumentNullException("Descriptor must be supplied"); if (assemblyManager == null) throw new ArgumentNullException("Assembly manager must be supplied"); try { var _result = CChain<Tuple<PluginExclusionReason, object>> // Check the plugin's identifier is unique .If(() => assemblyManager.GetPluginDescriptors().Count(pd => pd.Metadata.Identifier == descriptor.Metadata.Identifier) > 1, new Tuple<PluginExclusionReason, object>(PluginExclusionReason.PluginIdentifierNotUnique, // Get all the other type names that are plugins sharing the identifier assemblyManager.GetPluginDescriptors() .Where(d => d.Metadata.Identifier == descriptor.Metadata.Identifier && d.PluginTypeName != descriptor.PluginTypeName) .Select(d => d.PluginTypeName) .ToList() .AsReadOnly())) // Check the plugin is marshalable .ThenIf(() => !assemblyManager.PluginTypeIsMarshalable(descriptor), new Tuple<PluginExclusionReason, object>(PluginExclusionReason.TypeNotCrossAppDomainObject, null)) // Check it implements the IPlugin interface .ThenIf(() => !assemblyManager.PluginTypeImplementsCorePluginInterface(descriptor), new Tuple<PluginExclusionReason,object>(PluginExclusionReason.CorePluginInterfaceNotImplemented, null)) // Check it implements the specific plugin interface it claims to .ThenIf(() => !assemblyManager.PluginTypeImplementsPromisedInterface(descriptor), new Tuple<PluginExclusionReason,object>(PluginExclusionReason.NonAdherenceToInterface, null)) .Result; if (_result == null) { success = true; res = PluginExclusionReason.Unknown; resultAddit = null; } else { success = false; res = _result.Item1; resultAddit = _result.Item2; } return new Res<PluginExclusionReason, object>((success &= true), res, resultAddit); } catch (Exception ex) { throw new ApplicationException("Failed to check core usability of plugin", ex); } }
public IProcessHost CreateHostFromPlugin(IPluginDescriptor descriptor) { return (IProcessHost)_instFactory.CreateCreator() .CreateInstanceWithSeparation(_ioc.Get<IPluginPoweredProcessHost>(new[] { new IOCConstructorArgument("descriptor", descriptor), }).GetType(), new[] { new IOCConstructorArgument("descriptor", descriptor), }); }
private void RegisterBuiltInComponent(IPluginDescriptor builtInPluginDescriptor, string serviceId, Type serviceType, object component) { IServiceDescriptor serviceDescriptor = registry.RegisterService( new ServiceRegistration(builtInPluginDescriptor, serviceId, new TypeName(serviceType))); registry.RegisterComponent( new ComponentRegistration(builtInPluginDescriptor, serviceDescriptor, serviceId, new TypeName(component.GetType())) { ComponentHandlerFactory = new InstanceHandlerFactory(component) }); }
private void VerifyPluginTraits(IPluginDescriptor plugin, ref bool success) { try { plugin.ResolveTraits(); } catch (Exception ex) { success = false; dispatchLogger.Log(LogSeverity.Error, "Unresolvable plugin traits.", ex); } }
private void RegisterEventHandlerProxy(Type interfaceType, IPluginDescriptor plugin, IServiceDescriptor serviceDescriptor, string componentId) { var proxyType = typeof(EventHandlerProxy <>).MakeGenericType(interfaceType.GetGenericArguments()); var typeName = new TypeName(proxyType).ConvertToPartialAssemblyName(); var componentRegistration = new ComponentRegistration(plugin, serviceDescriptor, Guid.NewGuid().ToString(), typeName); componentRegistration.ComponentProperties.Add("target", string.Format("${{{0}}}", componentId)); registry.RegisterComponent(componentRegistration); }
private IServiceDescriptor GetServiceDescriptor(Type interfaceType, IPluginDescriptor plugin) { var serviceDescriptor = registry.Services.GetByServiceType(interfaceType); if (serviceDescriptor == null) { var serviceRegistration = new ServiceRegistration(plugin, interfaceType.FullName, new TypeName(interfaceType)); serviceDescriptor = registry.RegisterService(serviceRegistration); } return(serviceDescriptor); }
private void RegisterFirstInterface(IEnumerable<Type> interfaceTypes, IPluginDescriptor plugin, string componentId, TypeName typeName) { foreach (var interfaceType in interfaceTypes) { if (IsOpenGenericType(interfaceType)) return; if (ComponentIsAlreadyRegisteredForService(interfaceType, typeName)) return; var serviceDescriptor = GetServiceDescriptor(interfaceType, plugin); RegisterComponent(componentId, typeName, plugin, serviceDescriptor); return; } }
private void RegisterComponent(Type interfaceType, string componentId, TypeName typeName, IPluginDescriptor plugin, IServiceDescriptor serviceDescriptor) { ComponentRegistration componentRegistration; if (IsAnEventHandler(interfaceType)) { componentRegistration = RegisterEventHandlerProxy(interfaceType, plugin, serviceDescriptor, componentId); } else { componentRegistration = new ComponentRegistration(plugin, serviceDescriptor, componentId, typeName); } registry.RegisterComponent(componentRegistration); }
private string FindIcarusPath() { IPluginDescriptor icarusPlugin = registry.Plugins["Gallio.Icarus"]; if (icarusPlugin != null) { foreach (string searchPath in icarusPlugin.GetSearchPaths("Gallio.Icarus.exe")) { if (File.Exists(searchPath)) { return(searchPath); } } } return(null); }
private void RegisterBuiltInComponents() { IPluginDescriptor builtInPlugin = registry.RegisterPlugin( new PluginRegistration("BuiltIn", new TypeName(typeof(DefaultPlugin)), new DirectoryInfo(runtimeSetup.RuntimePath)) { TraitsProperties = { { "Name", "Gallio Built-In Components" }, { "Description", "Provides built-in runtime services." }, { "Version", typeof(DefaultRuntime).Assembly.GetName().Version.ToString() } } }); RegisterBuiltInComponent(builtInPlugin, "BuiltIn.Registry", typeof(IRegistry), registry); RegisterBuiltInComponent(builtInPlugin, "BuiltIn.ServiceLocator", typeof(IServiceLocator), registry.ServiceLocator); RegisterBuiltInComponent(builtInPlugin, "BuiltIn.Logger", typeof(ILogger), dispatchLogger); RegisterBuiltInComponent(builtInPlugin, "BuiltIn.Runtime", typeof(IRuntime), this); RegisterBuiltInComponent(builtInPlugin, "BuiltIn.AssemblyLoader", typeof(IAssemblyLoader), assemblyLoader); RegisterBuiltInComponent(builtInPlugin, "BuiltIn.PluginLoader", typeof(IPluginLoader), pluginLoader); }
private void RegisterFirstInterface(IEnumerable <Type> interfaceTypes, IPluginDescriptor plugin, string componentId, TypeName typeName) { foreach (var interfaceType in interfaceTypes) { if (IsOpenGenericType(interfaceType)) { return; } if (ComponentIsAlreadyRegisteredForService(interfaceType, typeName)) { return; } var serviceDescriptor = GetServiceDescriptor(interfaceType, plugin); RegisterComponent(componentId, typeName, plugin, serviceDescriptor); return; } }
private static void RegisterComponents(IRegistry registry, IList <PluginData> topologicallySortedPlugins, IList <IPluginDescriptor> pluginDescriptors) { for (int i = 0; i < topologicallySortedPlugins.Count; i++) { Plugin plugin = topologicallySortedPlugins[i].Plugin; IPluginDescriptor pluginDescriptor = pluginDescriptors[i]; foreach (Component component in plugin.Components) { var serviceDescriptor = registry.Services[component.ServiceId]; if (serviceDescriptor == null) { throw new RuntimeException(string.Format("Could not register component '{0}' of plugin '{1}' because it implements service '{2}' which was not found in the registry.", component.ComponentId, plugin.PluginId, component.ServiceId)); } try { var componentRegistration = new ComponentRegistration(pluginDescriptor, serviceDescriptor, component.ComponentId, component.ComponentType != null ? new TypeName(component.ComponentType) : null); if (component.Parameters != null) { componentRegistration.ComponentProperties = component.Parameters.PropertySet; } if (component.Traits != null) { componentRegistration.TraitsProperties = component.Traits.PropertySet; } registry.RegisterComponent(componentRegistration); } catch (Exception ex) { throw new RuntimeException(string.Format("Could not register component '{0}' of plugin '{1}'.", component.ComponentId, plugin.PluginId), ex); } } } }
private void VerifyPluginAssemblyBindings(IPluginDescriptor plugin, ref bool success) { foreach (AssemblyBinding assemblyBinding in plugin.AssemblyBindings) { try { if (assemblyBinding.CodeBase != null && assemblyBinding.CodeBase.IsFile) { var assemblyName = AssemblyName.GetAssemblyName(assemblyBinding.CodeBase.LocalPath); if (assemblyName.FullName != assemblyBinding.AssemblyName.FullName) { success = false; dispatchLogger.Log(LogSeverity.Error, string.Format( "Plugin '{0}' has an incorrect assembly binding. Accoding to the plugin metadata we expected assembly name '{1}' but it was actually '{2}' when loaded.", plugin.PluginId, assemblyBinding.AssemblyName.FullName, assemblyName.FullName)); } } else if (assemblyBinding.CodeBase == null) { try { Assembly.Load(assemblyBinding.AssemblyName); } catch (FileNotFoundException) { success = false; dispatchLogger.Log(LogSeverity.Error, string.Format( "Plugin '{0}' expects assembly '{1}' to be installed in the GAC but it was not found.", plugin.PluginId, assemblyBinding.AssemblyName.FullName)); } } } catch (Exception ex) { success = false; dispatchLogger.Log(LogSeverity.Error, string.Format("Plugin '{0}' has an assembly reference for that could not be loaded with code base '{1}'.", plugin.PluginId, assemblyBinding.CodeBase), ex); } } }
public Res<PluginBootstrapResult> BootstrapPlugin(IPluginDescriptor descriptor) { PluginBootstrapResult res = PluginBootstrapResult.Success; if (descriptor == null) throw new ArgumentNullException("Descriptor must be supplied"); try { // If descriptor has no controller type set, then set the current default if (descriptor.Metadata.ControllerType == null) { descriptor.Metadata.ControllerType = _pluginControllerFactory .CreateController().GetType(); } return new Res<PluginBootstrapResult>(res == PluginBootstrapResult.Success, res); } catch (Exception ex) { throw new ApplicationException("Failed to bootstrap plugin", ex); } }
private void RegisterComponentForServices(Assembly assembly, Type type, TypeName typeName, IPluginDescriptor plugin) { var componentId = type.FullName; foreach (var interfaceType in type.GetInterfaces()) { if (false == RelevantInterface(interfaceType, assembly)) continue; if (IsOpenGenericType(interfaceType)) continue; if (ComponentAlreadyRegisteredForService(interfaceType, typeName)) continue; var serviceDescriptor = GetServiceDescriptor(interfaceType, plugin); RegisterComponent(interfaceType, componentId, typeName, plugin, serviceDescriptor); } }
public object CreatePluginInstance(IPluginDescriptor descriptor, string pluginAssemblyPath, IPluginInstance pluginManagedInstance, IPluginInteractionLinkFactory pluginInteractionLinkFactory) { if (descriptor == null) throw new ArgumentNullException("Plugin descriptor must be supplied"); if (string.IsNullOrEmpty(pluginAssemblyPath)) throw new ArgumentNullException("Plugin assembly path must be supplied"); try { lock (_lock) { if (!_pluginInstance.IsWritten) { _pluginDescriptor.Value = descriptor; _pluginInstance.Value = (IPlugin)_appDomainBridge.Value.CreateInstance(descriptor.PluginTypeName, pluginAssemblyPath); _pluginInteractionLink.Value = pluginInteractionLinkFactory.CreateInteractionLink( descriptor, _pluginInstance.Value, this, pluginManagedInstance); return _pluginInstance.Value; } else { throw new InvalidOperationException("Controller already created plugin instance"); } } } catch (Exception ex) { throw new ApplicationException("Failed to create plugin instance", ex); } }
private void RegisterEventHandlers(IEnumerable <Type> interfaceTypes, IPluginDescriptor plugin, string componentId, TypeName typeName) { foreach (var interfaceType in interfaceTypes) { if (IsAnEventHandler(interfaceType) == false) { continue; } if (IsOpenGenericType(interfaceType)) { continue; } if (ComponentIsAlreadyRegisteredForService(interfaceType, typeName)) { continue; } var serviceDescriptor = GetServiceDescriptor(interfaceType, plugin); RegisterEventHandlerProxy(interfaceType, plugin, serviceDescriptor, componentId); } }
private bool _pluginExistsInAssembly(IPluginDescriptor descriptor) { if (descriptor == null) throw new ArgumentNullException("Descriptor must be supplied"); try { // While plugins do have identifiers that are intended to be unique, this is by no means // a concrete guarantee that a plugin is present. // Because the plugin type names are most likely to be unique these are used // as the basis of any presence tests. return (GetPluginDescriptors() .DefaultIfEmpty(null) .SingleOrDefault(d => d.PluginTypeName == descriptor.PluginTypeName) != null); } catch (Exception ex) { throw new ApplicationException("Failed to determine if plugin exists within assembly", ex); } }
/// <summary> /// Initializes a new instance of the <see cref="PluginManager"/> class. /// </summary> public PluginManager() { // Just so that it does not return null; PluginDescriptors = new IPluginDescriptor[0]; }
public DistribPlugin(IPluginDescriptor descriptor) { _pluginDescriptor = descriptor; }
public bool PluginTypeIsMarshalable(IPluginDescriptor descriptor) { if (descriptor == null) throw new ArgumentNullException("Descriptor must be supplied"); try { if (!_pluginExistsInAssembly(descriptor)) { throw new InvalidOperationException("A plugin matching the details supplied could not be found"); } var t = _assembly.GetType(descriptor.PluginTypeName); return (t.BaseType != null && t.BaseType.Equals(typeof(CrossAppDomainObject))); } catch (Exception ex) { throw new ApplicationException("Failed to determine if plugin is marshalable", ex); } }
private IServiceDescriptor GetServiceDescriptor(Type interfaceType, IPluginDescriptor plugin) { var serviceDescriptor = registry.Services.GetByServiceType(interfaceType); if (serviceDescriptor == null) { var serviceRegistration = new ServiceRegistration(plugin, interfaceType.FullName, new TypeName(interfaceType)); serviceDescriptor = registry.RegisterService(serviceRegistration); } return serviceDescriptor; }
public void Update(IPluginDescriptor descriptor) { _plugins[descriptor.Key] = descriptor; }
private void RegisterEventHandlers(IEnumerable<Type> interfaceTypes, IPluginDescriptor plugin, string componentId, TypeName typeName) { foreach (var interfaceType in interfaceTypes) { if (IsAnEventHandler(interfaceType) == false) continue; if (IsOpenGenericType(interfaceType)) continue; if (ComponentIsAlreadyRegisteredForService(interfaceType, typeName)) continue; var serviceDescriptor = GetServiceDescriptor(interfaceType, plugin); RegisterEventHandlerProxy(interfaceType, plugin, serviceDescriptor, componentId); } }
private static IList<IPluginDescriptor> RegisterPlugins(IRegistry registry, IList<PluginData> topologicallySortedPlugins) { IPluginDescriptor[] pluginDescriptors = new IPluginDescriptor[topologicallySortedPlugins.Count]; for (int i = 0; i < topologicallySortedPlugins.Count; i++) { Plugin plugin = topologicallySortedPlugins[i].Plugin; DirectoryInfo baseDirectory = topologicallySortedPlugins[i].BaseDirectory; try { var pluginType = plugin.PluginType != null ? new TypeName(plugin.PluginType) : new TypeName(typeof(DefaultPlugin)); List<string> disabledReasons = new List<string>(); var pluginRegistration = new PluginRegistration(plugin.PluginId, pluginType, baseDirectory); if (plugin.Parameters != null) pluginRegistration.PluginProperties = plugin.Parameters.PropertySet; if (plugin.Traits != null) pluginRegistration.TraitsProperties = plugin.Traits.PropertySet; pluginRegistration.ProbingPaths = plugin.ProbingPaths; pluginRegistration.RecommendedInstallationPath = plugin.RecommendedInstallationPath; if (plugin.EnableCondition != null) pluginRegistration.EnableCondition = Condition.Parse(plugin.EnableCondition); foreach (var file in plugin.Files) pluginRegistration.FilePaths.Add(file.Path); foreach (var dependency in plugin.Dependencies) { string pluginDependencyId = dependency.PluginId; IPluginDescriptor pluginDependency = registry.Plugins[pluginDependencyId]; if (pluginDependency == null) { disabledReasons.Add(string.Format("Could not find plugin '{0}' upon which this plugin depends.", pluginDependencyId)); } else { pluginRegistration.PluginDependencies.Add(pluginDependency); } } foreach (var assembly in plugin.Assemblies) { Uri absoluteCodeBase; if (assembly.CodeBase != null) { List<string> attemptedPaths = new List<string>(); string foundCodeBasePath = ProbeForCodeBase(baseDirectory, plugin.ProbingPaths, assembly.CodeBase, attemptedPaths); if (foundCodeBasePath == null) { StringBuilder formattedPaths = new StringBuilder(); foreach (string path in attemptedPaths) { if (formattedPaths.Length != 0) formattedPaths.Append(", "); formattedPaths.Append("'").Append(path).Append("'"); } disabledReasons.Add(string.Format("Could not find assembly '{0}' after probing for its code base in {1}.", assembly.FullName, formattedPaths)); absoluteCodeBase = null; } else { absoluteCodeBase = new Uri(foundCodeBasePath); } } else { #if STRICT_GAC_CHECKS if (!IsAssemblyRegisteredInGAC(assembly.FullName)) { disabledReasons.Add( string.Format("Could not find assembly '{0}' in the global assembly cache.", assembly.FullName)); } #endif absoluteCodeBase = null; } var assemblyBinding = new AssemblyBinding(new AssemblyName(assembly.FullName)) { CodeBase = absoluteCodeBase, QualifyPartialName = assembly.QualifyPartialName, ApplyPublisherPolicy = assembly.ApplyPublisherPolicy }; foreach (BindingRedirect redirect in assembly.BindingRedirects) assemblyBinding.AddBindingRedirect(new AssemblyBinding.BindingRedirect(redirect.OldVersion)); pluginRegistration.AssemblyBindings.Add(assemblyBinding); } IPluginDescriptor pluginDescriptor = registry.RegisterPlugin(pluginRegistration); pluginDescriptors[i] = pluginDescriptor; if (disabledReasons.Count != 0) pluginDescriptor.Disable(disabledReasons[0]); } catch (Exception ex) { throw new RuntimeException(string.Format("Could not register plugin '{0}'.", plugin.PluginId), ex); } } return pluginDescriptors; }
/// <summary> /// Initializes a new instance of the <see cref="BasePlugin"/> class. /// </summary> /// <param name="pluginDescriptor">The plugin descriptor.</param> /// <exception cref="System.ArgumentNullException">pluginDescriptor</exception> public BasePlugin(IPluginDescriptor pluginDescriptor) { if (pluginDescriptor == null) throw new ArgumentNullException("pluginDescriptor"); descriptor = pluginDescriptor; }
private static IList <IPluginDescriptor> RegisterPlugins(IRegistry registry, IList <PluginData> topologicallySortedPlugins) { IPluginDescriptor[] pluginDescriptors = new IPluginDescriptor[topologicallySortedPlugins.Count]; for (int i = 0; i < topologicallySortedPlugins.Count; i++) { Plugin plugin = topologicallySortedPlugins[i].Plugin; DirectoryInfo baseDirectory = topologicallySortedPlugins[i].BaseDirectory; try { var pluginType = plugin.PluginType != null ? new TypeName(plugin.PluginType) : new TypeName(typeof(DefaultPlugin)); List <string> disabledReasons = new List <string>(); var pluginRegistration = new PluginRegistration(plugin.PluginId, pluginType, baseDirectory); if (plugin.Parameters != null) { pluginRegistration.PluginProperties = plugin.Parameters.PropertySet; } if (plugin.Traits != null) { pluginRegistration.TraitsProperties = plugin.Traits.PropertySet; } pluginRegistration.ProbingPaths = plugin.ProbingPaths; pluginRegistration.RecommendedInstallationPath = plugin.RecommendedInstallationPath; if (plugin.EnableCondition != null) { pluginRegistration.EnableCondition = Condition.Parse(plugin.EnableCondition); } foreach (var file in plugin.Files) { pluginRegistration.FilePaths.Add(file.Path); } foreach (var dependency in plugin.Dependencies) { string pluginDependencyId = dependency.PluginId; IPluginDescriptor pluginDependency = registry.Plugins[pluginDependencyId]; if (pluginDependency == null) { disabledReasons.Add(string.Format("Could not find plugin '{0}' upon which this plugin depends.", pluginDependencyId)); } else { pluginRegistration.PluginDependencies.Add(pluginDependency); } } foreach (var assembly in plugin.Assemblies) { Uri absoluteCodeBase; if (assembly.CodeBase != null) { List <string> attemptedPaths = new List <string>(); string foundCodeBasePath = ProbeForCodeBase(baseDirectory, plugin.ProbingPaths, assembly.CodeBase, attemptedPaths); if (foundCodeBasePath == null) { StringBuilder formattedPaths = new StringBuilder(); foreach (string path in attemptedPaths) { if (formattedPaths.Length != 0) { formattedPaths.Append(", "); } formattedPaths.Append("'").Append(path).Append("'"); } disabledReasons.Add(string.Format("Could not find assembly '{0}' after probing for its code base in {1}.", assembly.FullName, formattedPaths)); absoluteCodeBase = null; } else { absoluteCodeBase = new Uri(foundCodeBasePath); } } else { #if STRICT_GAC_CHECKS if (!IsAssemblyRegisteredInGAC(assembly.FullName)) { disabledReasons.Add( string.Format("Could not find assembly '{0}' in the global assembly cache.", assembly.FullName)); } #endif absoluteCodeBase = null; } var assemblyBinding = new AssemblyBinding(new AssemblyName(assembly.FullName)) { CodeBase = absoluteCodeBase, QualifyPartialName = assembly.QualifyPartialName, ApplyPublisherPolicy = assembly.ApplyPublisherPolicy }; foreach (BindingRedirect redirect in assembly.BindingRedirects) { assemblyBinding.AddBindingRedirect(new AssemblyBinding.BindingRedirect(redirect.OldVersion)); } pluginRegistration.AssemblyBindings.Add(assemblyBinding); } IPluginDescriptor pluginDescriptor = registry.RegisterPlugin(pluginRegistration); pluginDescriptors[i] = pluginDescriptor; if (disabledReasons.Count != 0) { pluginDescriptor.Disable(disabledReasons[0]); } } catch (Exception ex) { throw new RuntimeException(string.Format("Could not register plugin '{0}'.", plugin.PluginId), ex); } } return(pluginDescriptors); }
public static InitializePluginResult FromSuccess([NotNull] IPluginDescriptor plugin) { return(new InitializePluginResult(plugin)); }
public PluginDetailsTreeModel(IPluginDescriptor pluginDescriptor) { this.pluginDescriptor = pluginDescriptor; }
public void Add(IPluginDescriptor descriptor) { _plugins.Add(descriptor.Key, descriptor); }
private static ComponentRegistration RegisterEventHandlerProxy(Type interfaceType, IPluginDescriptor plugin, IServiceDescriptor serviceDescriptor, string componentId) { var proxyType = typeof(EventHandlerProxy<>).MakeGenericType(interfaceType.GetGenericArguments()); var typeName = new TypeName(proxyType).ConvertToPartialAssemblyName(); var componentRegistration = new ComponentRegistration(plugin, serviceDescriptor, Guid.NewGuid().ToString(), typeName); componentRegistration.ComponentProperties.Add("target", string.Format("${{{0}}}", componentId)); return componentRegistration; }
public IPluginInstance CreatePluginInstance(IPluginDescriptor descriptor) { if (descriptor == null) throw new ArgumentNullException("Plugin descriptor must be supplied"); IPluginInstance pluginInstance; try { if (!descriptor.IsUsable) { throw new InvalidOperationException(string.Format("Plugin is marked as excluded: {0}", descriptor.ExclusionReason.ToString())); } lock (_lock) { lock (_pluginInstances) { List<IPluginInstance> instancesList; if (_pluginInstances.TryGetValue(descriptor, out instancesList) == false) { instancesList = new List<IPluginInstance>(); } pluginInstance = _pluginInstanceFactory.CreatePluginInstance(descriptor, this); instancesList.Add(pluginInstance); _pluginInstances[descriptor] = instancesList; } } return pluginInstance; } catch (Exception ex) { throw new ApplicationException("Failed to create plugin instance", ex); } }
/// <summary> /// Creates a service registration. /// </summary> /// <param name="plugin">The plugin to which the service will belong.</param> /// <param name="serviceId">The service id.</param> /// <param name="serviceTypeName">The service type name.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="plugin"/>, <paramref name="serviceId"/> /// or <paramref name="serviceTypeName"/> is null.</exception> public ServiceRegistration(IPluginDescriptor plugin, string serviceId, TypeName serviceTypeName) { Plugin = plugin; ServiceId = serviceId; ServiceTypeName = serviceTypeName; }
/// <summary> /// Initializes a new instance of the <see cref="ReflectorPluginCore"/> class. /// </summary> /// <param name="descriptor">The descriptor.</param> public BaseDecompilerPluginCore(IPluginDescriptor descriptor) : base(descriptor) { }
public bool PluginTypeImplementsPromisedInterface(IPluginDescriptor descriptor) { if (descriptor == null) throw new ArgumentNullException("Descriptor must be supplied"); try { if (!_pluginExistsInAssembly(descriptor)) { throw new InvalidOperationException("A plugin matching the details supplied could not be found"); } return _assembly.GetType(descriptor.PluginTypeName) .GetInterface(descriptor.Metadata.InterfaceType.FullName) != null; } catch (Exception ex) { throw new ApplicationException("Failed to determine if plugin implements promised interface", ex); } }