Exemple #1
0
        public async Task Handle(JupyterRequestContext context)
        {
            var executeRequest = GetJupyterRequest(context);

            context.RequestHandlerStatus.SetAsBusy();
            var executionCount = executeRequest.Silent ? _executionCount : Interlocked.Increment(ref _executionCount);

            var executeInputPayload = new ExecuteInput(executeRequest.Code, executionCount);
            var executeReply        = Message.Create(executeInputPayload, context.Request.Header);

            context.ServerChannel.Send(executeReply);

            var command = new SubmitCode(executeRequest.Code);

            var openRequest = new InflightRequest(context, executeRequest, executionCount);

            InFlightRequests[command] = openRequest;

            try
            {
                await Kernel.SendAsync(command);
            }
            catch (Exception e)
            {
                OnCommandFailed(new CommandFailed(e, command));
            }
        }
        public async Task Handle(JupyterRequestContext context)
        {
            var executeRequest = GetJupyterRequest(context);

            context.RequestHandlerStatus.SetAsBusy();
            var executionCount = executeRequest.Silent ? _executionCount : Interlocked.Increment(ref _executionCount);

            var command   = new SubmitCode(executeRequest.Code, "csharp");
            var id        = Guid.NewGuid();
            var transient = new Dictionary <string, object> {
                { "display_id", id.ToString() }
            };
            var openRequest = new InflightRequest(context, executeRequest, executionCount, transient);

            InFlightRequests[command] = openRequest;

            try
            {
                var kernelResult = await Kernel.SendAsync(command);

                openRequest.AddDisposable(kernelResult.KernelEvents.Subscribe(OnKernelResultEvent));
            }
            catch (Exception e)
            {
                InFlightRequests.TryRemove(command, out _);

                var errorContent = new Error(
                    eName: "Unhandled Exception",
                    eValue: $"{e.Message}"
                    );

                if (!executeRequest.Silent)
                {
                    // send on io
                    var error = Message.Create(
                        errorContent,
                        context.Request.Header);
                    context.IoPubChannel.Send(error);

                    // send on stderr
                    var stdErr = new StdErrStream(errorContent.EValue);
                    var stream = Message.Create(
                        stdErr,
                        context.Request.Header);
                    context.IoPubChannel.Send(stream);
                }

                //  reply Error
                var executeReplyPayload = new ExecuteReplyError(errorContent, executionCount: executionCount);

                // send to server
                var executeReply = Message.CreateResponse(
                    executeReplyPayload,
                    context.Request);

                context.ServerChannel.Send(executeReply);
                context.RequestHandlerStatus.SetAsIdle();
            }
        }
Exemple #3
0
 private void SendDisplayData(DisplayData displayData, InflightRequest openRequest)
 {
     if (!openRequest.Request.Silent)
     {
         // send on io
         var executeResultMessage = Message.Create(
             displayData,
             openRequest.Context.Request.Header);
         openRequest.Context.IoPubChannel.Send(executeResultMessage);
     }
 }
        public async Task Handle(JupyterRequestContext context)
        {
            var isCompleteRequest = GetJupyterRequest(context);
            var command           = new SubmitCode(isCompleteRequest.Code, submissionType: SubmissionType.Diagnose);

            var openRequest = new InflightRequest(context, isCompleteRequest, 0);

            InFlightRequests[command] = openRequest;

            await Kernel.SendAsync(command);
        }
        public async Task Handle(JupyterRequestContext context)
        {
            var executeRequest = GetJupyterRequest(context);

            context.RequestHandlerStatus.SetAsBusy();
            var executionCount = executeRequest.Silent ? _executionCount : Interlocked.Increment(ref _executionCount);

            var command = new SubmitCode(executeRequest.Code, "csharp");

            var openRequest = new InflightRequest(context, executeRequest, executionCount);

            InFlightRequests[command] = openRequest;

            try
            {
                await Kernel.SendAsync(command);
            }
            catch (Exception e)
            {
                InFlightRequests.TryRemove(command, out _);

                var errorContent = new Error(
                    eName: "Unhandled Exception",
                    eValue: $"{e.Message}"
                    );

                if (!executeRequest.Silent)
                {
                    // send on io
                    var error = Message.Create(
                        errorContent,
                        context.Request.Header);
                    context.IoPubChannel.Send(error);

                    // send on stderr
                    var stdErr = new StdErrStream(errorContent.EValue);
                    var stream = Message.Create(
                        stdErr,
                        context.Request.Header);
                    context.IoPubChannel.Send(stream);
                }

                //  reply Error
                var executeReplyPayload = new ExecuteReplyError(errorContent, executionCount: executionCount);

                // send to server
                var executeReply = Message.CreateResponse(
                    executeReplyPayload,
                    context.Request);

                context.ServerChannel.Send(executeReply);
                context.RequestHandlerStatus.SetAsIdle();
            }
        }
        public async Task Handle(JupyterRequestContext context)
        {
            var completeRequest = GetJupyterRequest(context);

            context.RequestHandlerStatus.SetAsBusy();

            var command = new RequestCompletion(completeRequest.Code, completeRequest.CursorPosition);

            var openRequest = new InflightRequest(context, completeRequest, 0);

            InFlightRequests[command] = openRequest;

            await Kernel.SendAsync(command);
        }
Exemple #7
0
        public async Task Handle(JupyterRequestContext context)
        {
            var interruptRequest = GetJupyterRequest(context);

            context.RequestHandlerStatus.SetAsBusy();

            var command = new CancelCurrentCommand();

            var openRequest = new InflightRequest(context, interruptRequest, 0);

            InFlightRequests[command] = openRequest;

            await Kernel.SendAsync(command);
        }
Exemple #8
0
        public async Task Handle(JupyterRequestContext context)
        {
            var completeRequest = GetJupyterRequest(context);

            context.RequestHandlerStatus.SetAsBusy();

            var command = new RequestCompletion(completeRequest.Code, completeRequest.CursorPosition);

            var openRequest = new InflightRequest(context, completeRequest, 0, null);

            InFlightRequests[command] = openRequest;

            var kernelResult = await Kernel.SendAsync(command);

            openRequest.AddDisposable(kernelResult.KernelEvents.Subscribe(OnKernelResultEvent));
        }
        public async Task Handle(JupyterRequestContext context)
        {
            var executeRequest = GetJupyterRequest(context);

            context.RequestHandlerStatus.SetAsBusy();
            var executionCount = executeRequest.Silent ? _executionCount : Interlocked.Increment(ref _executionCount);

            var command = new SubmitCode(executeRequest.Code, "csharp");

            var openRequest = new InflightRequest(context, executeRequest, executionCount);

            InFlightRequests[command] = openRequest;

            try
            {
                await Kernel.SendAsync(command);
            }
            catch (Exception e)
            {
                OnCommandFailed(new CommandFailed(e, command));
            }
        }