public Task Handle(JupyterRequestContext context)
        {
            var executeRequest = context.GetRequestContent <ExecuteRequest>() ?? throw new InvalidOperationException($"Request Content must be a not null {typeof(ExecuteRequest).Name}");

            context.RequestHandlerStatus.SetAsBusy();
            var command   = new SubmitCode(executeRequest.Code);
            var id        = command.Id;
            var transient = new Dictionary <string, object> {
                { "display_id", id.ToString() }
            };
            var executionCount = executeRequest.Silent ? _executionCount : Interlocked.Increment(ref _executionCount);

            _openRequests[id] = new OpenRequest(context, executeRequest, executionCount, id, transient);
            return(_kernel.SendAsync(command));
        }
Esempio n. 2
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            _shell.Bind(_shellAddress);
            _ioPubSocket.Bind(_ioPubAddress);
            _stdIn.Bind(_stdInAddress);
            _control.Bind(_controlAddress);

            using (var activity = Logger <Shell> .Log.OnEnterAndExit())
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    var message = _shell.GetMessage();

                    activity.Info("Received: {message}", message.ToJson());

                    var status = new RequestHandlerStatus(message.Header, new MessageSender(_ioPubSocket, _signatureValidator));


                    switch (message.Header.MessageType)
                    {
                    case MessageTypeValues.KernelInfoRequest:
                        status.SetAsBusy();
                        HandleKernelInfoRequest(message);
                        status.SetAsIdle();
                        break;

                    case MessageTypeValues.KernelShutdownRequest:
                        status.SetAsBusy();
                        status.SetAsIdle();
                        break;

                    default:
                        var context = new JupyterRequestContext(
                            _shellSender,
                            _ioPubSender,
                            message,
                            new RequestHandlerStatus(message.Header, _shellSender));

                        await _scheduler.Schedule(context);

                        break;
                    }
                }
            }
        }