public void AddGroup() { var repository = new PluginRepository(); var definition = new GroupDefinition("a"); var fileInfo = new PluginFileInfo("a", DateTimeOffset.Now); repository.AddGroup(definition, fileInfo); var groups = repository.Groups(); Assert.AreEqual(1, groups.Count()); Assert.AreSame(definition, groups.First()); Assert.AreSame(definition, repository.Group(new GroupRegistrationId("a"))); var files = repository.KnownPluginFiles(); Assert.AreEqual(1, files.Count()); Assert.AreSame(fileInfo, files.First()); }
/// <summary> /// Adds a new part group to the repository. /// </summary> /// <param name="group">The part group definition.</param> /// <param name="pluginFileInfo">The file info of the assembly which owns the group.</param> public void AddGroup(GroupDefinition group, PluginFileInfo pluginFileInfo) { lock (m_Lock) { { Lokad.Enforce.Argument(() => group); Lokad.Enforce.Argument(() => pluginFileInfo); Lokad.Enforce.With<DuplicateGroupDefinitionException>( !m_Groups.ContainsKey(group.Id), Resources.Exceptions_Messages_DuplicateGroupDefinition); } m_Groups.Add(group.Id, new Tuple<GroupDefinition, PluginFileInfo>(group, pluginFileInfo)); if (!m_PluginFiles.Contains(pluginFileInfo)) { m_PluginFiles.Add(pluginFileInfo); } } }
public void RemovePluginsWithParentType() { var currentlyBuilding = new Dictionary <Type, TypeIdentity>(); var repository = new PluginRepository(); Func <Type, TypeIdentity> identityGenerator = TypeIdentityBuilder.IdentityFactory(repository, currentlyBuilding); PartDefinition parentDefinition = new PartDefinition { Identity = identityGenerator(typeof(MockExportingInterfaceImplementation)), }; var parentFileInfo = new PluginFileInfo("a", DateTimeOffset.Now); repository.AddPart(parentDefinition, parentFileInfo); PartDefinition childDefinition = new PartDefinition { Identity = identityGenerator(typeof(MockChildExportingInterfaceImplementation)), }; var childFileInfo = new PluginFileInfo("b", DateTimeOffset.Now); repository.AddPart(childDefinition, childFileInfo); Assert.IsTrue(repository.ContainsDefinitionForType(TypeIdentity.CreateDefinition(typeof(MockExportingInterfaceImplementation)))); Assert.IsTrue(repository.ContainsDefinitionForType(TypeIdentity.CreateDefinition(typeof(MockChildExportingInterfaceImplementation)))); Assert.IsTrue( repository.IsSubTypeOf( TypeIdentity.CreateDefinition(typeof(object)), TypeIdentity.CreateDefinition(typeof(MockChildExportingInterfaceImplementation)))); repository.RemovePlugins(new string[] { parentFileInfo.Path }); Assert.IsFalse(repository.ContainsDefinitionForType(TypeIdentity.CreateDefinition(typeof(MockExportingInterfaceImplementation)))); Assert.IsTrue(repository.ContainsDefinitionForType(TypeIdentity.CreateDefinition(typeof(MockChildExportingInterfaceImplementation)))); Assert.IsFalse( repository.IsSubTypeOf( TypeIdentity.CreateDefinition(typeof(object)), TypeIdentity.CreateDefinition(typeof(MockChildExportingInterfaceImplementation)))); }
public void AddPart() { var currentlyBuilding = new Dictionary<Type, TypeIdentity>(); var repository = new PluginRepository(); Func<Type, TypeIdentity> identityGenerator = TypeIdentityBuilder.IdentityFactory(repository, currentlyBuilding); PartDefinition definition = new PartDefinition { Identity = identityGenerator(typeof(ExportOnProperty)), }; var fileInfo = new PluginFileInfo("a", DateTimeOffset.Now); repository.AddPart(definition, fileInfo); var parts = repository.Parts(); Assert.AreEqual(1, parts.Count()); Assert.AreSame(definition, parts.First()); Assert.AreSame(definition, repository.Part(TypeIdentity.CreateDefinition(typeof(ExportOnProperty)))); var files = repository.KnownPluginFiles(); Assert.AreEqual(1, files.Count()); Assert.AreSame(fileInfo, files.First()); }
/// <summary> /// Initializes a new instance of the <see cref="GroupDefinitionBuilder"/> class. /// </summary> /// <param name="repository">The object that stores information about all the known parts and part groups.</param> /// <param name="importEngine">The object that matches part imports with part exports.</param> /// <param name="identityGenerator">The function that generates type identity objects.</param> /// <param name="builderGenerator">The function that is used to create schedule builders.</param> /// <param name="fileInfo">The file info for the assembly that owns the group exporter.</param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="repository"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="importEngine"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="identityGenerator"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="builderGenerator"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="fileInfo"/> is <see langword="null" />. /// </exception> public GroupDefinitionBuilder( IPluginRepository repository, IConnectParts importEngine, Func<Type, TypeIdentity> identityGenerator, Func<IBuildFixedSchedules> builderGenerator, PluginFileInfo fileInfo) { { Lokad.Enforce.Argument(() => repository); Lokad.Enforce.Argument(() => importEngine); Lokad.Enforce.Argument(() => identityGenerator); Lokad.Enforce.Argument(() => builderGenerator); Lokad.Enforce.Argument(() => fileInfo); } m_BuilderGenerator = builderGenerator; m_ImportEngine = importEngine; m_IdentityGenerator = identityGenerator; m_Repository = repository; m_FileInfo = fileInfo; }
/// <summary> /// Adds a new part to the repository. /// </summary> /// <param name="part">The part definition.</param> /// <param name="pluginFileInfo">The file info of the assembly which owns the part.</param> public void AddPart(PartDefinition part, PluginFileInfo pluginFileInfo) { lock (m_Lock) { { Lokad.Enforce.Argument(() => part); Lokad.Enforce.Argument(() => pluginFileInfo); Lokad.Enforce.With<DuplicatePartDefinitionException>( !m_Parts.ContainsKey(part.Identity), Resources.Exceptions_Messages_DuplicatePartDefinition); } m_Parts.Add(part.Identity, new Tuple<PartDefinition, PluginFileInfo>(part, pluginFileInfo)); if (!m_PluginFiles.Contains(pluginFileInfo)) { m_PluginFiles.Add(pluginFileInfo); } } }
/// <summary> /// Adds a new part to the repository. /// </summary> /// <param name="part">The part definition.</param> /// <param name="pluginFileInfo">The file info of the assembly which owns the part.</param> public void AddPart(PartDefinition part, PluginFileInfo pluginFileInfo) { m_Repository.AddPart(part, pluginFileInfo); }
/// <summary> /// Adds a new part group to the repository. /// </summary> /// <param name="group">The part group definition.</param> /// <param name="pluginFileInfo">The file info of the assembly which owns the group.</param> public void AddGroup(GroupDefinition group, PluginFileInfo pluginFileInfo) { m_Repository.AddGroup(group, pluginFileInfo); }
public void RemovePluginsWithParentType() { var currentlyBuilding = new Dictionary<Type, TypeIdentity>(); var repository = new PluginRepository(); Func<Type, TypeIdentity> identityGenerator = TypeIdentityBuilder.IdentityFactory(repository, currentlyBuilding); PartDefinition parentDefinition = new PartDefinition { Identity = identityGenerator(typeof(MockExportingInterfaceImplementation)), }; var parentFileInfo = new PluginFileInfo("a", DateTimeOffset.Now); repository.AddPart(parentDefinition, parentFileInfo); PartDefinition childDefinition = new PartDefinition { Identity = identityGenerator(typeof(MockChildExportingInterfaceImplementation)), }; var childFileInfo = new PluginFileInfo("b", DateTimeOffset.Now); repository.AddPart(childDefinition, childFileInfo); Assert.IsTrue(repository.ContainsDefinitionForType(TypeIdentity.CreateDefinition(typeof(MockExportingInterfaceImplementation)))); Assert.IsTrue(repository.ContainsDefinitionForType(TypeIdentity.CreateDefinition(typeof(MockChildExportingInterfaceImplementation)))); Assert.IsTrue( repository.IsSubTypeOf( TypeIdentity.CreateDefinition(typeof(object)), TypeIdentity.CreateDefinition(typeof(MockChildExportingInterfaceImplementation)))); repository.RemovePlugins(new string[] { parentFileInfo.Path }); Assert.IsFalse(repository.ContainsDefinitionForType(TypeIdentity.CreateDefinition(typeof(MockExportingInterfaceImplementation)))); Assert.IsTrue(repository.ContainsDefinitionForType(TypeIdentity.CreateDefinition(typeof(MockChildExportingInterfaceImplementation)))); Assert.IsFalse( repository.IsSubTypeOf( TypeIdentity.CreateDefinition(typeof(object)), TypeIdentity.CreateDefinition(typeof(MockChildExportingInterfaceImplementation)))); }
public void RemovePlugins() { var currentlyBuilding = new Dictionary<Type, TypeIdentity>(); var repository = new PluginRepository(); Func<Type, TypeIdentity> identityGenerator = TypeIdentityBuilder.IdentityFactory(repository, currentlyBuilding); PartDefinition partDefinition = new PartDefinition { Identity = identityGenerator(typeof(ExportOnProperty)), }; var partFileInfo = new PluginFileInfo("a", DateTimeOffset.Now); repository.AddPart(partDefinition, partFileInfo); var groupDefinition = new GroupDefinition("b"); var groupFileInfo = new PluginFileInfo("c", DateTimeOffset.Now); repository.AddGroup(groupDefinition, groupFileInfo); Assert.That( repository.KnownPluginFiles(), Is.EquivalentTo( new List<PluginFileInfo> { partFileInfo, groupFileInfo, })); repository.RemovePlugins( new List<string> { partFileInfo.Path }); Assert.That( repository.KnownPluginFiles(), Is.EquivalentTo( new List<PluginFileInfo> { groupFileInfo, })); Assert.AreEqual(0, repository.Parts().Count()); Assert.AreEqual(1, repository.Groups().Count()); Assert.IsFalse(repository.ContainsDefinitionForType(typeof(ExportOnProperty).AssemblyQualifiedName)); }
private void ScanAssembly(Assembly assembly) { try { m_Logger.Log( LevelToLog.Trace, string.Format( CultureInfo.InvariantCulture, Resources.RemoteAssemblyScanner_LogMessage_ScanningAssembly_WithName, assembly.FullName)); var file = new FileInfo(assembly.LocalFilePath()); var fileInfo = new PluginFileInfo(file.FullName, file.LastWriteTimeUtc); var createTypeIdentity = TypeIdentityBuilder.IdentityFactory(m_Repository, new Dictionary<Type, TypeIdentity>()); var mefParts = ExtractImportsAndExports(assembly, createTypeIdentity); var parts = mefParts.Select(p => ExtractActionsAndConditions(p.Item1, p.Item2, createTypeIdentity)); foreach (var part in parts) { m_Logger.Log( LevelToLog.Trace, string.Format( CultureInfo.InvariantCulture, Resources.RemoteAssemblyScanner_LogMessage_AddingPartToRepository_WithPartInformation, part.Identity)); m_Repository.AddPart(part, fileInfo); } var groupExporters = assembly.GetTypes().Where(t => typeof(IExportGroupDefinitions).IsAssignableFrom(t)); foreach (var t in groupExporters) { try { m_Logger.Log( LevelToLog.Trace, string.Format( CultureInfo.InvariantCulture, Resources.RemoteAssemblyScanner_LogMessage_RegisteringGroupsViaExporter_WithExporterType, t.AssemblyQualifiedName)); var builder = new GroupDefinitionBuilder( m_Repository, m_ImportEngine, createTypeIdentity, m_ScheduleBuilder, fileInfo); var exporter = Activator.CreateInstance(t) as IExportGroupDefinitions; exporter.RegisterGroups(builder); } catch (Exception e) { m_Logger.Log(LevelToLog.Warn, e.ToString()); } } } catch (Exception e) { m_Logger.Log( LevelToLog.Error, string.Format( CultureInfo.InvariantCulture, Resources.Plugins_LogMessage_Scanner_TypeScanFailed_WithAssemblyAndException, assembly.GetName().FullName, e)); } }
private void ScanAssembly(Assembly assembly) { try { m_Logger.Log( LevelToLog.Trace, string.Format( CultureInfo.InvariantCulture, Resources.RemoteAssemblyScanner_LogMessage_ScanningAssembly_WithName, assembly.FullName)); var file = new FileInfo(assembly.LocalFilePath()); var fileInfo = new PluginFileInfo(file.FullName, file.LastWriteTimeUtc); var createTypeIdentity = TypeIdentityBuilder.IdentityFactory(m_Repository, new Dictionary <Type, TypeIdentity>()); var mefParts = ExtractImportsAndExports(assembly, createTypeIdentity); var parts = mefParts.Select(p => ExtractActionsAndConditions(p.Item1, p.Item2, createTypeIdentity)); foreach (var part in parts) { m_Logger.Log( LevelToLog.Trace, string.Format( CultureInfo.InvariantCulture, Resources.RemoteAssemblyScanner_LogMessage_AddingPartToRepository_WithPartInformation, part.Identity)); m_Repository.AddPart(part, fileInfo); } var groupExporters = assembly.GetTypes().Where(t => typeof(IExportGroupDefinitions).IsAssignableFrom(t)); foreach (var t in groupExporters) { try { m_Logger.Log( LevelToLog.Trace, string.Format( CultureInfo.InvariantCulture, Resources.RemoteAssemblyScanner_LogMessage_RegisteringGroupsViaExporter_WithExporterType, t.AssemblyQualifiedName)); var builder = new GroupDefinitionBuilder( m_Repository, m_ImportEngine, createTypeIdentity, m_ScheduleBuilder, fileInfo); var exporter = Activator.CreateInstance(t) as IExportGroupDefinitions; exporter.RegisterGroups(builder); } catch (Exception e) { m_Logger.Log(LevelToLog.Warn, e.ToString()); } } } catch (Exception e) { m_Logger.Log( LevelToLog.Error, string.Format( CultureInfo.InvariantCulture, Resources.Plugins_LogMessage_Scanner_TypeScanFailed_WithAssemblyAndException, assembly.GetName().FullName, e)); } }