/// <summary> /// 将源码编译成js代码 /// </summary> /// <param name="source">源码</param> /// <param name="filename">文件名称</param> /// <param name="isCreateFile">是否产生编译后的js文件,如果产生文件,则文件产生的目录为运行时库所在的路径,默认为Host的根路径下的Compiled/Logic/</param> /// <param name="outfilepath">产生编译后的js文件的存放路径,只有在isCreateFile=true的时候有效</param> /// <returns></returns> public Dictionary <string, string> Compile(string filename, string source, bool isCreateFile) { var p = new TagParameter(); var d = new TagData(); p.RootPath = _context.RootPath; p.CommonLibPath = _context.CommonLibPath; p.RunTimeLibPath = _context.RunTimeLibPath; p.Text = source; p.SetValue("__tags__", _context.AllTags); ModuleProxyManager.Call <HostLogicProxy, TagParameter, TagData>(p, d); Dictionary <string, string> contents = (Dictionary <string, string>)d.ExtentionObj.result; if (isCreateFile) { if (!Directory.Exists(p.RunTimeLibPath)) { Directory.CreateDirectory(p.RunTimeLibPath); } if (!Directory.Exists(p.RunTimeLibPath + HostJsConstants.LOGIC_PATH)) { Directory.CreateDirectory(p.RunTimeLibPath + HostJsConstants.LOGIC_PATH); } foreach (var item in contents) { var path = p.RunTimeLibPath + HostJsConstants.LOGIC_PATH + filename + (item.Key != "" ? "." + item.Key : "") + ".hjs"; File.WriteAllText(path, item.Value, Encoding.UTF8); } } return(contents); }
/// <summary> /// 将源码编译成js代码 /// </summary> /// <param name="filename">文件名称</param> /// <param name="source">源码</param> /// <param name="isCreateFile">是否产生编译后的文件,如果产生文件,则文件产生的目录为Host的根路径下的Compiled/View/</param> /// <param name="outfilepath">产生编译后的js文件的存放路径,只有在isCreateFile=true的时候有效</param> /// <returns></returns> public string Compile(string filename, string source, bool isCreateFile) { var rtn = ""; var p = new TagParameter(); var d = new TagData(); p.RootPath = _context.RootPath; p.CommonLibPath = _context.CommonLibPath; p.RunTimeLibPath = _context.RunTimeLibPath; p.Text = source; p.SetValue("__tags__", _context.AllTags); ModuleProxyManager.Call <HostViewProxy, TagParameter, TagData>(p, d); rtn = d.ParsedText; if (isCreateFile) { if (!Directory.Exists(p.RunTimeLibPath + HostJsConstants.VIEW_PATH)) { Directory.CreateDirectory(p.RunTimeLibPath + HostJsConstants.VIEW_PATH); } var path = p.RunTimeLibPath + HostJsConstants.VIEW_PATH + filename + ".hjs"; File.WriteAllText(path, rtn, Encoding.UTF8); } return(rtn); }