Exemplo n.º 1
0
        public void SetEvaluator(string id)
        {
            if (_evaluatorId == id && _evaluator != null)
            {
                return;
            }

            IInteractiveEvaluator eval = null;

            try {
                eval = string.IsNullOrEmpty(id) ?
                       null :
                       _providers.Select(p => p.GetEvaluator(id)).FirstOrDefault(e => e != null);
            } catch (NoInterpretersException ex) {
                _window.WriteErrorLine(ex.Message);
            } catch (MissingInterpreterException ex) {
                _window.WriteErrorLine(ex.Message);
            } catch (DirectoryNotFoundException ex) {
                _window.WriteErrorLine(ex.Message);
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                _window.WriteErrorLine(ex.ToUnhandledExceptionMessage(GetType()));
            }

            var oldEval = _evaluator;

            _evaluator = null;
            if (oldEval != null)
            {
                DetachWindow(oldEval);
                DetachMultipleScopeHandling(oldEval);
                oldEval.Dispose();
            }

            _evaluator   = eval;
            _evaluatorId = id;

            if (eval != null)
            {
                eval.CurrentWindow = CurrentWindow;
                if (eval.CurrentWindow != null)
                {
                    // Otherwise, we'll initialize when the window is set
                    DoInitializeAsync(eval).DoNotWait();
                }
            }
            UpdateCaption();
            PersistEvaluator();

            EvaluatorChanged?.Invoke(this, EventArgs.Empty);
            AttachMultipleScopeHandling(eval);
        }
Exemplo n.º 2
0
        public void SetEvaluator(string id)
        {
            if (_evaluatorId == id && _evaluator != null)
            {
                return;
            }

            var eval = string.IsNullOrEmpty(id) ?
                       null :
                       _providers.Select(p => p.GetEvaluator(id)).FirstOrDefault(e => e != null);

            var oldEval = _evaluator;

            _evaluator = null;
            if (oldEval != null)
            {
                DetachWindow(oldEval);
                DetachMultipleScopeHandling(oldEval);
                oldEval.Dispose();
            }

            _evaluator   = eval;
            _evaluatorId = id;

            if (eval != null)
            {
                eval.CurrentWindow = CurrentWindow;
                if (eval.CurrentWindow != null)
                {
                    // Otherwise, we'll initialize when the window is set
                    DoInitializeAsync(eval).DoNotWait();
                }
            }
            UpdateCaption();
            PersistEvaluator();

            EvaluatorChanged?.Invoke(this, EventArgs.Empty);
            AttachMultipleScopeHandling(eval);
        }