Ejemplo n.º 1
0
 public IYodiiEngineResult Stop( string callerKey )
 {
     if( !_capability.CanStop )
     {
         throw new InvalidOperationException( "You must call Capability.CanStop and ensure that it returns true before calling Stop." );
     }
     YodiiCommand command = new YodiiCommand( false, _fullName, IsPlugin, StartDependencyImpact.Unknown, callerKey );
     return _engine.AddYodiiCommand( command );
 }
Ejemplo n.º 2
0
 bool ApplyAndTellMeIfCommandMustBeKept( YodiiCommand cmd )
 {
     if( cmd.ServiceFullName != null )
     {
         // If the service does not exist, we keep the command.
         ServiceData s;
         if( _services.TryGetValue( cmd.ServiceFullName, out s ) )
         {
             if ( cmd.Start ) return s.DynamicStartByCommand( cmd.Impact );
             return s.DynamicStopByCommand();
         }
         return true;
     }
     // Starts or stops the plugin.
     // If the plugin does not exist, we keep the command.
     PluginData p;
     if( _plugins.TryGetValue(cmd.PluginFullName, out p) )
     {
         if ( cmd.Start ) return p.DynamicStartByCommand( cmd.Impact );
         else return p.DynamicStopByCommand();
     }
     return true;
 }
Ejemplo n.º 3
0
 public IYodiiEngineResult Start( string callerKey, StartDependencyImpact impact = StartDependencyImpact.Unknown )
 {
     if( !_capability.CanStartWith( impact ) )
     {
         throw new InvalidOperationException( "You must call Capability.CanStart with the wanted impact and ensure that it returns true before calling Start." );
     }
     YodiiCommand command = new YodiiCommand( true, _fullName, IsPlugin, impact, callerKey );
     return _engine.AddYodiiCommand( command );
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Solves undetermined status based on commands.
        /// </summary>
        /// <param name="commands"></param>
        /// <returns>This method returns a Tuple <IEnumerable<IPluginInfo>,IEnumerable<IPluginInfo>,IEnumerable<IPluginInfo>> to the host.
        /// Plugins are either disabled, stopped (but can be started) or running (locked or not).</returns>
        internal DynamicSolverResult DynamicResolution( IEnumerable<YodiiCommand> pastCommands, YodiiCommand newOne = null )
        {
            foreach( var f in _serviceFamilies ) f.DynamicResetState();
            foreach( var p in _plugins.Values ) p.DynamicResetState();
            foreach( var f in _serviceFamilies )
            {
                Debug.Assert( !f.Root.Disabled || f.Root.FindFirstPluginData( p => !p.Disabled ) == null );
                f.DynamicOnAllPluginsStateInitialized();
            }
            List<YodiiCommand> commands = new List<YodiiCommand>();
            if( newOne != null )
            {
                bool alwaysTrue = ApplyAndTellMeIfCommandMustBeKept( newOne );
                Debug.Assert( alwaysTrue, "The newly added command is necessarily okay." );
                commands.Add( newOne );
            }

            foreach( var previous in pastCommands )
            {
                if( newOne == null || newOne.ServiceFullName != previous.ServiceFullName || newOne.PluginFullName != previous.PluginFullName )
                {
                    if( ApplyAndTellMeIfCommandMustBeKept( previous ) )
                    {
                        commands.Add( previous );
                    }
                }
            }
            foreach( var f in _serviceFamilies )
            {
                Debug.Assert( !f.Root.Disabled || f.Root.FindFirstPluginData( p => !p.Disabled ) == null, "All plugins must be disabled." );
                if( !f.Root.Disabled ) f.DynamicFinalDecision( true );
            }
            foreach( var f in _serviceFamilies )
            {
                Debug.Assert( !f.Root.Disabled || f.Root.FindFirstPluginData( p => !p.Disabled ) == null, "All plugins must be disabled." );
                if( !f.Root.Disabled ) f.DynamicFinalDecision( false );
            }

            List<IPluginInfo> disabled = new List<IPluginInfo>();
            List<IPluginInfo> stopped = new List<IPluginInfo>();
            List<IPluginInfo> running = new List<IPluginInfo>();

            foreach( var p in _plugins.Values )
            {
                if( p.DynamicStatus != null )
                {
                    if( p.DynamicStatus.Value == RunningStatus.Disabled ) disabled.Add( p.PluginInfo );
                    else if( p.DynamicStatus.Value == RunningStatus.Stopped ) stopped.Add( p.PluginInfo );
                    else running.Add( p.PluginInfo );
                }
                else
                {
                    Debug.Assert( p.Service == null );
                    p.DynamicStopBy( PluginRunningStatusReason.StoppedByFinalDecision );
                    stopped.Add( p.PluginInfo );
                }
            }
            return new DynamicSolverResult( disabled.AsReadOnlyList(), stopped.AsReadOnlyList(), running.AsReadOnlyList(), commands.AsReadOnlyList() );
        }