Exemple #1
0
        /// <summary>
        /// 将.NET内置的编译结果对象转换为ScriptAgent的编译结果对象
        /// </summary>
        /// <param name="results">.NET内置的编译结果对象</param>
        /// <returns>ScriptAgent的编译结果对象(永不为null)</returns>
        private CompileResults GetCompileResults(CompilerResults results)
        {
            CompileResults compileResults = new CompileResults();

            if (results == null)
            {
                return(compileResults);
            }
            if (results.Errors != null && results.Errors.HasErrors)
            {
                foreach (CompilerError error in results.Errors)
                {
                    if (error.IsWarning)
                    {
                        compileResults.HasWarnings = true;
                    }
                    else
                    {
                        compileResults.HasErrors = true;
                    }
                    error.Line -= this.m_nScriptHeaderLineCount;
                    compileResults.Errors.Add(new CompileError(error.FileName
                                                               , error.Line, error.Column, error.ErrorNumber, error.ErrorText, error.IsWarning));
                }
                return(compileResults);
            }
            //以裸数据的方式加载程序,防止程序集临时文件被占用导致无法清除
            byte[] byteAssemblyData = AssemblyHelper.Instance.GetAssemblyData(results.PathToAssembly);
            compileResults.CompiledAssembly = AssemblyHelper.Instance.GetScriptAssembly(byteAssemblyData);
            return(compileResults);
        }
Exemple #2
0
 private Script.CompileErrorCollection GetCompileErrors(Script.CompileResults results)
 {
     Script.CompileErrorCollection errors = null;
     if (results == null)
     {
         return(null);
     }
     errors = results.Errors;
     return(errors);
 }
Exemple #3
0
        /// <summary>
        /// 编译指定脚本源码,返回编译结果
        /// </summary>
        /// <param name="scriptProperty">脚本配置信息</param>
        /// <returns>ScriptAgent的编译结果对象(永不为null)</returns>
        public CompileResults CompileScript(ScriptProperty scriptProperty)
        {
            if (scriptProperty == null)
            {
                return(new CompileResults());
            }

            GlobalMethods.IO.CreateDirectory(this.CachePath);
            string szOutputFile = string.Format("{0}\\Calc.{1}.dll"
                                                , this.CachePath, Math.Abs(scriptProperty.ScriptText.GetHashCode()).ToString());

            CompileResults results = this.CompileScript(scriptProperty.ScriptText, scriptProperty.ScriptLang, szOutputFile);

            scriptProperty.ScriptData = AssemblyHelper.Instance.GetAssemblyData(szOutputFile);
            GlobalMethods.IO.DeleteFile(szOutputFile);
            return(results);
        }