Exemplo n.º 1
0
        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) {
            }
        }
Exemplo n.º 2
0
        public IRPlotDeviceVisualComponent GetPlotVisualComponent(IRPlotDevice device) {
            _shell.AssertIsOnMainThread();

            IRPlotDeviceVisualComponent visualComponent = null;
            _assignedVisualComponents.TryGetValue(device.DeviceId, out visualComponent);
            return visualComponent;
        }
Exemplo n.º 3
0
 private void UnsubscribeDeviceEvents(IRPlotDevice device)
 {
     device.PlotAddedOrUpdated -= ActivePlotChanged;
     device.Cleared            -= DeviceCleared;
     device.DeviceNumChanged   -= DeviceNumChanged;
     device.PlotRemoved        -= PlotRemoved;
 }
Exemplo n.º 4
0
        private void ShowDevice(IRPlotDevice device)
        {
            _mainThread.CheckAccess();

            var visualComponent = GetVisualComponentForDevice(device.DeviceId);

            visualComponent?.Container.Show(focus: false, immediate: false);
        }
Exemplo n.º 5
0
        private void ShowDevice(IRPlotDevice device)
        {
            InteractiveWorkflow.Shell.AssertIsOnMainThread();

            var visualComponent = GetVisualComponentForDevice(device.DeviceId);

            visualComponent?.Container.Show(focus: false, immediate: false);
        }
Exemplo n.º 6
0
        public IRPlotDeviceVisualComponent GetPlotVisualComponent(IRPlotDevice device)
        {
            _shell.AssertIsOnMainThread();

            IRPlotDeviceVisualComponent visualComponent = null;

            _assignedVisualComponents.TryGetValue(device.DeviceId, out visualComponent);
            return(visualComponent);
        }
Exemplo n.º 7
0
        public IRPlotDeviceVisualComponent GetPlotVisualComponent(IRPlotDevice device)
        {
            _mainThread.CheckAccess();

            IRPlotDeviceVisualComponent visualComponent = null;

            _assignedVisualComponents.TryGetValue(device.DeviceId, out visualComponent);
            return(visualComponent);
        }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 9
0
        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);
            }
        }
Exemplo n.º 10
0
        public void EndLocatorMode(IRPlotDevice device, LocatorResult result)
        {
            device.LocatorMode = false;

            var tcs = _locatorTcs;

            _locatorTcs = null;
            tcs?.TrySetResult(result);

            _locatorCancelTokenRegistration.Dispose();
        }
Exemplo n.º 11
0
        private void CancelLocatorMode(IRPlotDevice device)
        {
            device.LocatorMode = false;

            var tcs = _locatorTcs;

            _locatorTcs = null;
            tcs?.TrySetCanceled();

            _locatorCancelTokenRegistration.Dispose();
        }
Exemplo n.º 12
0
        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);
            }
        }
Exemplo n.º 13
0
        public void Assign(IRPlotDevice device)
        {
            _mainThread.Assert();

            _device = device;
            _device.PlotAddedOrUpdated += PlotAddedOrUpdated;
            _device.Cleared            += Cleared;
            _device.DeviceNumChanged   += DeviceNumChanged;
            _device.LocatorModeChanged += DeviceLocatorModeChanged;

            Refresh(_device.ActivePlot);
        }
Exemplo n.º 14
0
        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);
            }
        }
Exemplo n.º 15
0
        public Task AssignAsync(IRPlotDevice device)
        {
            _shell.AssertIsOnMainThread();

            _device = device;
            _device.PlotAddedOrUpdated += PlotAddedOrUpdated;
            _device.Cleared            += Cleared;
            _device.DeviceNumChanged   += DeviceNumChanged;

            Refresh(_device.ActivePlot);

            return(Task.CompletedTask);
        }
Exemplo n.º 16
0
        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;
            }
        }
Exemplo n.º 17
0
        public void Unassign()
        {
            _mainThread.Assert();

            if (_device != null)
            {
                _device.PlotAddedOrUpdated -= PlotAddedOrUpdated;
                _device.Cleared            -= Cleared;
                _device.DeviceNumChanged   -= DeviceNumChanged;
                _device.LocatorModeChanged -= DeviceLocatorModeChanged;
            }

            _device = null;
            Refresh(null);
        }
Exemplo n.º 18
0
        public Task UnassignAsync()
        {
            _shell.AssertIsOnMainThread();

            if (_device != null)
            {
                _device.PlotAddedOrUpdated -= PlotAddedOrUpdated;
                _device.Cleared            -= Cleared;
                _device.DeviceNumChanged   -= DeviceNumChanged;
            }

            _device = null;
            Refresh(null);

            return(Task.CompletedTask);
        }
Exemplo n.º 19
0
        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);
                }
            }
        }
Exemplo n.º 20
0
 public async Task ActivateDeviceAsync(IRPlotDevice device) {
     Debug.Assert(device != null);
     await _interactiveWorkflow.RSession.ActivatePlotDeviceAsync(device.DeviceId);
 }
Exemplo n.º 21
0
 public void Assign(IRPlotDevice device) {
     _viewModel.Assign(device);
     Container.UpdateCommandStatus(false);
 }
Exemplo n.º 22
0
 public async Task ActivateDeviceAsync(IRPlotDevice device)
 {
     Debug.Assert(device != null);
     await _interactiveWorkflow.RSession.ActivatePlotDeviceAsync(device.DeviceId);
 }
Exemplo n.º 23
0
 public void Assign(IRPlotDevice device)
 {
     _viewModel.Assign(device);
     Container.UpdateCommandStatus(false);
 }
Exemplo n.º 24
0
        public void Unassign() {
            _shell.AssertIsOnMainThread();

            if (_device != null) {
                _device.PlotAddedOrUpdated -= PlotAddedOrUpdated;
                _device.Cleared -= Cleared;
                _device.DeviceNumChanged -= DeviceNumChanged;
            }

            _device = null;
            Refresh(null);
        }
Exemplo n.º 25
0
 private async Task RefreshDeviceNum(IRPlotDevice device) {
     var num = await InteractiveWorkflow.RSession.GetPlotDeviceNumAsync(device.DeviceId);
     device.DeviceNum = num ?? 0;
 }
Exemplo n.º 26
0
        private async Task RefreshDeviceNum(IRPlotDevice device)
        {
            var num = await InteractiveWorkflow.RSession.GetPlotDeviceNumAsync(device.DeviceId);

            device.DeviceNum = num ?? 0;
        }
Exemplo n.º 27
0
 public RPlotDeviceEventArgs(IRPlotDevice device) {
     Device = device;
 }
Exemplo n.º 28
0
 public RPlot(IRPlotDevice parentDevice, Guid plotId, BitmapImage image) {
     ParentDevice = parentDevice;
     PlotId = plotId;
     Image = image;
 }
Exemplo n.º 29
0
 public RPlotDeviceEventArgs(IRPlotDevice device)
 {
     Device = device;
 }
Exemplo n.º 30
0
 private void UnsubscribeDeviceEvents(IRPlotDevice device) {
     device.PlotAddedOrUpdated -= ActivePlotChanged;
     device.Cleared -= DeviceCleared;
     device.DeviceNumChanged -= DeviceNumChanged;
     device.PlotRemoved -= PlotRemoved;
 }
Exemplo n.º 31
0
        public void Assign(IRPlotDevice device) {
            _shell.AssertIsOnMainThread();

            _device = device;
            _device.PlotAddedOrUpdated += PlotAddedOrUpdated;
            _device.Cleared += Cleared;
            _device.DeviceNumChanged += DeviceNumChanged;

            Refresh(_device.ActivePlot);
        }
Exemplo n.º 32
0
        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);
            }
        }
Exemplo n.º 33
0
        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) {
            }
        }
Exemplo n.º 34
0
 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);
     }
 }
Exemplo n.º 35
0
        private void ShowDevice(IRPlotDevice device) {
            InteractiveWorkflow.Shell.AssertIsOnMainThread();

            var visualComponent = GetVisualComponentForDevice(device.DeviceId);
            visualComponent?.Container.Show(focus: false, immediate: false);
        }
Exemplo n.º 36
0
 public RPlot(IRPlotDevice parentDevice, Guid plotId, object image)
 {
     ParentDevice = parentDevice;
     PlotId       = plotId;
     Image        = image;
 }
Exemplo n.º 37
0
 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);
     }
 }
Exemplo n.º 38
0
        public async Task AssignAsync(IRPlotDevice device)
        {
            await _viewModel.AssignAsync(device);

            Container.UpdateCommandStatus(false);
        }
Exemplo n.º 39
0
        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);
                }
            }
        }
Exemplo n.º 40
0
 public RPlot(IRPlotDevice parentDevice, Guid plotId, BitmapImage image)
 {
     ParentDevice = parentDevice;
     PlotId       = plotId;
     Image        = image;
 }
Exemplo n.º 41
0
        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}");
            }
        }