public RemoteTask <IParseResult> ParseAsync(string scriptCode, ScriptingOptions Options, Func <MethodInfo[], MethodInfo> EntryMethodSelector, Func <MethodInfo, IParameter[]> EntryMethodParameterFactory) { IMethodSymbol _scriptEntryMethod; Assembly assembly = GetOrCreateScriptAssembly(new IParameter[0], scriptCode, Options, null, out _scriptEntryMethod); MethodInfo entryMethod = GetEntryMethod(assembly, _scriptEntryMethod); // eg the <factory> method Type submissionType = entryMethod.DeclaringType; // eg typeof(Submission#0) MethodInfo[] entryMethodCandidates = GetEntryMethodCandidatesFrom(submissionType); MethodInfo parsedEntryMethod = EntryMethodSelector(entryMethodCandidates); if (parsedEntryMethod == null) { throw new InvalidOperationException("No entry method function when parsing script"); } IParameter[] parsedParameters = EntryMethodParameterFactory(parsedEntryMethod); string refactoredCode = RefactorCodeToCallEntryMethod(scriptCode, parsedEntryMethod, parsedParameters); var result = new ParseResult(refactoredCode, parsedParameters, parsedEntryMethod.Name); return(RemoteTask.ServerStart <IParseResult>(cts => Task.FromResult <IParseResult>(result))); }
private LastCompilationInfo m_LastCompilation = null; // for caching results/compilations /// <summary> /// Runs the script asynchronously /// </summary> /// <param name="factory">Factory method to create an IScriptGlobals instance in the current (= the script's) AppDomain</param> /// <param name="parameters">Full list of IParameterValues to be passed to the script</param> /// <param name="scriptCode">Code of the script</param> /// <param name="Options">Options for script execution, compilation or invocation</param> /// <param name="submission">Returns an instance of the compiler-generated wrapped script class (e.g. an instance of Submission#0)</param> /// <returns>A RemoteTask, so the caller (which could reside in a different AppDomain) can unwrap the results asynchronously</returns> public RemoteTask <object> RunAsync(Func <AppDomain, IScriptGlobals> factory, IParameterValue[] parameters, string scriptCode, ScriptingOptions Options) { string debug_code_file_path = (Debugger.IsAttached) ? Path.Combine(Path.GetTempPath(), "ExcelScript.DebuggedCode.csx") : null; IScriptGlobals globalsInstance = null; try { scriptCode = RewriteCode(scriptCode, parameters, debug_code_file_path); if (debug_code_file_path != null) { // todo: might cause problems in multi threaded scenarios / whenever we're running through the .RunAsync() function in parallel. // possibly create varying or even fully random file paths - though though that might need some cleanup logic string line_directive = (debug_code_file_path == null) ? String.Empty : "#line 1 \"" + debug_code_file_path + "\"" + Environment.NewLine; File.WriteAllText(debug_code_file_path, scriptCode); scriptCode = line_directive + scriptCode; } IMethodSymbol entryPoint; var assembly = GetOrCreateScriptAssembly(parameters.Select(x => x.Parameter).ToArray(), scriptCode, Options, debug_code_file_path, out entryPoint); globalsInstance = CreateGlobals(factory, parameters); var entryMethod = GetEntryMethod(assembly, entryPoint); // the <factory> method var result = RemoteTask.ServerStart <object>(cts => InvokeFactoryAsync(entryMethod, globalsInstance)); return(result); } finally { if (!String.IsNullOrEmpty(debug_code_file_path) && File.Exists(debug_code_file_path)) { File.Delete(debug_code_file_path); } IDisposable globalsDisposable = globalsInstance as IDisposable; if (globalsDisposable != null) { globalsDisposable.Dispose(); } } }
public RemoteTask <FormattedText> GetFormattedCodeAsync(string scriptCode, ScriptingOptions Options, FormatColorScheme ColorScheme) { var result = RemoteTask.ServerStart <FormattedText>(cts => InternalGetFormattedCodeAsync(scriptCode, Options, ColorScheme)); return(result); }
public RemoteTask <string> GetRtfFormattedCodeAsync(string originalScriptCode, ScriptingOptions Options, FormatColorScheme ColorScheme) { var result = RemoteTask.ServerStart <string>(cts => InternalGetRtfFormattedCodeAsync(originalScriptCode, Options, ColorScheme)); return(result); }