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> /// 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); }
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 PartDefinition ExtractActionsAndConditions(Type type, PartDefinition part, Func<Type, TypeIdentity> createTypeIdentity) { var actions = new List<ScheduleActionDefinition>(); var conditions = new List<ScheduleConditionDefinition>(); foreach (var method in type.GetMethods()) { if (method.ReturnType == typeof(void) && !method.GetParameters().Any()) { var actionAttribute = method.GetCustomAttribute<ScheduleActionAttribute>(true); if (actionAttribute != null) { var actionDefinition = ScheduleActionDefinition.CreateDefinition( actionAttribute.Name, method, createTypeIdentity); actions.Add(actionDefinition); m_Logger.Log( LevelToLog.Info, string.Format( CultureInfo.InvariantCulture, "Discovered action: {0}", actionDefinition)); } continue; } if (method.ReturnType == typeof(bool) && !method.GetParameters().Any()) { var conditionAttribute = method.GetCustomAttribute<ScheduleConditionAttribute>(true); if (conditionAttribute != null) { var conditionDefinition = MethodBasedScheduleConditionDefinition.CreateDefinition( conditionAttribute.Name, method, createTypeIdentity); conditions.Add(conditionDefinition); m_Logger.Log( LevelToLog.Info, string.Format( CultureInfo.InvariantCulture, "Discovered condition: {0}", conditionDefinition)); } } } foreach (var property in type.GetProperties()) { if (property.PropertyType == typeof(bool)) { var conditionAttribute = property.GetCustomAttribute<ScheduleConditionAttribute>(true); if (conditionAttribute != null) { var conditionDefinition = PropertyBasedScheduleConditionDefinition.CreateDefinition( conditionAttribute.Name, property, createTypeIdentity); conditions.Add(conditionDefinition); m_Logger.Log( LevelToLog.Info, string.Format( CultureInfo.InvariantCulture, "Discovered condition: {0}", conditionDefinition)); } } } if (actions.Count > 0 || conditions.Count > 0) { part.Actions = actions; part.Conditions = conditions; } return part; }