public Task InitializeSession(InteractiveSessionDescription sessionDescription)
 {
     referenceWhitelist.Clear();
     return(GetSession().InitializeAsync(
                sessionDescription,
                Context.ConnectionAborted));
 }
Пример #2
0
        /// <summary>
        /// Hosts an interactive REPL against a supported Workbooks target platform.
        /// This is analogous to 'csharp' or 'csi' or any other REPL on the planet.
        /// </summary>
        static async Task <int> ReplPlayerMain()
        {
            // As an exercise to the reader, this puppy should take an optional
            // workbook flavor ID to know what platform you want to REPL and find
            // it in the list of installed and available ones...
            // For now we'll just pick the first available option 😺
            var workbookTarget = WorkbookAppInstallation.All.FirstOrDefault();

            if (workbookTarget == null)
            {
                RenderError("No workbook target platforms could be found.");
                return(1);
            }

            // We do not currently expose a list of available language descriptions
            // for the given build/installation, but if we did, this is when
            // you'd want to pick one. Just assume 'csharp' for now. Stay tuned.
            language = "csharp";

            // A session description combines just enough info for the entire
            // EvaluationService to get itself in order to do your bidding.
            var sessionDescription = new InteractiveSessionDescription(
                language,
                workbookTarget.Id,
                new EvaluationEnvironment(Environment.CurrentDirectory));

            // Now create and get ready to deal with the session; a more complete
            // client should handle more than just OnNext from the observer.
            var session = InteractiveSession.CreateWorkbookSession();

            session.Events.Subscribe(new Observer <InteractiveSessionEvent> (OnSessionEvent));

            // And initialize it with all of our prerequisites...
            // Status events raised within this method will be posted to the
            // observable above ("starting agent", "initializing workspace", etc).
            await session.InitializeAsync(sessionDescription);

            // At this point we have the following in order, ready to serve:
            //
            //   1. a connected agent ready to execute code
            //   2. a workspace that can perform compliation, intellisense, etc
            //   3. an evaluation service that is ready to deal with (1) and (2)
            //
            // It's at this point that a full UI would allow the user to actually
            // run code. This is the "User Experience main()"...
            //
            // This is the REPL you're looking for...
            while (true)
            {
                // append a new cell (no arguments here imply append)
                var cellId = await session.EvaluationService.InsertCodeCellAsync();

                // render the initial/top-level prompt
                WriteReplPrompt();

                while (true)
                {
                    var deltaBuffer    = ReadLine();
                    var existingBuffer = await session.EvaluationService.GetCodeCellBufferAsync(cellId);

                    await session.EvaluationService.UpdateCodeCellAsync(
                        cellId,
                        existingBuffer.Value + deltaBuffer);

                    if (session.WorkspaceService.IsCellComplete(cellId))
                    {
                        break;
                    }

                    WriteReplPrompt(secondaryPrompt: true);
                }

                await session.EvaluationService.EvaluateAsync(cellId);
                await EvaluationServiceRaceBug();
            }
        }
 public Task InitializeSession(InteractiveSessionDescription sessionDescription)
 => GetSession().InitializeAsync(
     sessionDescription,
     Context.Connection.ConnectionAbortedToken);
Пример #4
0
        /// <summary>
        /// Hosts an interactive REPL against a supported Workbooks target platform.
        /// This is analogous to 'csharp' or 'csi' or any other REPL on the planet.
        /// </summary>
        static async Task <int> ReplPlayerMain(InteractiveSession session)
        {
            // As an exercise to the reader, this puppy should take an optional
            // workbook flavor ID to know what platform you want to REPL and find
            // it in the list of installed and available ones...
            // For now we'll just pick the first available option 😺
            var workbookTarget = WorkbookAppInstallation.All.FirstOrDefault();

            if (workbookTarget == null)
            {
                RenderError("No workbook target platforms could be found.");
                return(1);
            }

            // We do not currently expose a list of available language descriptions
            // for the given build/installation, but if we did, this is when
            // you'd want to pick one. Just assume 'csharp' for now. Stay tuned.
            language = "csharp";

            // A session description combines just enough info for the entire
            // EvaluationService to get itself in order to do your bidding.
            var sessionDescription = new InteractiveSessionDescription(
                language,
                workbookTarget.Id,
                new EvaluationEnvironment(Environment.CurrentDirectory));

            // And initialize it with all of our prerequisites...
            // Status events raised within this method will be posted to the
            // observable above ("starting agent", "initializing workspace", etc).
            await session.InitializeAsync(sessionDescription);

            CodeCellId cellId = default;

            var editor = new LineEditor("xic");

            editor.BeforeRenderPrompt = () => ForegroundColor = ConsoleColor.Yellow;
            editor.AfterRenderPrompt  = () => ResetColor();

            // At this point we have the following in order, ready to serve:
            //
            //   1. a connected agent ready to execute code
            //   2. a workspace that can perform compliation, intellisense, etc
            //   3. an evaluation service that is ready to deal with (1) and (2)
            //
            // It's at this point that a full UI would allow the user to actually
            // run code. This is the "User Experience main()"...
            //
            // This is the REPL you're looking for...
            while (true)
            {
                // append a new cell (no arguments here imply append)
                cellId = await session.EvaluationService.InsertCodeCellAsync();

                for (int i = 0; true; i++)
                {
                    var deltaBuffer = editor.Edit(
                        GetPrompt(i > 0),
                        null);

                    var existingBuffer = await session.EvaluationService.GetCodeCellBufferAsync(cellId);

                    await session.EvaluationService.UpdateCodeCellAsync(
                        cellId,
                        existingBuffer.Value + deltaBuffer);

                    if (session.WorkspaceService.IsCellComplete(cellId))
                    {
                        break;
                    }
                }

                var finishedEvent = await session.EvaluationService.EvaluateAsync(cellId);

                // if the evaluation was not successful, remove the cell so it's not internally
                // re-evaluated (which would continue to yield the same failures)
                if (finishedEvent.Status != CodeCellEvaluationStatus.Success)
                {
                    await session.EvaluationService.RemoveCodeCellAsync(finishedEvent.CodeCellId);
                }
            }
        }
 public void NotifySessionDescriptionChanged(InteractiveSessionDescription sessionDescription);
 public Task InitializeAsync(InteractiveSessionDescription sessionDescription, CancellationToken cancellationToken = default(CancellationToken));