Exemplo n.º 1
0
 static Engine()
 {
     DirectoryInfo rundir = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory;
     List<Engine> engines = new List<Engine>();
     foreach(FileInfo fi in rundir.GetFiles("*.dll")) {
         try {
             Assembly assy = Assembly.LoadFrom(fi.FullName);
             foreach(Type t in assy.GetExportedTypes()) {
                 if(!t.IsAbstract && typeof(Engine).IsAssignableFrom(t)) {
                     Engine e = (Engine) Activator.CreateInstance(t);
                     if(e.Exists) engines.Add(e);
                 }
             }
         } catch (BadImageFormatException) {
             // do nothing. The dll isn't in the right format, so we'll ignore it.
         } catch (FileLoadException) {
             // do nothing. We tried to load the same assembly twice or the assembly name was longer than MAX_PATH characters.
             // In either case, we can't do anything with it.
         } catch (System.Reflection.ReflectionTypeLoadException) {
             // ignore ReflectionTypeLoadException
         } catch (TypeLoadException) {
             // ignore
         } catch (Exception e) {
             throw new ApplicationException("Could not load math engine plugin " + fi.Name + ":\n\n" + e.Message, e);
         }
     }
     engines.Sort(delegate(Engine a, Engine b) { return a.Name.CompareTo(b.Name); });
     _engines = engines.ToArray();
     Trace.Assert(_engines.Length > 0);
     int ix = 0;
     for(int i = 0; i < _engines.Length; i++) {
         if (_engines[i] is BuiltInEngine) {
         //if(_engines[i] is MMAEngine) {
             ix = i;
             break;
         }
     }
     _current = _engines[ix];
 }
Exemplo n.º 2
0
 private static void PushEngine(Engine e)
 {
     _engineStack.Push(_current);
     _current = e;
     _current.Activate();
 }
Exemplo n.º 3
0
 private static void PopEngine()
 {
     if(_engineStack.Count != 0) {
         _current.Deactivate();
         _current = _engineStack.Pop();
     }
 }