Exemple #1
0
        static public Composition.TreeComponent RemoveNoiseFromTreeComingFromLocalFileSystem(
            Composition.TreeComponent originalTree)
        {
            if (originalTree.TreeContent == null)
            {
                return(originalTree);
            }

            Composition.TreeComponent getComponentFromStringName(string name) =>
            originalTree.TreeContent.FirstOrDefault(c => c.name.SequenceEqual(Encoding.UTF8.GetBytes(name))).component;

            var elmJson = getComponentFromStringName("elm.json");

            bool keepNode((IImmutableList <byte> name, Composition.TreeComponent component) node)
            {
                if (elmJson != null && node.name.SequenceEqual(Encoding.UTF8.GetBytes("elm-stuff")))
                {
                    return(false);
                }

                return(true);
            }

            return(new Composition.TreeComponent
            {
                TreeContent =
                    originalTree.TreeContent
                    .Where(keepNode)
                    .Select(child => (child.name, RemoveNoiseFromTreeComingFromLocalFileSystem(child.component))).ToImmutableList()
            });
Exemple #2
0
 static public Result <string, SubmissionResponseValueStructure> EvaluateSubmissionAndGetResultingValue(
     Composition.TreeComponent appCodeTree,
     string submission,
     IReadOnlyList <string> previousLocalSubmissions = null)
 {
     using (var jsEngine = PrepareJsEngineToEvaluateElm())
     {
         return(EvaluateSubmissionAndGetResultingValue(
                    jsEngine,
                    appCodeTree: appCodeTree,
                    submission: submission,
                    previousLocalSubmissions: previousLocalSubmissions));
     }
 }
Exemple #3
0
        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));
        }
Exemple #4
0
 public InteractiveSession(Composition.TreeComponent appCodeTree)
 {
     this.appCodeTree = appCodeTree;
 }