Example #1
0
        public SystemsManager( IPluginManager pluginManager, ILogManager logManager, INGinCore core, IMainLoopManager mainLoopManager )
        {
            this.LogManager = logManager;

            foreach ( SystemAttribute plugin in pluginManager.GetPluginsForType( typeof( SystemAttribute ) ) )
            {
                // create and store system
                //ConstructorInfo constructor = plugin.SystemType.GetConstructor( plugin.ConstructorParameterTypes );
                //ISystem system = plugin.SystemType.InvokeMember( plugin.SystemType.Name, global::System.Reflection.BindingFlags.CreateInstance, null, null, new object[] { this.LogManager } ) as ISystem;
                ISystem system = core.GetService( plugin.SystemType ) as ISystem;

                lock ( this.registeredSystemsLock )
                {
                    this.registeredSystems.Add( system.Name, system );
                }
            }
        }
Example #2
0
        internal StateManager( ILogManager logManager, IPluginManager pluginManager, IMachine stateMachine, INGinCore core )
        {
            if ( logManager == null )
            {
                string message = "The log manager must not be null.";
                ArgumentNullException argnEx = new ArgumentNullException( "logManager", message );
                throw argnEx;
            }

            if ( pluginManager == null )
            {
                string message = "The plugin manager must not be null.";
                ArgumentNullException argnEx = new ArgumentNullException( "pluginManager", message );
                logManager.Trace( Namespace.LoggerName, LogLevel.Error, argnEx, message );
                throw argnEx;
            }

            if ( stateMachine == null )
            {
                string message = "The state machine must not be null.";
                ArgumentNullException argnEx = new ArgumentNullException( "stateMachine", message );
                logManager.Trace( Namespace.LoggerName, LogLevel.Error, argnEx, message );
                throw argnEx;
            }

            if ( core == null )
            {
                string message = "The core must not be null.";
                ArgumentNullException argnEx = new ArgumentNullException( "core", message );
                logManager.Trace( Namespace.LoggerName, LogLevel.Error, argnEx, message );
                throw argnEx;
            }

            this.LogManager = logManager;
            this.PluginManager = pluginManager;
            this.StateMachine = stateMachine;
            this.Core = core;

            this.Core.RunStarted += new CoreStateDelegate( this.Core_RunStarted );
            this.Core.RunStopped += new CoreStateDelegate( this.Core_RunStopped );
        }
Example #3
0
 public PerformanceTestRunner( INGinCore core, ILogManager logManager, ISystemsManager systemsManager )
 {
     this.Core = core;
     this.LogManager = logManager;
     this.SystemsManager = systemsManager;
 }
Example #4
0
 public StateManager( ILogManager logManager, IPluginManager pluginManager, INGinCore core )
     : this(logManager, pluginManager, new Machine( logManager ), core)
 {
 }
Example #5
0
 void Core_RunStopped( INGinCore senderCore )
 {
     this.Shutdown( false );
 }
Example #6
0
 void Core_RunStarted( INGinCore senderCore )
 {
     this.Initialize( this.PluginManager, this.StateMachine, this.Core );
 }
Example #7
0
        internal void Initialize( IPluginManager pluginManager, IMachine stateMachine, INGinCore core )
        {
            // ensure plugin manager is not null
            if ( pluginManager == null )
            {
                string message = "The plugin manager must not be null.";
                ArgumentNullException argnEx = new ArgumentNullException( "logManager", message );
                this.LogManager.Trace( Namespace.LoggerName, LogLevel.Error, argnEx, message );
                throw argnEx;
            }

            // ensure state machine is not null
            if ( stateMachine == null )
            {
                string message = "The state machine must not be null.";
                ArgumentNullException argnEx = new ArgumentNullException( "stateMachine", message );
                this.LogManager.Trace( Namespace.LoggerName, LogLevel.Error, argnEx, message );
                throw argnEx;
            }

            if ( core == null )
            {
                string message = "The core must not be null.";
                ArgumentNullException argnEx = new ArgumentNullException( "core", message );
                this.LogManager.Trace( Namespace.LoggerName, LogLevel.Error, argnEx, message );
                throw argnEx;
            }

            IEnumerable<Attribute> statePlugins = pluginManager.GetPluginsForType( typeof( NGinRootStateAttribute ) );

            // ensure that only one root state is defined
            if ( statePlugins.Count<Attribute>() > 1 )
            {
                string message = "More than one root state plugin was found. There must be only 1.";
                InvalidOperationException invOpEx = new InvalidOperationException( message );
                this.LogManager.Trace( Namespace.LoggerName, LogLevel.Error, invOpEx, message );
                throw invOpEx;
            }

            // get attribute
            NGinRootStateAttribute rootStateAtt = statePlugins.ElementAt<Attribute>( 0 ) as NGinRootStateAttribute;

            // make sure attribute is not null
            if ( rootStateAtt == null )
            {
                string message = "Error loading the root state plugin.";
                InvalidOperationException invOpEx = new InvalidOperationException( message );
                this.LogManager.Trace( Namespace.LoggerName, LogLevel.Error, invOpEx, message );
                throw invOpEx;
            }

            // add type to machine root
            Type rootStateType = rootStateAtt.RootStateType;
            IState state = core.GetService( rootStateType ) as IState;

            if ( state == null )
            {
                string message = String.Format( System.Globalization.CultureInfo.InvariantCulture, "An error occurred while retrieving instance of {0}.", rootStateType.FullName );
                InvalidOperationException invopEx = new InvalidOperationException( message );
                this.LogManager.Trace( Namespace.LoggerName, LogLevel.Error, invopEx, message );
                throw invopEx;
            }

            this.StateMachine.RootState.AddSubState( state );

            stateMachine.Initialize( state.Name );
        }