public void VariableGrid_ConstructorTest02() { VisualTreeObject actual = null; using (var hostScript = new VariableRHostScript()) { using (var script = new ControlTestScript(typeof(VariableGridHost))) { DoIdle(100); EvaluationWrapper wrapper = null; Task.Run(async () => { hostScript.VariableProvider.Subscribe( 0, "grid.test", (r) => wrapper = new EvaluationWrapper(r)); await hostScript.EvaluateAsync("grid.test <- matrix(1:10, 2, 5)"); }).Wait(); DoIdle(2000); wrapper.Should().NotBeNull(); UIThreadHelper.Instance.Invoke(() => { var host = (VariableGridHost)script.Control; host.SetEvaluation(wrapper); }); DoIdle(1000); actual = VisualTreeObject.Create(script.Control); } } ViewTreeDump.CompareVisualTrees(_files, actual, "VariableGrid02"); }
public GridDataProvider(EvaluationWrapper evaluation) { _evaluation = evaluation; RowCount = evaluation.Dimensions[0]; ColumnCount = evaluation.Dimensions[1]; }
internal void SetEvaluation(EvaluationWrapper evaluation) { if (!string.IsNullOrWhiteSpace(evaluation.Expression)) { Caption = Invariant($"{Resources.VariableGrid_Caption}: {evaluation.Expression}"); } _gridHost.SetEvaluation(evaluation); }
public void ShowDataGrid(DebugEvaluationResult evaluationResult) { var wrapper = new EvaluationWrapper(evaluationResult); if (!wrapper.CanShowDetail) { throw new InvalidOperationException("Cannot show data grid on evaluation result " + evaluationResult); } wrapper.ShowDetailCommand.Execute(null); }
public async Task EvaluateAsync(string rScript) { VariableSubscription subscription = null; // One eval at a time await _sem.WaitAsync(); try { _mre.Reset(); _globalEnv = null; subscription = _variableProvider.Subscribe(0, "base::environment()", OnGlobalEnvironmentEvaluated); using (var evaluation = await base.Session.BeginEvaluationAsync()) { await evaluation.EvaluateAsync(rScript); } if (System.Diagnostics.Debugger.IsAttached) { _mre.Wait(); } else { if (!_mre.Wait(TimeSpan.FromSeconds(10))) { throw new TimeoutException("Evaluate time out"); } } } finally { _variableProvider.Unsubscribe(subscription); _sem.Release(); } }
private void SetRootNode(EvaluationWrapper evaluation) { _rootNode = new ObservableTreeNode( new VariableNode(_settings, evaluation), Comparer<ITreeNode>.Create(Comparison)); RootTreeGrid.ItemsSource = new TreeNodeCollection(_rootNode).ItemList; }
private async Task SetRootModelAsync(REnvironment env) { await TaskUtilities.SwitchToBackgroundThread(); var debugSession = await GetDebugSessionAsync(); var frames = await debugSession.GetStackFramesAsync(); var frame = frames.FirstOrDefault(f => f.Index == 0); if (frame != null) { const DebugEvaluationResultFields fields = DebugEvaluationResultFields.Classes | DebugEvaluationResultFields.Expression | DebugEvaluationResultFields.TypeName | (DebugEvaluationResultFields.Repr | DebugEvaluationResultFields.ReprStr) | DebugEvaluationResultFields.Dim | DebugEvaluationResultFields.Length; DebugEvaluationResult result = await frame.EvaluateAsync( GetExpression(env), fields); var wrapper = new EvaluationWrapper(result); var rootNodeModel = new VariableNode(_settings, wrapper); VsAppShell.Current.DispatchOnUIThread( () => { _rootNode.Model = rootNodeModel; }); } }
private void SetRootNode(EvaluationWrapper evaluation) { _rootNode = new ObservableTreeNode( new VariableNode(_settings, evaluation), Comparer <ITreeNode> .Create(Comparison)); RootTreeGrid.ItemsSource = new TreeNodeCollection(_rootNode).ItemList; }
private void OnGlobalEnvironmentEvaluation(DebugEvaluationResult result) { var wrapper = new EvaluationWrapper(result); var rootNodeModel = new VariableNode(_settings, wrapper); VsAppShell.Current.DispatchOnUIThread( () => { EnvironmentName.Text = GlobalEnvironmentName; _rootNode.Model = rootNodeModel; }); }
private void SubscribeAction(DebugEvaluationResult evaluation) { VsAppShell.Current.DispatchOnUIThread( () => { if (evaluation is DebugErrorEvaluationResult) { // evaluation error, this could happen if R object is removed var error = (DebugErrorEvaluationResult)evaluation; SetError(error.ErrorText); return; } var wrapper = new EvaluationWrapper(evaluation); if (wrapper.TypeName == "NULL" && wrapper.Value == "NULL") { // the variable should have been removed SetError( string.Format( CultureInfo.InvariantCulture, Package.Resources.VariableGrid_Missing, evaluation.Expression)); } else if (wrapper.Dimensions.Count != 2) { // the same evaluation changed to non-matrix SetError( string.Format( CultureInfo.InvariantCulture, Package.Resources.VariableGrid_NotTwoDimension, evaluation.Expression)); } else if (wrapper.Dimensions[0] != _evaluation.Dimensions[0] || wrapper.Dimensions[1] != _evaluation.Dimensions[1]) { ClearError(); // matrix size changed. Reset the evaluation SetEvaluation(wrapper); } else { ClearError(); // size stays same. Refresh VariableGrid.Refresh(); } }); }
internal void SetEvaluation(EvaluationWrapper evaluation) { ClearError(); VariableGrid.Initialize(new GridDataProvider(evaluation)); _evaluation = evaluation; if (_subscription != null) { _variableProvider.Unsubscribe(_subscription); _subscription = null; } _subscription = _variableProvider.Subscribe( evaluation.FrameIndex, evaluation.Expression, SubscribeAction); }
internal void SetEvaluation(EvaluationWrapper wrapper) { if (wrapper.TypeName == "NULL" && wrapper.Value == "NULL") { // the variable should have been removed SetError( string.Format( CultureInfo.InvariantCulture, Package.Resources.VariableGrid_Missing, wrapper.Expression)); } else if (wrapper.Dimensions.Count != 2) { // the same evaluation changed to non-matrix SetError( string.Format( CultureInfo.InvariantCulture, Package.Resources.VariableGrid_NotTwoDimension, wrapper.Expression)); } else if (_evaluation == null || (wrapper.Dimensions[0] != _evaluation.Dimensions[0] || wrapper.Dimensions[1] != _evaluation.Dimensions[1])) { // matrix size changed. Reset the evaluation ClearError(); VariableGrid.Initialize(new GridDataProvider(wrapper)); _evaluation = wrapper; } else { ClearError(); // size stays same. Refresh VariableGrid.Refresh(); } }
private async Task EvaluateAsync() { try { await TaskUtilities.SwitchToBackgroundThread(); var debugSession = await VsAppShell.Current.ExportProvider.GetExportedValue <IDebugSessionProvider>().GetDebugSessionAsync(_rSession); const DebugEvaluationResultFields fields = DebugEvaluationResultFields.Classes | DebugEvaluationResultFields.Expression | DebugEvaluationResultFields.TypeName | (DebugEvaluationResultFields.Repr | DebugEvaluationResultFields.ReprStr) | DebugEvaluationResultFields.Dim | DebugEvaluationResultFields.Length; var result = await debugSession.EvaluateAsync(_evaluation.Expression, fields); var wrapper = new EvaluationWrapper(result); VsAppShell.Current.DispatchOnUIThread(() => SetEvaluation(wrapper)); } catch (Exception ex) { VsAppShell.Current.DispatchOnUIThread(() => SetError(ex.Message)); } }
public bool CanShowDataGrid(DebugEvaluationResult evaluationResult) { var wrapper = new EvaluationWrapper(evaluationResult); return(wrapper.CanShowDetail); }
public bool CanShowDataGrid(DebugEvaluationResult evaluationResult) { var wrapper = new EvaluationWrapper(evaluationResult); return wrapper.CanShowDetail; }
private void OnGlobalEnvironmentEvaluated(DebugEvaluationResult result) { _globalEnv = new EvaluationWrapper(result); _mre.Set(); }
public VariableNode(IRToolsSettings settings, EvaluationWrapper evaluation) { _settings = settings; _evaluation = evaluation; }