public static void Initialize() { if (_compiler == IntPtr.Zero) { _compiler = shp_CreateNewCompiler(1); } if (_vm == IntPtr.Zero) { try { _vm = SHP_CreateNewVM(1); SHP_SetVerbosity(_vm, 1); _compilerOutputDelegate = new CompilerOutputDelegate(compilerOutputCallback); _endWaitDelegate = new SheepEndWaitDelegate(endWaitCallback); SHP_SetOutputCallback(_vm, Marshal.GetFunctionPointerForDelegate(_compilerOutputDelegate)); SHP_SetEndWaitCallback(_vm, Marshal.GetFunctionPointerForDelegate(_endWaitDelegate)); BasicSheepFunctions.Init(); } catch (DllNotFoundException ex) { throw new SheepException("Unable to load the Sheep library.", ex); } } }
public void Run(ScriptCode code, CompilerOutputDelegate cod, PermissionSet permissionSet) { var resultAssembly = this.Compile(code.SourceCode, cod).CompiledAssembly; if (resultAssembly != null) { if (permissionSet != null) { permissionSet.PermitOnly(); } //// run script foreach (var item in code.StartUpList.OrderBy(row => row.order)) { if (resultAssembly.GetType(item.ClassName) == null || resultAssembly.GetType(item.ClassName).GetMethod(item.MethordName) == null) { throw new Exception(string.Format("没有找到公共的{0}.{0}", item.ClassName, item.MethordName)); } MethodInfo methordInfo = resultAssembly.GetType(item.ClassName).GetMethod(item.MethordName); methordInfo.Invoke(item.Instance, item.MethordParameters); } if (permissionSet != null) { CodeAccessPermission.RevertPermitOnly(); } } }
public virtual CompilerResults Compile(string code, CompilerOutputDelegate cod, CompilerParameters compilerParameters) { CompilerResults results = codeCompiler.CompileAssemblyFromSource(compilerParameters, code); if (results.Errors.HasErrors) { if (cod != null) { cod("-- Compilation of script failed"); } StringBuilder sb = new StringBuilder(); foreach (CompilerError err in results.Errors) { if (cod != null) { cod(err.ToString()); } sb.Append(err.ToString()).AppendLine(); } } else { if (cod != null) { cod("-- Compilation of script succesfull"); } } return(results); }
public CompilerResults Compile(string code, CompilerOutputDelegate cod) { try { MemoryComplieParameters.ReferencedAssemblies.AddRange(CodeCompilerFactory.GetReferencedAssemblies(FrameworkVersion).ToArray()); if (CustomeAssemblies != null) { MemoryComplieParameters.ReferencedAssemblies.AddRange(CustomeAssemblies.ToArray()); } return(this.Compile(code, cod, MemoryComplieParameters)); } catch (System.IO.FileNotFoundException exp) { throw new Exception("Unable to load script assembly (probably a complier error, check debug output)", exp); } }
public void Run(ScriptCode code, CompilerOutputDelegate cod) { this.Run(code, cod, null); }
public virtual CompilerResults Compile(string code, CompilerOutputDelegate cod, CompilerParameters compilerParameters) { CompilerResults results = codeCompiler.CompileAssemblyFromSource(compilerParameters, code); if (results.Errors.HasErrors) { if (cod != null) cod("-- Compilation of script failed"); StringBuilder sb = new StringBuilder(); foreach (CompilerError err in results.Errors) { if (cod != null) cod(err.ToString()); sb.Append(err.ToString()).AppendLine(); } } else { if (cod != null) cod("-- Compilation of script succesfull"); } return results; }
public CompilerResults Compile(string code, CompilerOutputDelegate cod) { try { MemoryComplieParameters.ReferencedAssemblies.AddRange(CodeCompilerFactory.GetReferencedAssemblies(FrameworkVersion).ToArray()); if (CustomeAssemblies != null) { MemoryComplieParameters.ReferencedAssemblies.AddRange(CustomeAssemblies.ToArray()); } return this.Compile(code, cod, MemoryComplieParameters); } catch (System.IO.FileNotFoundException exp) { throw new Exception("Unable to load script assembly (probably a complier error, check debug output)", exp); } }