protected override Assembly LoadAssembly() { var scriptEngines = ScriptDomain.ScriptEngines; var right = Path.Substring(scriptEngines.BaseDirectory.Length + 1).Replace('\\', '.').Replace('-', '_'); var left = System.IO.Path.GetFileNameWithoutExtension(right); var namespacename = scriptEngines.Namespace; var typename = left; var index = left.LastIndexOf('.'); if (index > 0) { namespacename += "." + left.Substring(0, index); typename = left.Substring(index + 1); } if (typename.Length > 0 && char.IsLower(typename[0])) { typename = char.ToUpper(typename[0]) + typename.Substring(1, typename.Length - 1); } var path = Path + ScriptEngines.ScriptExtension; var script = File.ReadAllText(path, Encoding.UTF8); var html = File.ReadAllText(Path); html = CodeConverter(html, namespacename, typename); var appScriptRefs = new List <string>() { scriptEngines.AppScriptDomain.PathToAssembly }; if (scriptEngines.ApplicationDomain.IsEnabled) { appScriptRefs.Add(scriptEngines.ApplicationDomain.PathToAssembly); } var refAssemblies = scriptEngines.ReferencedAssemblyNames.Concat(appScriptRefs).Distinct().ToArray(); var sources = new string[] { script, html }; var assemblyName = System.IO.Path.GetFileNameWithoutExtension(Path); var result = ScriptCompiler.CompileFromSource(sources, refAssemblies, assemblyName); if (!result.Success) { logger.Debug(typename + WindowExtension + ScriptEngines.ScriptExtension); logger.Debug(html); throw new InvalidOperationException("compile error:" + string.Join(Environment.NewLine, result.Diagnostics)); } return(result.Assembly); }
private Assembly LoadAssembly() { var path = FullName; if (!File.Exists(path)) { throw new FileNotFoundException(path); } var content = File.ReadAllText(path, Encoding.UTF8); var source = new string[] { content }; var appScriptRefs = new string[] { ScriptEngines.AppScriptDomain.PathToAssembly }; var refAssemblies = ScriptEngines.ReferencedAssemblyNames.Concat(appScriptRefs).ToArray(); var pathDirectory = System.IO.Path.GetDirectoryName(pathToAssembly); var result = ScriptCompiler.CompileFromSource(source, refAssemblies, AssemblyName, pathDirectory, false); if (!result.Success) { throw new InvalidOperationException("compile error:" + string.Join(Environment.NewLine, result.Diagnostics)); } return(result.Assembly); }
protected override Assembly LoadAssembly() { var content = File.ReadAllText(Path, Encoding.UTF8); var source = new string[] { content }; var scriptEngines = ScriptDomain.ScriptEngines; var appScriptRefs = new List <string>() { scriptEngines.AppScriptDomain.PathToAssembly }; if (scriptEngines.ApplicationDomain.IsEnabled) { appScriptRefs.Add(scriptEngines.ApplicationDomain.PathToAssembly); } var refAssemblies = scriptEngines.ReferencedAssemblyNames.Concat(appScriptRefs).Distinct().ToArray(); var assemblyName = System.IO.Path.GetFileNameWithoutExtension(Path); var result = ScriptCompiler.CompileFromSource(source, refAssemblies, assemblyName); if (!result.Success) { throw new InvalidOperationException("compile error:" + string.Join(Environment.NewLine, result.Diagnostics)); } return(result.Assembly); }