/// <summary> /// Ctor to use in simple cases /// </summary> /// <param name="runner">The runner</param> /// <param name="userConfig">The user configuration</param> /// <param name="pluginIds">The pluginIds of those that should be started and stopped when the cluster is started or stopped. /// The first one is considered the "main" (note this has no impact on the way start/stop are handled)</param> public PluginCluster( ISimplePluginRunner runner, IUserConfiguration userConfig, params Guid[] pluginIds ) { if( pluginIds.Length == 0 ) throw new ArgumentException( "A PluginCluster cannot be created without pluginIds. It need at least one" ); _mainPluginId = pluginIds[0]; List<Guid> plugins = pluginIds.ToList(); _startWithPlugin = plugins; _stopWithPlugin = plugins; _runner = runner; _userConfig = userConfig; }
/// <summary> /// Ctor to use when the plugins that should be started together with the main plugin are different from those that should be stopped together with the main plugin. /// </summary> /// <param name="runner">The runner</param> /// <param name="userConfig">The user configuration</param> /// <param name="mainPluginId">The Guid of the main plugin</param> /// <param name="startWithPlugin">The plugins to start together with the main plugin</param> /// <param name="stopWithPlugin">The plugins to stop together with the main plugin</param> public PluginCluster( ISimplePluginRunner runner, IUserConfiguration userConfig, Guid mainPluginId, IEnumerable<Guid> startWithPlugin, IEnumerable<Guid> stopWithPlugin ) { _mainPluginId = mainPluginId; _startWithPlugin = new List<Guid>(); _startWithPlugin.Add( mainPluginId ); _startWithPlugin.AddRange( startWithPlugin ); _stopWithPlugin = new List<Guid>(); _stopWithPlugin.Add( mainPluginId ); _stopWithPlugin.AddRange( stopWithPlugin ); _runner = runner; _userConfig = userConfig; }
public ConfigFeatureStarter( ConfigManager configManager, ISimplePluginRunner runner, PluginCluster pluginCluster ) : base(configManager) { _pluginCluster = pluginCluster; _runner = runner; _runner.PluginHost.StatusChanged += ( o, e ) => { if( _pluginCluster.StartWithPlugin.Contains( e.PluginProxy.PluginKey.PluginId ) || _pluginCluster.StopWithPlugin.Contains( e.PluginProxy.PluginKey.PluginId ) ) { NotifyOfPropertyChange( () => Start ); NotifyOfPropertyChange( () => Stop ); NotifyOfPropertyChange( () => IsRunning ); NotifyOfPropertyChange( () => IsRunnable ); } }; Start = new SimpleCommand( StartPlugin, CanStart ); Stop = new SimpleCommand( StopPlugin ); }
/// <summary> /// Ctor of a ConfigFeatureStarter. /// Be careful with the list of Guid passed as parameter. /// When stopped, ALL these plugins' user configuration will be set to Manual and receive a "Stop" LiveUserAction. /// Plugins that are used by other plugins/feature must not be added in this list. (use service requirements in the plugins when possible) /// </summary> /// <param name="configManager"></param> /// <param name="runner"></param> /// <param name="userConfig"></param> /// <param name="mainPluginIds"></param> public ConfigFeatureStarter( ConfigManager configManager, ISimplePluginRunner runner, IUserConfiguration userConfig, params Guid[] mainPluginIds ) : base(configManager) { _pluginIds = mainPluginIds; _runner = runner; _userConfig = userConfig; _runner.PluginHost.StatusChanged += ( o, e ) => { if( _pluginIds.Contains( e.PluginProxy.PluginKey.PluginId ) ) { NotifyOfPropertyChange( () => Start ); NotifyOfPropertyChange( () => Stop ); NotifyOfPropertyChange( () => IsRunning ); NotifyOfPropertyChange( () => IsRunnable ); } }; Start = new SimpleCommand( StartPlugin, CanStart ); Stop = new SimpleCommand( StopPlugin ); }
/// <summary> /// Initializes a new <see cref="IContext"/>: one and only one context can be created by a host. /// Context events are associated to the abstract methods <see cref="LoadSystemConfig"/>/<see cref="SaveSystemConfig"/>, /// <see cref="LoadUserConfig"/>/<see cref="SaveUserConfig"/> and <see cref="SaveContext"/>: it is up to this host to provide /// actual System and User configuration. /// </summary> /// <returns>A new context.</returns> public virtual IContext CreateContext() { if (Context != null) { throw new InvalidOperationException(Res.R.HostAlreadyOwnsContext); } _ctx = CK.Context.Context.CreateInstance(); IConfigManagerExtended cfg = _ctx.ConfigManager.Extended; cfg.LoadSystemConfigRequired += (o, e) => LoadSystemConfig(); cfg.LoadUserConfigRequired += (o, e) => LoadUserConfig(); ISimplePluginRunner runner = _ctx.PluginRunner; runner.ServiceHost.DefaultConfiguration.SetAllEventsConfiguration(typeof(IContext), ServiceLogEventOptions.LogErrors | ServiceLogEventOptions.SilentEventError); runner.ServiceHost.ApplyConfiguration(); 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); }