static public Result <string, SubmissionResponseValueStructure> EvaluateSubmissionAndGetResultingValue( JavaScriptEngineSwitcher.Core.IJsEngine evalElmPreparedJsEngine, Composition.TreeComponent appCodeTree, string submission, IReadOnlyList <string> previousLocalSubmissions = null) { var modulesTexts = appCodeTree == null ? null : ElmApp.ToFlatDictionaryWithPathComparer( appCodeTree.EnumerateBlobsTransitive() .Select(file => (filePath: (IImmutableList <string>)file.path.Select(pathComponent => Encoding.UTF8.GetString(pathComponent.ToArray())).ToImmutableList(), content: file.blobContent))) .Select(appCodeFile => appCodeFile.Key.Last().EndsWith(".elm") ? Encoding.UTF8.GetString(appCodeFile.Value.ToArray()) : null) .WhereNotNull() .ToImmutableList(); var argumentsJson = Newtonsoft.Json.JsonConvert.SerializeObject( new { modulesTexts = modulesTexts ?? ImmutableList <string> .Empty, submission = submission, previousLocalSubmissions = previousLocalSubmissions ?? ImmutableList <string> .Empty, } ); var responseJson = evalElmPreparedJsEngine.CallFunction("evaluateSubmissionInInteractive", argumentsJson) ?.ToString(); var responseStructure = Newtonsoft.Json.JsonConvert.DeserializeObject <EvaluateSubmissionResponseStructure>( responseJson); if (responseStructure.DecodedArguments == null) { throw new Exception("Failed to decode arguments: " + responseStructure.FailedToDecodeArguments); } if (responseStructure.DecodedArguments.Evaluated == null) { return(Result <string, SubmissionResponseValueStructure> .err(responseStructure.DecodedArguments.FailedToEvaluate)); } return(Result <string, ElmEngine.EvaluateElm.SubmissionResponseValueStructure> .ok( responseStructure.DecodedArguments.Evaluated.SubmissionResponseValue)); }
static public Result <string, EvaluatedSctructure> EvaluateSubmissionAndGetResultingValue( JavaScriptEngineSwitcher.Core.IJsEngine evalElmPreparedJsEngine, TreeWithStringPath?appCodeTree, string submission, IReadOnlyList <string>?previousLocalSubmissions = null) { var modulesTexts = appCodeTree == null ? null : TreeToFlatDictionaryWithPathComparer(compileTree(appCodeTree) !) .Select(appCodeFile => appCodeFile.Key.Last().EndsWith(".elm") ? Encoding.UTF8.GetString(appCodeFile.Value.ToArray()) : null) .WhereNotNull() .ToImmutableList(); var argumentsJson = System.Text.Json.JsonSerializer.Serialize( new { modulesTexts = modulesTexts ?? ImmutableList <string> .Empty, submission = submission, previousLocalSubmissions = previousLocalSubmissions ?? ImmutableList <string> .Empty, } ); var responseJson = evalElmPreparedJsEngine.CallFunction("evaluateSubmissionInInteractive", argumentsJson).ToString() !; var responseStructure = System.Text.Json.JsonSerializer.Deserialize <EvaluateSubmissionResponseStructure>(responseJson) !; if (responseStructure.DecodedArguments == null) { throw new Exception("Failed to decode arguments: " + responseStructure.FailedToDecodeArguments); } if (responseStructure.DecodedArguments.Evaluated == null) { return(Result <string, EvaluatedSctructure> .err(responseStructure.DecodedArguments.FailedToEvaluate !)); } return(Result <string, EvaluatedSctructure> .ok( responseStructure.DecodedArguments.Evaluated)); }
public object CallFunction(string functionName, params object[] args) { CheckDisposed(); return(_engine.CallFunction(functionName, args)); }