Exemple #1
0
        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();
                }
            }
        }
Exemple #2
0
        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;
        }
Exemple #3
0
 public void Run(ScriptCode code, CompilerOutputDelegate cod)
 {
     this.Run(code, cod, null);
 }
Exemple #4
0
 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);
     }
 }