using System; using System.Collections.Generic; using System.Text; using System.Security; using System.Security.Permissions; using System.Security.Policy; using System.Reflection; using System.IO; using System.Diagnostics; using System.Collections.Specialized; namespace CSTextEditor { public class CompilerCode { public String text; public string[] references; public CompilerCode(String code) { this.text = code; references = new string[] { "System.dll", "System.Windows.Forms.dll" }; } public CompilerCode() { } private Assembly cachedScriptAssembly = null; public void Compile(CompilerOutputDelegate cod) { try { cachedScriptAssembly = Compiler.DefaultCompiler.Compile(this, cod).CompiledAssembly; } catch (System.IO.FileNotFoundException exp) { throw new Exception("Unable to load script assembly (probably a complier error, check debug output)", exp); } } public void Run(CompilerOutputDelegate cod, object subject, object[] parameters, PermissionSet permissionSet) { if (cachedScriptAssembly == null) { // compile if necessary cachedScriptAssembly = Compiler.DefaultCompiler.Compile(this, cod).CompiledAssembly; } if (cachedScriptAssembly != null) { // run script //this.cachedScriptAssembly.GetType( Template.ScriptClassName ).GetMethod( Template.ScriptMainMethodName ).Invoke(subject, parameters); Process process = new Process(); process.StartInfo.FileName = cachedScriptAssembly.Location; process.Start(); } } public static PermissionSet GetDefaultScriptPermissionSet() { PermissionSet internalDefScriptPermSet = new PermissionSet(PermissionState.None); internalDefScriptPermSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution)); internalDefScriptPermSet.AddPermission(new ReflectionPermission(ReflectionPermissionFlag.MemberAccess)); return internalDefScriptPermSet; } } }