public void BuildWithDependency(string functionFileName) { // Compile var environment = EnvironmentManager.CreateEnvironment(BASE_PATH, functionFileName); var functionFile = environment.FunctionFile; var projectFile = environment.ProjectFile; var assemblyFile = environment.AssemblyFile; var restorer = new DependencyRestorer(environment); restorer.CopyAndRestore(); var compiler = new DefaultCompiler(new DefaultParser(), new WithDependencyReferencesManager()); var function = FunctionCreator.CreateFunction(functionFile, projectFile); compiler.Compile(function); // Invoke var invoker = new DefaultInvoker(); var args = WebManager.GetHttpRequest(); object result = invoker.Execute(function, args); }
public void BuildWithDependency(string functionFileName) { var environment = EnvironmentManager.CreateEnvironment(BASE_PATH, functionFileName); var functionFile = environment.FunctionFile; var projectFile = environment.ProjectFile; var assemblyFile = environment.AssemblyFile; Assert.True(File.Exists(functionFile)); Assert.True(File.Exists(projectFile)); Assert.False(File.Exists(assemblyFile)); var restorer = new DependencyRestorer(environment); restorer.CopyAndRestore(); var compiler = new DefaultCompiler(new DefaultParser(), new WithDependencyReferencesManager()); var function = FunctionCreator.CreateFunction(functionFile, projectFile); Assert.False(function.IsCompiled()); compiler.Compile(function); Assert.True(function.IsCompiled()); Assert.True(File.Exists(assemblyFile)); Assert.NotEmpty(File.ReadAllBytes(assemblyFile)); }
public static void Main(string[] args) {/* * var code = "a = 1.0f\nb =4f\nc=1f\nc=\"asdas\""; * * var parser = new JSParser(); * * var assembly = parser.Parse(code); * * Console.WriteLine(assembly.Code); * * return; */ var compiler = new DefaultCompiler(); var assCode = File.ReadAllText(@"G:\Sharpyson\Sharpyson\Sharpyson.A\Program.cs"); var assembly = DefaultParsers.CSharp.Parse(assCode); var result = compiler.Compile(assembly); if (result.Success) { Console.ForegroundColor = ConsoleColor.Yellow; foreach (var warning in result.Warnings) { Console.WriteLine($"|{warning}|"); } Console.ResetColor(); Console.WriteLine($"Compilation was successfull. ({result.AssemblyPath})"); AppDomainHandler.Start(new List <CompilerResult> { result }); /* * * var psi = new ProcessStartInfo * { * FileName = "CMD.EXE", * Arguments = $"/K {result.AssemblyPath}" * }; * var p = Process.Start(psi); * p.WaitForExit();*/ } else { Console.ForegroundColor = ConsoleColor.Red; foreach (var error in result.Errors) { Console.WriteLine($"|{error}|"); } Console.ResetColor(); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); //Compile Function. var function = FunctionFactory.BuildFunction(Configuration); var compiler = new DefaultCompiler(new DefaultParser(), new DefaultReferencesManager()); if (!function.IsCompiled()) { compiler.Compile(function); } services.AddSingleton <IFunction>(function); services.AddSingleton <IInvoker>(new DefaultInvoker()); }
private static IFunction GetCompiledFunctionWithDepedencies(string functionFileName) { // Creates Environment var environment = EnvironmentManager.CreateEnvironment(BASE_PATH, functionFileName); var functionFile = environment.FunctionFile; var projectFile = environment.ProjectFile; var assemblyFile = environment.AssemblyFile; // Restore Dependencies var restorer = new DependencyRestorer(environment); restorer.CopyAndRestore(); // Compile var compiler = new DefaultCompiler(new DefaultParser(), new WithDependencyReferencesManager()); var function = FunctionCreator.CreateFunction(functionFile, projectFile); compiler.Compile(function); return(function); }