private async Task RSessionMutatedAsync() { await _shell.SwitchToMainThreadAsync(); try { var deviceId = await InteractiveWorkflow.RSession.GetActivePlotDeviceAsync(); var device = FindDevice(deviceId); var deviceChanged = device != ActiveDevice; ActiveDevice = device; // Update all the devices in parallel IRPlotDevice[] devices; lock (_devicesLock) { devices = _devices.ToArray(); } var tasks = devices.Select(RefreshDeviceNum); await Task.WhenAll(tasks); _interactiveWorkflow.ActiveWindow?.Container.UpdateCommandStatus(false); if (deviceChanged) { ActiveDeviceChanged?.Invoke(this, new RPlotDeviceEventArgs(ActiveDevice)); } } catch (RException) { } catch (OperationCanceledException) { } }
public IRPlotDeviceVisualComponent GetPlotVisualComponent(IRPlotDevice device) { _shell.AssertIsOnMainThread(); IRPlotDeviceVisualComponent visualComponent = null; _assignedVisualComponents.TryGetValue(device.DeviceId, out visualComponent); return visualComponent; }
private void UnsubscribeDeviceEvents(IRPlotDevice device) { device.PlotAddedOrUpdated -= ActivePlotChanged; device.Cleared -= DeviceCleared; device.DeviceNumChanged -= DeviceNumChanged; device.PlotRemoved -= PlotRemoved; }
private void ShowDevice(IRPlotDevice device) { _mainThread.CheckAccess(); var visualComponent = GetVisualComponentForDevice(device.DeviceId); visualComponent?.Container.Show(focus: false, immediate: false); }
private void ShowDevice(IRPlotDevice device) { InteractiveWorkflow.Shell.AssertIsOnMainThread(); var visualComponent = GetVisualComponentForDevice(device.DeviceId); visualComponent?.Container.Show(focus: false, immediate: false); }
public IRPlotDeviceVisualComponent GetPlotVisualComponent(IRPlotDevice device) { _shell.AssertIsOnMainThread(); IRPlotDeviceVisualComponent visualComponent = null; _assignedVisualComponents.TryGetValue(device.DeviceId, out visualComponent); return(visualComponent); }
public IRPlotDeviceVisualComponent GetPlotVisualComponent(IRPlotDevice device) { _mainThread.CheckAccess(); IRPlotDeviceVisualComponent visualComponent = null; _assignedVisualComponents.TryGetValue(device.DeviceId, out visualComponent); return(visualComponent); }
private async Task CopyPlotAsync(IRPlot sourcePlot, IRPlotDevice targetDevice) { await TaskUtilities.SwitchToBackgroundThread(); try { await InteractiveWorkflow.RSession.CopyPlotAsync(sourcePlot.ParentDevice.DeviceId, sourcePlot.PlotId, targetDevice.DeviceId); } catch (RException ex) { throw new RPlotManagerException(string.Format(CultureInfo.InvariantCulture, Resources.Plots_EvalError, ex.Message), ex); } }
public async Task PreviousPlotAsync(IRPlotDevice device) { await TaskUtilities.SwitchToBackgroundThread(); try { await _interactiveWorkflow.RSession.PreviousPlotAsync(device.DeviceId); } catch (RException ex) { throw new RPlotManagerException(string.Format(CultureInfo.InvariantCulture, Resources.Plots_EvalError, ex.Message), ex); } }
public void EndLocatorMode(IRPlotDevice device, LocatorResult result) { device.LocatorMode = false; var tcs = _locatorTcs; _locatorTcs = null; tcs?.TrySetResult(result); _locatorCancelTokenRegistration.Dispose(); }
private void CancelLocatorMode(IRPlotDevice device) { device.LocatorMode = false; var tcs = _locatorTcs; _locatorTcs = null; tcs?.TrySetCanceled(); _locatorCancelTokenRegistration.Dispose(); }
private async Task ShowDeviceAsync(IRPlotDevice device) { InteractiveWorkflow.Shell.AssertIsOnMainThread(); var visualComponent = await GetVisualComponentForDevice(device.DeviceId); if (visualComponent != null) { visualComponent.Container.Show(focus: false, immediate: false); } }
public void Assign(IRPlotDevice device) { _mainThread.Assert(); _device = device; _device.PlotAddedOrUpdated += PlotAddedOrUpdated; _device.Cleared += Cleared; _device.DeviceNumChanged += DeviceNumChanged; _device.LocatorModeChanged += DeviceLocatorModeChanged; Refresh(_device.ActivePlot); }
public async Task ResizeAsync(IRPlotDevice device, int pixelWidth, int pixelHeight, int resolution) { if (!_interactiveWorkflow.RSession.IsHostRunning) { return; } try { await _interactiveWorkflow.RSession.ResizePlotAsync(device.DeviceId, pixelWidth, pixelHeight, resolution); } catch (RException ex) { throw new RPlotManagerException(string.Format(CultureInfo.InvariantCulture, Resources.Plots_EvalError, ex.Message), ex); } }
public Task AssignAsync(IRPlotDevice device) { _shell.AssertIsOnMainThread(); _device = device; _device.PlotAddedOrUpdated += PlotAddedOrUpdated; _device.Cleared += Cleared; _device.DeviceNumChanged += DeviceNumChanged; Refresh(_device.ActivePlot); return(Task.CompletedTask); }
private async Task ExecuteAndWaitForPlotsAsync(IRPlotDevice device, string[] scripts) { var eval = _workflow.ActiveWindow.InteractiveWindow.Evaluator; foreach (string script in scripts) { var plotReceivedTask = EventTaskSources.IRPlotDevice.PlotAddedOrUpdated.Create(device); var result = await eval.ExecuteCodeAsync(script.EnsureLineBreak()); result.IsSuccessful.Should().BeTrue(); await plotReceivedTask; } }
public void Unassign() { _mainThread.Assert(); if (_device != null) { _device.PlotAddedOrUpdated -= PlotAddedOrUpdated; _device.Cleared -= Cleared; _device.DeviceNumChanged -= DeviceNumChanged; _device.LocatorModeChanged -= DeviceLocatorModeChanged; } _device = null; Refresh(null); }
public Task UnassignAsync() { _shell.AssertIsOnMainThread(); if (_device != null) { _device.PlotAddedOrUpdated -= PlotAddedOrUpdated; _device.Cleared -= Cleared; _device.DeviceNumChanged -= DeviceNumChanged; } _device = null; Refresh(null); return(Task.CompletedTask); }
public async Task CopyOrMovePlotFromAsync(Guid sourceDeviceId, Guid sourcePlotId, IRPlotDevice targetDevice, bool isMove) { Debug.Assert(targetDevice != null); InteractiveWorkflow.Shell.AssertIsOnMainThread(); var sourcePlot = FindPlot(sourceDeviceId, sourcePlotId); if (sourcePlot != null) { await CopyPlotAsync(sourcePlot, targetDevice); if (isMove) { await RemovePlotAsync(sourcePlot); // Removing that plot may activate the device from the removed plot, // which would hide this device. So we re-show it. ShowDevice(targetDevice); } } }
public async Task ActivateDeviceAsync(IRPlotDevice device) { Debug.Assert(device != null); await _interactiveWorkflow.RSession.ActivatePlotDeviceAsync(device.DeviceId); }
public void Assign(IRPlotDevice device) { _viewModel.Assign(device); Container.UpdateCommandStatus(false); }
public async Task ActivateDeviceAsync(IRPlotDevice device) { Debug.Assert(device != null); await _interactiveWorkflow.RSession.ActivatePlotDeviceAsync(device.DeviceId); }
public void Assign(IRPlotDevice device) { _viewModel.Assign(device); Container.UpdateCommandStatus(false); }
public void Unassign() { _shell.AssertIsOnMainThread(); if (_device != null) { _device.PlotAddedOrUpdated -= PlotAddedOrUpdated; _device.Cleared -= Cleared; _device.DeviceNumChanged -= DeviceNumChanged; } _device = null; Refresh(null); }
private async Task RefreshDeviceNum(IRPlotDevice device) { var num = await InteractiveWorkflow.RSession.GetPlotDeviceNumAsync(device.DeviceId); device.DeviceNum = num ?? 0; }
private async Task RefreshDeviceNum(IRPlotDevice device) { var num = await InteractiveWorkflow.RSession.GetPlotDeviceNumAsync(device.DeviceId); device.DeviceNum = num ?? 0; }
public RPlotDeviceEventArgs(IRPlotDevice device) { Device = device; }
public RPlot(IRPlotDevice parentDevice, Guid plotId, BitmapImage image) { ParentDevice = parentDevice; PlotId = plotId; Image = image; }
public RPlotDeviceEventArgs(IRPlotDevice device) { Device = device; }
private void UnsubscribeDeviceEvents(IRPlotDevice device) { device.PlotAddedOrUpdated -= ActivePlotChanged; device.Cleared -= DeviceCleared; device.DeviceNumChanged -= DeviceNumChanged; device.PlotRemoved -= PlotRemoved; }
public void Assign(IRPlotDevice device) { _shell.AssertIsOnMainThread(); _device = device; _device.PlotAddedOrUpdated += PlotAddedOrUpdated; _device.Cleared += Cleared; _device.DeviceNumChanged += DeviceNumChanged; Refresh(_device.ActivePlot); }
public async Task ResizeAsync(IRPlotDevice device, int pixelWidth, int pixelHeight, int resolution) { if (!_interactiveWorkflow.RSession.IsHostRunning) { return; } try { await _interactiveWorkflow.RSession.ResizePlotAsync(device.DeviceId, pixelWidth, pixelHeight, resolution); } catch (RException ex) { throw new RPlotManagerException(string.Format(CultureInfo.InvariantCulture, Resources.Plots_EvalError, ex.Message), ex); } }
private async Task RSessionMutatedAsync() { await _shell.SwitchToMainThreadAsync(); try { var deviceId = await InteractiveWorkflow.RSession.GetActivePlotDeviceAsync(); var device = FindDevice(deviceId); var deviceChanged = device != ActiveDevice; ActiveDevice = device; // Update all the devices in parallel var tasks = _devices.Select(RefreshDeviceNum); await Task.WhenAll(tasks); _interactiveWorkflow.ActiveWindow?.Container.UpdateCommandStatus(false); if (deviceChanged) { ActiveDeviceChanged?.Invoke(this, new RPlotDeviceEventArgs(ActiveDevice)); } } catch (RException) { } catch (OperationCanceledException) { } }
public async Task PreviousPlotAsync(IRPlotDevice device) { await TaskUtilities.SwitchToBackgroundThread(); try { await _interactiveWorkflow.RSession.PreviousPlotAsync(device.DeviceId); } catch (RException ex) { throw new RPlotManagerException(string.Format(CultureInfo.InvariantCulture, Resources.Plots_EvalError, ex.Message), ex); } }
private void ShowDevice(IRPlotDevice device) { InteractiveWorkflow.Shell.AssertIsOnMainThread(); var visualComponent = GetVisualComponentForDevice(device.DeviceId); visualComponent?.Container.Show(focus: false, immediate: false); }
public RPlot(IRPlotDevice parentDevice, Guid plotId, object image) { ParentDevice = parentDevice; PlotId = plotId; Image = image; }
private async Task CopyPlotAsync(IRPlot sourcePlot, IRPlotDevice targetDevice) { await TaskUtilities.SwitchToBackgroundThread(); try { await InteractiveWorkflow.RSession.CopyPlotAsync(sourcePlot.ParentDevice.DeviceId, sourcePlot.PlotId, targetDevice.DeviceId); } catch (RException ex) { throw new RPlotManagerException(string.Format(CultureInfo.InvariantCulture, Resources.Plots_EvalError, ex.Message), ex); } }
public async Task AssignAsync(IRPlotDevice device) { await _viewModel.AssignAsync(device); Container.UpdateCommandStatus(false); }
public async Task CopyOrMovePlotFromAsync(Guid sourceDeviceId, Guid sourcePlotId, IRPlotDevice targetDevice, bool isMove) { Debug.Assert(targetDevice != null); InteractiveWorkflow.Shell.AssertIsOnMainThread(); var sourcePlot = FindPlot(sourceDeviceId, sourcePlotId); if (sourcePlot != null) { await CopyPlotAsync(sourcePlot, targetDevice); if (isMove) { await RemovePlotAsync(sourcePlot); // Removing that plot may activate the device from the removed plot, // which would hide this device. So we re-show it. ShowDevice(targetDevice); } } }
public RPlot(IRPlotDevice parentDevice, Guid plotId, BitmapImage image) { ParentDevice = parentDevice; PlotId = plotId; Image = image; }
private async Task ExecuteAndWaitForPlotsAsync(IRPlotDevice device, string[] scripts) { var eval = _workflow.ActiveWindow.InteractiveWindow.Evaluator; foreach (string script in scripts) { var plotReceivedTask = EventTaskSources.IRPlotDevice.PlotAddedOrUpdated.Create(device); var result = await eval.ExecuteCodeAsync(script.EnsureLineBreak()); result.IsSuccessful.Should().BeTrue(); await plotReceivedTask.Should().BeCompletedAsync(10000, $"it should execute script: {script}"); } }