public void Close()
 {
     if (this.startupInstance != null)
     {
         try
         {
             this.startupInstance.Shutdown();
             this.startupInstance = null;
         }
         catch (Exception exception)
         {
             throw new JSVsaException(JSVsaError.EngineCannotReset, exception.ToString(), exception);
         }
     }
     this.engine.Close();
 }
 public virtual void Run()
 {
     this.TryObtainLock();
     try
     {
         this.Preconditions(Pre.SiteSet | Pre.RootNamespaceSet | Pre.RootMonikerSet | Pre.EngineNotRunning | Pre.EngineNotClosed);
         System.AppDomain currentDomain = System.AppDomain.CurrentDomain;
         if (this.haveCompiledState)
         {
             if (this.rootNamespace != this.compiledRootNamespace)
             {
                 throw new JSVsaException(JSVsaError.RootNamespaceInvalid);
             }
             this.loadedAssembly = this.LoadCompiledState();
             currentDomain.SetData(this.engineMoniker, this.loadedAssembly);
         }
         else
         {
             if (this.failedCompilation)
             {
                 throw new JSVsaException(JSVsaError.EngineNotCompiled);
             }
             this.startupClass   = null;
             this.loadedAssembly = currentDomain.GetData(this.engineMoniker) as System.Reflection.Assembly;
             if (this.loadedAssembly == null)
             {
                 string name  = this.engineMoniker + "/" + currentDomain.GetHashCode().ToString(CultureInfo.InvariantCulture);
                 Mutex  mutex = new Mutex(false, name);
                 if (mutex.WaitOne())
                 {
                     try
                     {
                         this.loadedAssembly = currentDomain.GetData(this.engineMoniker) as System.Reflection.Assembly;
                         if (this.loadedAssembly == null)
                         {
                             byte[] buffer;
                             byte[] buffer2;
                             this.engineSite.GetCompiledState(out buffer, out buffer2);
                             if (buffer == null)
                             {
                                 throw new JSVsaException(JSVsaError.GetCompiledStateFailed);
                             }
                             this.loadedAssembly = System.Reflection.Assembly.Load(buffer, buffer2, this.executionEvidence);
                             currentDomain.SetData(this.engineMoniker, this.loadedAssembly);
                         }
                     }
                     finally
                     {
                         mutex.ReleaseMutex();
                         mutex.Close();
                     }
                 }
             }
         }
         try
         {
             if (this.startupClass == null)
             {
                 this.startupClass = this.loadedAssembly.GetType(this.rootNamespace + "._Startup", true);
             }
         }
         catch (Exception exception)
         {
             throw new JSVsaException(JSVsaError.BadAssembly, exception.ToString(), exception);
         }
         try
         {
             this.startupInstance = (BaseVsaStartup)Activator.CreateInstance(this.startupClass);
             this.isEngineRunning = true;
             this.startupInstance.SetSite(this.engineSite);
             this.startupInstance.Startup();
         }
         catch (Exception exception2)
         {
             throw new JSVsaException(JSVsaError.UnknownError, exception2.ToString(), exception2);
         }
     }
     finally
     {
         this.ReleaseLock();
     }
 }
 private bool LoadAssembly(byte[] pe, byte[] pdb)
 {
     try
     {
         Assembly assembly = Assembly.Load(pe, pdb, SecurityContextSource.CurrentAppDomain);
         Type type = assembly.GetType(this.engine.RootNamespace + "._Startup");
         this.startupInstance = (BaseVsaStartup) Activator.CreateInstance(type);
         this.startupInstance.SetSite(this.engine.Site);
         this.startupInstance.Startup();
         Type type2 = assembly.GetType(this.engine.RootNamespace + ".__WebProxyScript");
         this.scriptInstance = Activator.CreateInstance(type2);
         CallMethod(this.scriptInstance, "SetEngine", new object[] { this.engine });
     }
     catch
     {
         return false;
     }
     return true;
 }
 public virtual void Run()
 {
     this.TryObtainLock();
     try
     {
         this.Preconditions(Pre.SiteSet | Pre.RootNamespaceSet | Pre.RootMonikerSet | Pre.EngineNotRunning | Pre.EngineNotClosed);
         System.AppDomain currentDomain = System.AppDomain.CurrentDomain;
         if (this.haveCompiledState)
         {
             if (this.rootNamespace != this.compiledRootNamespace)
             {
                 throw new JSVsaException(JSVsaError.RootNamespaceInvalid);
             }
             this.loadedAssembly = this.LoadCompiledState();
             currentDomain.SetData(this.engineMoniker, this.loadedAssembly);
         }
         else
         {
             if (this.failedCompilation)
             {
                 throw new JSVsaException(JSVsaError.EngineNotCompiled);
             }
             this.startupClass = null;
             this.loadedAssembly = currentDomain.GetData(this.engineMoniker) as System.Reflection.Assembly;
             if (this.loadedAssembly == null)
             {
                 string name = this.engineMoniker + "/" + currentDomain.GetHashCode().ToString(CultureInfo.InvariantCulture);
                 Mutex mutex = new Mutex(false, name);
                 if (mutex.WaitOne())
                 {
                     try
                     {
                         this.loadedAssembly = currentDomain.GetData(this.engineMoniker) as System.Reflection.Assembly;
                         if (this.loadedAssembly == null)
                         {
                             byte[] buffer;
                             byte[] buffer2;
                             this.engineSite.GetCompiledState(out buffer, out buffer2);
                             if (buffer == null)
                             {
                                 throw new JSVsaException(JSVsaError.GetCompiledStateFailed);
                             }
                             this.loadedAssembly = System.Reflection.Assembly.Load(buffer, buffer2, this.executionEvidence);
                             currentDomain.SetData(this.engineMoniker, this.loadedAssembly);
                         }
                     }
                     finally
                     {
                         mutex.ReleaseMutex();
                         mutex.Close();
                     }
                 }
             }
         }
         try
         {
             if (this.startupClass == null)
             {
                 this.startupClass = this.loadedAssembly.GetType(this.rootNamespace + "._Startup", true);
             }
         }
         catch (Exception exception)
         {
             throw new JSVsaException(JSVsaError.BadAssembly, exception.ToString(), exception);
         }
         try
         {
             this.startupInstance = (BaseVsaStartup) Activator.CreateInstance(this.startupClass);
             this.isEngineRunning = true;
             this.startupInstance.SetSite(this.engineSite);
             this.startupInstance.Startup();
         }
         catch (Exception exception2)
         {
             throw new JSVsaException(JSVsaError.UnknownError, exception2.ToString(), exception2);
         }
     }
     finally
     {
         this.ReleaseLock();
     }
 }