Esempio n. 1
0
			/////////////////////////////////////////////////////////////////////////////

			public NmpMakeCurrent( NMP nmp )
			{
				// ******
				this.nmp = nmp;	// as NMP;

				//System.Diagnostics.Trace.Assert( null != this.nmp, "NmpMakeCurrent was passed an invalid NMP instance" );

				// ******
				MakeCurrent();
			}
Esempio n. 2
0
		/////////////////////////////////////////////////////////////////////////////

		public EvaluateFromFileContext( NMP nmp, string fullFilePath )
		{
			// ******
			if( ! File.Exists(fullFilePath) ) {
				throw new FileNotFoundException( fullFilePath );
			}

			// ******
			FromFile = true;
			SetFileInfo( fullFilePath );
			
			// ******
			//Text = File.ReadAllText( fullFilePath );
			Text = nmp.GrandCentral.ReadFile( fullFilePath );
		}
Esempio n. 3
0
			/////////////////////////////////////////////////////////////////////////////

			public EvalLock( NMP nmp )
			{
				// ******
				this.nmp = nmp;

				// ******
				object threadContext = ThreadContext.GetThreadStorage();
				System.Diagnostics.Trace.Assert( null != threadContext, "EvalLock: thread context is null" );
				System.Diagnostics.Trace.Assert( threadContext == nmp.threadContext, "EvalLock: the current thread context is not equal to the required thread context" );

				// ******
				if( nmp.inEval ) {
					throw new Exception( "Nmp: evaluation already in progress, Nmp is not reentrant" );
				}
				
				// ******
				nmp.inEval = true;
				//nmp.RestoreEnvironment();
			}
Esempio n. 4
0
//		/////////////////////////////////////////////////////////////////////////////
//		
//		public static void RegisterMacros( IMacroProcessor mp, string fullPath, bool displayFound )
//		{
//			// ******
//			Assembly asm = null;
//
//			// ******
//			try {
//				asm = Assembly.LoadFrom( fullPath );
//			}
//			catch ( Exception ex ) {
//				throw new Exception( string.Format("unable to load library \"{0}\": {1}", fullPath, ex.Message) );
//			}
//			
//			// ******
//			//
//			// register macros
//			//
//			RegisterMacroContainers( mp, asm, displayFound );
//
//			if( ! RegisterMacros(mp, asm, displayFound) ) {
//				throw new Exception( string.Format("unable to locate any macros in plugin library \"{0}\"", asm.FullName) );
//			}
//		}
//
//
//		///////////////////////////////////////////////////////////////////////////
//		
//		public static bool RegisterMacros( IMacroProcessor mp, Assembly asm, bool displayFound )
//		{
//		int	countRegistered = 0;
//		
//			// ******
//			//
//			// only public types
//			// 
//			Type [] types = asm.GetExportedTypes();
//			
//			foreach( Type type in types ) {
//				if( null != type.GetInterface("IMacroLoader") ) {
//					object typeInstance = null;
//
//					// ******
//					try {																																 
//						//
//						// first try creating with a ctor that takes an IMacroProcessor 
//						// parameter
//						//
//						typeInstance = Activator.CreateInstance( type, new object [] { mp } );
//					}
//					catch {
//					}
//
//					if( null == typeInstance ) {
//						try {																																 
//							//
//							// default constructor
//							//
//							typeInstance = Activator.CreateInstance( type );
//						}
//						catch {
//						}
//					}
//
//					if( null == typeInstance ) {
//						throw new Exception( string.Format("unable to create instance of \"{0}\" while trying to load macros from library: \"{1}\"", type.FullName, asm.CodeBase) );
//					}
//
//					// ******
//					IMacroLoader loader = typeInstance as IMacroLoader;
//					if( null == loader ) {
//						throw new Exception( string.Format("unable to cast instance of \"{0}\" to IMacroLoader while trying to load macros from library: \"{1}\"", type.FullName, asm.CodeBase) );
//					}
//
//					// ******
//					if( displayFound ) {
//						ThreadContext.WriteMessage( "calling LoadMacros() on \"{0}\"", type.FullName );
//					}
//
//					// ******
//					string objectMacroName = loader.ObjectMacroName;
//					if( ! string.IsNullOrEmpty(objectMacroName) ) {
//						mp.AddObjectMacro( objectMacroName, typeInstance );
//					}
//
//					// ******
//					countRegistered += loader.LoadMacros( mp, displayFound );
//				}
//			}
//			
//			// ******
//			if( displayFound ) {
//				ThreadContext.WriteMessage( string.Empty );
//			}
//			
//			// ******
//			return countRegistered > 0;
//		}
	
	
		/////////////////////////////////////////////////////////////////////////////
		//
		//public static int _RegisterMacros( IMacroProcessor mp, Type type, bool displayFound )
		//{
		//int	countRegistered = 0;
		//
		//	// ******
		//	object typeInstance = null;
		//
		//	// ******
		//	MethodInfo [] methods = type.GetMethods();
		//	foreach( MethodInfo info in methods ) {
		//		if( info.IsStatic ) {
		//			continue;
		//		}
		//		
		//		// ******
		//		if( typeof(object) == info.ReturnType ) {
		//			ParameterInfo [] pi = info.GetParameters();
		//			
		//			if( 3 == pi.Length ) {
		//				if( typeof(IMacroProcessor) == pi[0].ParameterType && typeof(IMacro) == pi[1].ParameterType && typeof(ArgumentList) == pi[2].ParameterType ) {
		//					if( displayFound ) {
		//						ThreadContext.WriteMessage( "adding macro: {0}", info.Name );
		//					}
		//					
		//					// ******
		//					if( null == typeInstance ) {
		//						try {
		//							typeInstance = Activator.CreateInstance( type );
		//						}
		//						catch ( Exception e ) {
		//							throw new Exception( string.Format("while attempting create instance of \"{0}\"", type.Name), e );
		//						}
		//						
		//					}
		//
		//					// ******
		//					Delegate macroDelegate= Delegate.CreateDelegate( typeof(MacroCall), typeInstance, info );
		//					if( null != macroDelegate ) {
		//						
		//						// NewBuiltinMacro( string name, IMacroHandler mh, MacroCall method )
		//						
		//						//mp.NewBuiltinMacro( info.Name, (MacroCall) macroDelegate, 0 );
		//						
		//							//mp.NewBuiltinMacro( info.Name, , (MacroCall) macroDelegate );
		//
		//
		//
		//						++countRegistered;
		//					}
		//					
		//				}
		//			}
		//		}
		//	}
		//		
		//	// ******
		//	return countRegistered;
		//}
		//
	
		///////////////////////////////////////////////////////////////////////////

		public void Register( NMP nmp, IMacroProcessor mp )
		{
		}
Esempio n. 5
0
		/////////////////////////////////////////////////////////////////////////////

		public bool Initialize( INmpHost host )
		{
			//
			// if null == host then create a reporting host
			//

			nmp = new NMP( host );
			return null != nmp;
		}
Esempio n. 6
0
		/////////////////////////////////////////////////////////////////////////////

		public EvaluateStringContext( NMP nmp, string text )
		{
			Text = nmp.GrandCentral.FixText( text );
		}
Esempio n. 7
0
			/////////////////////////////////////////////////////////////////////////////
		
			public void Dispose()
			{
				ThreadContext.SetThreadStorage( savedState );
				nmp = null;
				savedState = null;
			}