/// <summary> /// Writes a <see cref="RequirementLayer"/> as xml. /// </summary> /// <param name="w">The xml stream to write to: an element must be opened.</param> /// <param name="o">The object to write. Can not be null.</param> public static void WriteInlineToXml(XmlWriter w, RequirementLayer o) { w.WriteAttributeString("Name", o.LayerName); w.WriteStartElement("PluginRequirements"); foreach (PluginRequirement req in o.PluginRequirements) { w.WriteStartElement("PluginRequirement"); w.WriteAttributeString("PluginId", req.PluginId.ToString()); w.WriteAttributeString("Requirement", req.Requirement.ToString()); w.WriteFullEndElement(); } w.WriteFullEndElement(); w.WriteStartElement("ServiceRequirements"); foreach (ServiceRequirement req in o.ServiceRequirements) { w.WriteStartElement("ServiceRequirement"); w.WriteAttributeString("AssemblyQualifiedName", req.AssemblyQualifiedName); w.WriteAttributeString("Requirement", req.Requirement.ToString()); w.WriteFullEndElement(); } w.WriteFullEndElement(); }
public VMRequirementLayer( VMICoreElement element, RequirementLayer layer ) { _layer = layer; _element = element; _type = CoreElementType.Unknown; element = ExtractCoreElementType( element ); }
public void ApplicationExitDisableRunner() { Guid simplePluginId = new Guid( "{EEAEC976-2AFC-4A68-BFAD-68E169677D52}" ); TestContextHost host = new TestContextHost("TestContexts"); IContext c = host.CreateContext(); TestBase.CopyPluginToTestDir( "SimplePlugin.dll" ); c.PluginRunner.Discoverer.Discover( TestBase.TestFolderDir, true ); var pluginId = c.PluginRunner.Discoverer.FindPlugin( simplePluginId ); Assert.That( pluginId, Is.Not.Null ); Assert.That( c.PluginRunner.PluginHost.IsPluginRunning( pluginId ), Is.False ); Assert.That( c.PluginRunner.PluginHost.IsPluginRunning( pluginId.PluginId ), Is.False ); var req = new RequirementLayer( "Start SimplePlugin" ); req.PluginRequirements.AddOrSet( simplePluginId, RunningRequirement.MustExistAndRun ); c.PluginRunner.Add( req ); c.PluginRunner.Apply(); Assert.That( c.PluginRunner.PluginHost.IsPluginRunning( pluginId ), Is.True, "SimplePlugin is running." ); Assert.That( c.PluginRunner.PluginHost.IsPluginRunning( pluginId.PluginId ), Is.True, "SimplePlugin is running." ); int eventPhasis = 0; c.PluginRunner.PluginHost.StatusChanged += ( o, e ) => { Assert.That( eventPhasis >= 0 && eventPhasis < 3 ); Assert.That( e.PluginProxy.PluginKey.PluginId, Is.EqualTo( simplePluginId ) ); if( eventPhasis == 0 ) { Assert.That( e.Previous, Is.EqualTo( RunningStatus.Started ) ); Assert.That( e.PluginProxy.Status, Is.EqualTo( RunningStatus.Stopping ) ); eventPhasis = 1; } else if( eventPhasis == 1 ) { Assert.That( e.Previous, Is.EqualTo( RunningStatus.Stopping ) ); Assert.That( e.PluginProxy.Status, Is.EqualTo( RunningStatus.Stopped ) ); eventPhasis = 2; } else if( eventPhasis == 2 ) { Assert.That( e.Previous, Is.EqualTo( RunningStatus.Stopped ) ); Assert.That( e.PluginProxy.Status, Is.EqualTo( RunningStatus.Disabled ) ); eventPhasis = 3; } }; Assert.That( c.RaiseExitApplication( true ) ); Assert.That( c.PluginRunner.PluginHost.IsPluginRunning( pluginId ), Is.False, "SimplePlugin is no more running." ); Assert.That( c.PluginRunner.PluginHost.IsPluginRunning( pluginId.PluginId ), Is.False, "SimplePlugin is no more running." ); }
internal Keyboard( KeyboardCollection holder, string name ) { Debug.Assert( holder != null ); _keyboards = holder; _zones = new ZoneCollection( this ); _layouts = new LayoutCollection( this ); _name = name; _availableMode = _keyboards.Context.EmptyMode; _currentMode = _keyboards.Context.EmptyMode; _reqLayer = new RequirementLayer( "Keyboard" ); }
/// <summary> /// Reads back an existing <see cref="RequirementLayer"/> or creates a new one /// from xml data previously written by <see cref="WriteInlineToXml"/> method. /// </summary> /// <param name="r">The xml stream to read: the reader must be on an opened element.</param> /// <param name="reqLayer">An existing layer or null to create a new one.</param> public static void ReadInlineFromXml( XmlReader r, ref RequirementLayer reqLayer ) { if( reqLayer != null ) { reqLayer.LayerName = r.GetAttribute( "Name" ); } else reqLayer = new RequirementLayer( r.GetAttribute( "Name" ) ); r.Read(); if( r.IsStartElement( "PluginRequirements" ) ) { if( r.IsEmptyElement ) r.Read(); else { r.Read(); reqLayer.PluginRequirements.Clear(); while( r.IsStartElement( "PluginRequirement" ) ) { Guid pluginId = new Guid( r.GetAttribute( "PluginId" ) ); RunningRequirement runningReq = (RunningRequirement)Enum.Parse( typeof( RunningRequirement ), r.GetAttribute( "Requirement" ) ); reqLayer.PluginRequirements.AddOrSet( pluginId, runningReq ); if( r.IsEmptyElement ) r.Read(); else r.Skip(); } r.ReadEndElement(); } } if( r.IsStartElement( "ServiceRequirements" ) ) { if( r.IsEmptyElement ) r.Read(); else { r.Read(); reqLayer.ServiceRequirements.Clear(); while( r.IsStartElement( "ServiceRequirement" ) ) { string assemblyQualifiedName = r.GetAttribute( "AssemblyQualifiedName" ); RunningRequirement runningReq = (RunningRequirement)Enum.Parse( typeof( RunningRequirement ), r.GetAttribute( "Requirement" ) ); reqLayer.ServiceRequirements.AddOrSet( assemblyQualifiedName, runningReq ); if( r.IsEmptyElement ) r.Read(); else r.Skip(); } r.ReadEndElement(); } } }
public void SimpleWithoutDiscoverer() { Guid id = Guid.NewGuid(); RequirementLayer layer = new RequirementLayer( "MyLayer" ); PluginRunner.Add( layer ); Assert.That( !PluginRunner.IsDirty, "Not dirty because the layer is empty" ); layer.PluginRequirements.AddOrSet( id, RunningRequirement.MustExistAndRun ); Assert.That( !PluginRunner.IsDirty, "Not dirty since the plugin is not found in the discoverer: it is Disabled." ); PluginRunner.Remove( layer ); Assert.That( !PluginRunner.IsDirty, "Not dirty because the PluginRunner doesn't contains any requirement" ); }
public void SimpleRequirementLayer() { Guid id = new Guid( "{12A9FCC0-ECDC-4049-8DBF-8961E49A9EDE}" ); TestBase.CopyPluginToTestDir( "ServiceA.dll" ); PluginRunner.Discoverer.Discover( TestBase.TestFolderDir, true ); RequirementLayer layer = new RequirementLayer( "MyLayer" ); PluginRunner.Add( layer ); Assert.That( !PluginRunner.IsDirty, "Not dirty because the layer is empty" ); layer.PluginRequirements.AddOrSet( id, RunningRequirement.MustExistAndRun ); Assert.That( PluginRunner.IsDirty, "Dirty because the plugin has been found in the discoverer." ); Assert.IsTrue( PluginRunner.Remove( layer ) ); Assert.That( PluginRunner.RunnerRequirements.Count, Is.EqualTo( 0 ) ); Assert.That( !PluginRunner.IsDirty, "Not dirty because the PluginRunner doesn't contains any requirement" ); }
public VMIPluginRequirementLayer( VMIPlugin plugin, RequirementLayer layer ) { _layer = layer; _plugin = plugin; }
public void LiveUserConfigOptional() { Guid id_plugin1 = new Guid( "{12A9FCC0-ECDC-4049-8DBF-8961E49A9EDE}" ); Guid id_plugin2 = new Guid( "{E64F17D5-DCAB-4A07-8CEE-901A87D8295E}" ); TestBase.CopyPluginToTestDir( "ServiceA.dll" ); TestBase.CopyPluginToTestDir( "ServiceB.dll" ); PluginRunner.Discoverer.Discover( TestBase.TestFolderDir, true ); RequirementLayer layer = new RequirementLayer( "MyLayer" ); PluginRunner.Add( layer ); Assert.That( !PluginRunner.IsDirty, "Not dirty because the layer is empty" ); layer.PluginRequirements.AddOrSet( id_plugin1, RunningRequirement.Optional ); Assert.That( !PluginRunner.IsDirty, "Still not dirty because plugin's are optional ... so we have nothing to change." ); ConfigManager.UserConfiguration.LiveUserConfiguration.SetAction( id_plugin2, ConfigUserAction.None ); Assert.That( !PluginRunner.IsDirty ); Assert.IsTrue( PluginRunner.Remove( layer ) ); Assert.That( PluginRunner.RunnerRequirements.Count, Is.EqualTo( 0 ) ); Assert.That( !PluginRunner.IsDirty, "Not dirty because of the live user" ); }
/// <summary> /// Writes a <see cref="RequirementLayer"/> as xml. /// </summary> /// <param name="w">The xml stream to write to: an element must be opened.</param> /// <param name="o">The object to write. Can not be null.</param> public static void WriteInlineToXml( XmlWriter w, RequirementLayer o ) { w.WriteAttributeString( "Name", o.LayerName ); w.WriteStartElement( "PluginRequirements" ); foreach( PluginRequirement req in o.PluginRequirements ) { w.WriteStartElement( "PluginRequirement" ); w.WriteAttributeString( "PluginId", req.PluginId.ToString() ); w.WriteAttributeString( "Requirement", req.Requirement.ToString() ); w.WriteFullEndElement(); } w.WriteFullEndElement(); w.WriteStartElement( "ServiceRequirements" ); foreach( ServiceRequirement req in o.ServiceRequirements ) { w.WriteStartElement( "ServiceRequirement" ); w.WriteAttributeString( "AssemblyQualifiedName", req.AssemblyQualifiedName ); w.WriteAttributeString( "Requirement", req.Requirement.ToString() ); w.WriteFullEndElement(); } w.WriteFullEndElement(); }
public override IContext CreateContext() { IContext ctx = base.CreateContext(); _log.Debug( "LAUNCHING" ); _log.Debug( String.Format( "Launching {0} > Distribution : {1} > Version : {2}, GUID : {3}", CKApp.CurrentParameters.AppName, CKApp.CurrentParameters.DistribName, AppVersion, ApplicationGUID ) ); _notificationMngr = new NotificationManager(); // Discover available plugins. string pluginPath = Path.Combine( Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ), "Plugins" ); if( Directory.Exists( pluginPath ) ) ctx.PluginRunner.Discoverer.Discover( new DirectoryInfo( pluginPath ), true ); RequirementLayer hostRequirements = new RequirementLayer( "CivikeyStandardHost" ); hostRequirements.PluginRequirements.AddOrSet( new Guid( "{2ed1562f-2416-45cb-9fc8-eef941e3edbc}" ), RunningRequirement.MustExistAndRun ); //KeyboardContext hostRequirements.PluginRequirements.AddOrSet( new Guid( "{1DB78D66-B5EC-43AC-828C-CCAB91FA6210}" ), RunningRequirement.MustExistAndRun ); //HelpService hostRequirements.PluginRequirements.AddOrSet( new Guid( "{0F740086-85AC-46EB-87ED-12A4CA2D12D9}" ), RunningRequirement.MustExistAndRun ); //SendString //Making sure that these services are started regardless of the keyboard being opened at launch. //This way, even keyboards created by a user can use the differents key protocols. //We'll be able to remove that once the editor has the capacity to update the edited keyboard's RequirementLayer. hostRequirements.PluginRequirements.AddOrSet( new Guid( "{04B1B7F5-6CD8-4691-B5FD-2C4401C3AC0C}" ), RunningRequirement.MustExistAndRun ); //IChangeKeyboardCommandHandlerService hostRequirements.PluginRequirements.AddOrSet( new Guid( "{4EDBED5A-C38E-4A94-AD34-18720B09F3B7}" ), RunningRequirement.MustExistAndRun ); //IClicCommandHandlerService hostRequirements.PluginRequirements.AddOrSet( new Guid( "{4A3F1565-E127-473c-B169-0022A3EDB58D}" ), RunningRequirement.MustExistAndRun ); //IModeCommandHandlerService hostRequirements.PluginRequirements.AddOrSet( new Guid( "{B2EC4D13-7A4F-4F9E-A713-D5F8DDD161EF}" ), RunningRequirement.MustExistAndRun ); //IMoveMouseCommandHandler ctx.PluginRunner.Add( hostRequirements ); // Load or initialize the ctx. LoadResult res = Instance.LoadContext( Assembly.GetExecutingAssembly(), "Host.Resources.Contexts.ContextCiviKey.xml" ); // Initializes Services. { ctx.ServiceContainer.Add<IHostInformation>( this ); ctx.ServiceContainer.Add<IHostHelp>( this ); // inject specific xaml serializers. ctx.ServiceContainer.Add<IStructuredSerializer<Size>>( new XamlSerializer<Size>() ); ctx.ServiceContainer.Add<IStructuredSerializer<Color>>( new XamlSerializer<Color>() ); ctx.ServiceContainer.Add<IStructuredSerializer<LinearGradientBrush>>( new XamlSerializer<LinearGradientBrush>() ); ctx.ServiceContainer.Add<IStructuredSerializer<TextDecorationCollection>>( new XamlSerializer<TextDecorationCollection>() ); ctx.ServiceContainer.Add<IStructuredSerializer<FontWeight>>( new XamlSerializer<FontWeight>() ); ctx.ServiceContainer.Add<IStructuredSerializer<FontStyle>>( new XamlSerializer<FontStyle>() ); ctx.ServiceContainer.Add<IStructuredSerializer<Image>>( new XamlSerializer<Image>() ); //ctx.ServiceContainer.Add<INotificationService>( _notificationMngr ); } Context.PluginRunner.ApplyDone += new EventHandler<ApplyDoneEventArgs>( OnApplyDone ); _firstApplySucceed = Context.PluginRunner.Apply(); ctx.ConfigManager.SystemConfiguration.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler( OnSystemConfigurationPropertyChanged ); ctx.ConfigManager.UserConfiguration.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler( OnUserConfigurationPropertyChanged ); return ctx; }
/// <summary> /// Removes one <see cref="RequirementLayer"/>. /// Use <see cref="ISimplePluginRunner.Remove(RequirementLayer,bool)"/> to force the remove regardless of the number of times it has been <see cref="ISimplePluginRunner.Add">added</see>. /// </summary> /// <param name="runner">This <see cref="ISimplePluginRunner"/>.</param> /// <param name="r">The requirements layer to remove.</param> /// <returns>True if the layer has been found, false otherwise.</returns> public static bool Remove( this ISimplePluginRunner runner, RequirementLayer r ) { return runner.Remove( r, false ); }
/// <summary> /// Adds a <see cref="RequirementLayer"/>. /// The same requirements layer can be added multiple times. /// Only the last (balanced) call to <see cref="PluginModelExtension.Remove(ISimplePluginRunner,RequirementLayer)">Remove</see> will actually remove the layer. /// </summary> /// <param name="runner">This <see cref="ISimplePluginRunner"/>.</param> /// <param name="r">The requirements layer to add.</param> public static void Add( this ISimplePluginRunner runner, RequirementLayer r ) { runner.Add( r, true ); }
public override IContext CreateContext() { //WARNING : DO NOT get information from the system configuration or the user configuration before discovering. //Getting info from these conf will trigger the LoadSystemConf or LoadUserConf, which will parse configurations set in the corresponding files. //If a system conf is found and loaded at this point, plugin will be set as disabled (because the plugins are not yet discovered). If there is a userconf, the requirements will be parsed again later, and everything will work fine. //The problem occurs when there is no user conf. (this happens when CiviKey is launched for the first time) IContext ctx = base.CreateContext(); _log.Debug( "LAUNCHING" ); _notificationMngr = new NotificationManager(); // Discover available plugins. string pluginPath = Path.Combine( Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ), "Plugins" ); _log.Debug( "Discovering plugins..." ); if( Directory.Exists( pluginPath ) ) ctx.PluginRunner.Discoverer.Discover( new DirectoryInfo( pluginPath ), true ); _log.Debug( "Plugins discovered" ); _log.Debug( String.Format( "Launching {0} > Distribution : {1} > Version : {2}, GUID : {3}", CKApp.CurrentParameters.AppName, CKApp.CurrentParameters.DistribName, AppVersion, ApplicationUniqueId.UniqueId ) ); var hostRequirements = new RequirementLayer( "CivikeyStandardHost" ); hostRequirements.PluginRequirements.AddOrSet( new Guid( "{2ed1562f-2416-45cb-9fc8-eef941e3edbc}" ), RunningRequirement.MustExistAndRun );//KeyboardContext hostRequirements.PluginRequirements.AddOrSet( new Guid( "{0F740086-85AC-46EB-87ED-12A4CA2D12D9}" ), RunningRequirement.MustExistAndRun );//SendInput hostRequirements.PluginRequirements.AddOrSet( new Guid( "{B91D6A8D-2294-4BAA-AD31-AC1F296D82C4}" ), RunningRequirement.MustExistAndRun );//Window Executor hostRequirements.PluginRequirements.AddOrSet( new Guid( "{D173E013-2491-4491-BF3E-CA2F8552B5EB}" ), RunningRequirement.MustExistAndRun );//KeyboardDisplayer //Command handlers. These plugins register their protocols onto the keyboard editor. //Therefor, we need them started in order to be able to create any type of Key Command. hostRequirements.PluginRequirements.AddOrSet( new Guid( "{664AF22C-8C0A-4112-B6AD-FB03CDDF1603}" ), RunningRequirement.MustExistAndRun );//FileLauncherCommandHandler hostRequirements.PluginRequirements.AddOrSet( new Guid( "{418F670B-46E8-4BE2-AF37-95F43040EEA6}" ), RunningRequirement.MustExistAndRun );//KeySequenceCommandHandler hostRequirements.PluginRequirements.AddOrSet( new Guid( "{78D84978-7A59-4211-BE04-DD25B5E2FDC1}" ), RunningRequirement.MustExistAndRun );//TextTemplateCommandHandler hostRequirements.PluginRequirements.AddOrSet( new Guid( "{4EDBED5A-C38E-4A94-AD34-18720B09F3B7}" ), RunningRequirement.MustExistAndRun );//ClicCommandHandler hostRequirements.PluginRequirements.AddOrSet( new Guid( "{B2EC4D13-7A4F-4F9E-A713-D5F8DDD161EF}" ), RunningRequirement.MustExistAndRun );//MoveMouseCommandHandler // ToDoJL //hostRequirements.PluginRequirements.AddOrSet( new Guid( "{DC7F6FC8-EA12-4FDF-8239-03B0B64C4EDE}" ), RunningRequirement.MustExistAndRun );//HelpUpdater hostRequirements.ServiceRequirements.AddOrSet( "Help.Services.IHelpViewerService", RunningRequirement.MustExistAndRun ); //hostRequirements.ServiceRequirements.AddOrSet( "Help.Services.IHelpUpdaterService", RunningRequirement.MustExistAndRun ); ctx.PluginRunner.Add( hostRequirements ); // Load or initialize the ctx. LoadResult res = Instance.LoadContext( Assembly.GetExecutingAssembly(), "Host.Resources.Contexts.ContextCiviKey.xml" ); _log.Debug( "Context loaded successfully." ); // Initializes Services. { ctx.ServiceContainer.Add<IHostInformation>( this ); ctx.ServiceContainer.Add<IHostHelp>( this ); ctx.ServiceContainer.Add<IContextSaver>( this ); // inject specific xaml serializers. ctx.ServiceContainer.Add<IStructuredSerializer<Size>>( new XamlSerializer<Size>() ); ctx.ServiceContainer.Add<IStructuredSerializer<Color>>( new XamlSerializer<Color>() ); ctx.ServiceContainer.Add<IStructuredSerializer<LinearGradientBrush>>( new XamlSerializer<LinearGradientBrush>() ); ctx.ServiceContainer.Add<IStructuredSerializer<TextDecorationCollection>>( new XamlSerializer<TextDecorationCollection>() ); ctx.ServiceContainer.Add<IStructuredSerializer<FontWeight>>( new XamlSerializer<FontWeight>() ); ctx.ServiceContainer.Add<IStructuredSerializer<FontStyle>>( new XamlSerializer<FontStyle>() ); ctx.ServiceContainer.Add<IStructuredSerializer<Image>>( new XamlSerializer<Image>() ); ctx.ServiceContainer.Add<IStructuredSerializer<BitmapSource>>( new BitmapSourceSerializer<BitmapSource>() ); ctx.ServiceContainer.Add<IStructuredSerializer<InteropBitmap>>( new BitmapSourceSerializer<InteropBitmap>() ); ctx.ServiceContainer.Add<IStructuredSerializer<CachedBitmap>>( new BitmapSourceSerializer<CachedBitmap>() ); ctx.ServiceContainer.Add<IStructuredSerializer<BitmapFrame>>( new BitmapSourceSerializer<BitmapFrame>() ); ctx.ServiceContainer.Add<IStructuredSerializer<BitmapImage>>( new BitmapSourceSerializer<BitmapImage>() ); //ctx.ServiceContainer.Add<INotificationService>( _notificationMngr ); } Context.PluginRunner.ApplyDone += OnApplyDone; _log.Debug( "Starting Apply..." ); _firstApplySucceed = Context.PluginRunner.Apply(); ctx.ConfigManager.SystemConfiguration.PropertyChanged += OnSystemConfigurationPropertyChanged; ctx.ConfigManager.UserConfiguration.PropertyChanged += OnUserConfigurationPropertyChanged; return ctx; }
public void RequirementLayerService_AddFilled() { TestBase.CopyPluginToTestDir( "ServiceA.dll" ); PluginRunner.Discoverer.Discover( TestBase.TestFolderDir, true ); RequirementLayer layer = new RequirementLayer( "MyLayer" ); layer.ServiceRequirements.AddOrSet( "CK.Tests.Plugin.IServiceA, ServiceA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", RunningRequirement.MustExistAndRun ); PluginRunner.Add( layer ); Assert.That( PluginRunner.IsDirty, "Should be dirty" ); }
public void RequirementLayersEvents() { RequirementLayer layer = new RequirementLayer( "Layer" ); PluginRequirementCollectionEvents( layer.PluginRequirements as PluginRequirementCollection ); ServiceRequirementCollectionEvents( layer.ServiceRequirements as ServiceRequirementCollection ); }
/// <summary> /// Removes one <see cref="RequirementLayer"/>. /// Use <see cref="ISimplePluginRunner.Remove(RequirementLayer,bool)"/> to force the remove regardless of the number of times it has been <see cref="ISimplePluginRunner.Add">added</see>. /// </summary> /// <param name="runner">This <see cref="ISimplePluginRunner"/>.</param> /// <param name="r">The requirements layer to remove.</param> /// <returns>True if the layer has been found, false otherwise.</returns> public static bool Remove(this ISimplePluginRunner runner, RequirementLayer r) { return(runner.Remove(r, false)); }
/// <summary> /// Adds a <see cref="RequirementLayer"/>. /// The same requirements layer can be added multiple times. /// Only the last (balanced) call to <see cref="PluginModelExtension.Remove(ISimplePluginRunner,RequirementLayer)">Remove</see> will actually remove the layer. /// </summary> /// <param name="runner">This <see cref="ISimplePluginRunner"/>.</param> /// <param name="r">The requirements layer to add.</param> public static void Add(this ISimplePluginRunner runner, RequirementLayer r) { runner.Add(r, true); }
public void RequirementLayerOptionals() { Guid id_plugin1 = new Guid( "{12A9FCC0-ECDC-4049-8DBF-8961E49A9EDE}" ); Guid id_plugin2 = new Guid( "{E64F17D5-DCAB-4A07-8CEE-901A87D8295E}" ); TestBase.CopyPluginToTestDir( "ServiceA.dll" ); TestBase.CopyPluginToTestDir( "ServiceB.dll" ); PluginRunner.Discoverer.Discover( TestBase.TestFolderDir, true ); RequirementLayer layer = new RequirementLayer( "MyLayer" ); PluginRunner.Add( layer ); Assert.That( !PluginRunner.IsDirty, "Not dirty because the layer is empty" ); layer.PluginRequirements.AddOrSet( id_plugin1, RunningRequirement.Optional ); layer.PluginRequirements.AddOrSet( id_plugin2, RunningRequirement.Optional ); Assert.That( !PluginRunner.IsDirty, "Not dirty because plugin's are optional ... so we have nothing to change." ); Assert.IsTrue( PluginRunner.Remove( layer ) ); Assert.That( PluginRunner.RunnerRequirements.Count, Is.EqualTo( 0 ) ); Assert.That( !PluginRunner.IsDirty, "Not dirty because the PluginRunner doesn't contains any requirement" ); }
/// <summary> /// Reads back an existing <see cref="RequirementLayer"/> or creates a new one /// from xml data previously written by <see cref="WriteInlineToXml"/> method. /// </summary> /// <param name="r">The xml stream to read: the reader must be on an opened element.</param> /// <param name="reqLayer">An existing layer or null to create a new one.</param> public static void ReadInlineFromXml(XmlReader r, ref RequirementLayer reqLayer) { if (reqLayer != null) { reqLayer.LayerName = r.GetAttribute("Name"); } else { reqLayer = new RequirementLayer(r.GetAttribute("Name")); } r.Read(); if (r.IsStartElement("PluginRequirements")) { if (r.IsEmptyElement) { r.Read(); } else { r.Read(); reqLayer.PluginRequirements.Clear(); while (r.IsStartElement("PluginRequirement")) { Guid pluginId = new Guid(r.GetAttribute("PluginId")); RunningRequirement runningReq = (RunningRequirement)Enum.Parse(typeof(RunningRequirement), r.GetAttribute("Requirement")); reqLayer.PluginRequirements.AddOrSet(pluginId, runningReq); if (r.IsEmptyElement) { r.Read(); } else { r.Skip(); } } r.ReadEndElement(); } } if (r.IsStartElement("ServiceRequirements")) { if (r.IsEmptyElement) { r.Read(); } else { r.Read(); reqLayer.ServiceRequirements.Clear(); while (r.IsStartElement("ServiceRequirement")) { string assemblyQualifiedName = r.GetAttribute("AssemblyQualifiedName"); RunningRequirement runningReq = (RunningRequirement)Enum.Parse(typeof(RunningRequirement), r.GetAttribute("Requirement")); reqLayer.ServiceRequirements.AddOrSet(assemblyQualifiedName, runningReq); if (r.IsEmptyElement) { r.Read(); } else { r.Skip(); } } r.ReadEndElement(); } } }
public void RequirementLayerUnknownService() { PluginRunner.Discoverer.Discover( TestBase.TestFolderDir, true ); RequirementLayer layer = new RequirementLayer( "MyLayer" ); PluginRunner.Add( layer ); Assert.That( !PluginRunner.IsDirty, "Not dirty because the layer is empty" ); layer.ServiceRequirements.AddOrSet( "UnknownAQN!", RunningRequirement.Optional ); Assert.That( !PluginRunner.IsDirty, "Should not be dirty because the service is unknown and the requirement is optional" ); }