예제 #1
0
 public VsRHostScript(IRSessionCallback clientApp = null)
     : base(
         VsAppShell.Current.ExportProvider.GetExportedValue <IRSessionProvider>(),
         VsAppShell.Current.ExportProvider.GetExportedValue <IRInteractiveWorkflowProvider>().GetOrCreate().BrokerConnector,
         clientApp)
 {
 }
예제 #2
0
        public async Task EnsureHostStartedAsync(RHostStartupInfo startupInfo, IRSessionCallback callback, int timeout = 3000)
        {
            _disposeToken.ThrowIfDisposed();
            var lockToken = await _initializationLock.WaitAsync();

            if (!lockToken.IsSet)
            {
                await StartHostAsyncBackground(startupInfo, callback, lockToken, timeout);
            }
        }
예제 #3
0
        public async Task StartHostAsync(RHostStartupInfo startupInfo, IRSessionCallback callback, int timeout = 3000)
        {
            _disposeToken.ThrowIfDisposed();

            if (Interlocked.CompareExchange(ref _initializationTcs, new TaskCompletionSourceEx <object>(), null) != null)
            {
                throw new InvalidOperationException("Another instance of RHost is running for this RSession. Stop it before starting new one.");
            }

            await StartHostAsyncBackground(startupInfo, callback, timeout);
        }
예제 #4
0
파일: RSession.cs 프로젝트: jflam/RTVS
        public async Task EnsureHostStartedAsync(RHostStartupInfo startupInfo, IRSessionCallback callback, int timeout = 3000, CancellationToken cancellationToken = default(CancellationToken))
        {
            using (_disposeToken.Link(ref cancellationToken)) {
                var lockToken = await _initializationLock.WaitAsync(cancellationToken);

                if (!lockToken.IsSet)
                {
                    await StartHostAsyncBackground(startupInfo, callback, lockToken, timeout, cancellationToken);
                }
            }
        }
예제 #5
0
        public async Task InitializeAsync(IRSessionCallback clientApp = null)
        {
            _clientApp = clientApp ?? _clientApp;

            Session = SessionProvider.GetOrCreate(SessionNames.InteractiveWindow);
            if (Session.IsHostRunning)
            {
                await Session.StopHostAsync();
            }

            await Session.StartHostAsync(new RHostStartupInfo(), _clientApp ?? new RHostClientTestApp(), 50000);
        }
예제 #6
0
        public async Task EnsureHostStartedAsync(RHostStartupInfo startupInfo, IRSessionCallback callback, int timeout = 3000)
        {
            var existingInitializationTcs = Interlocked.CompareExchange(ref _initializationTcs, new TaskCompletionSource <object>(), null);

            if (existingInitializationTcs == null)
            {
                await StartHostAsyncBackground(startupInfo, callback, timeout);
            }
            else
            {
                await existingInitializationTcs.Task;
            }
        }
예제 #7
0
        public async Task InitializeAsync(IRSessionCallback clientApp = null)
        {
            _clientApp = clientApp;

            await Workflow.RSessions.TrySwitchBrokerAsync(GetType().Name);

            if (Workflow.RSession.IsHostRunning)
            {
                await Workflow.RSession.StopHostAsync();
            }

            await Workflow.RSession.StartHostAsync(new RHostStartupInfo(), _clientApp ?? new RHostClientTestApp(), 50000);
        }
예제 #8
0
파일: RSession.cs 프로젝트: jflam/RTVS
 public async Task StartHostAsync(RHostStartupInfo startupInfo, IRSessionCallback callback, int timeout = 3000, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (_disposeToken.Link(ref cancellationToken)) {
         var isStartedTask = _initializationLock.WaitAsync(cancellationToken);
         if (isStartedTask.IsCompleted && !isStartedTask.Result.IsSet)
         {
             var lockToken = isStartedTask.Result;
             await StartHostAsyncBackground(startupInfo, callback, lockToken, timeout, cancellationToken);
         }
         else
         {
             throw new InvalidOperationException("Another instance of RHost is running for this RSession. Stop it before starting new one.");
         }
     }
 }
예제 #9
0
        public async Task InitializeAsync(IRSessionCallback clientApp = null) {
            _clientApp = clientApp ?? _clientApp;

            Session = SessionProvider.GetOrCreate(SessionGuids.InteractiveWindowRSessionGuid);
            if (Session.IsHostRunning) {
                await Session.StopHostAsync();
            }

            await Session.StartHostAsync(new RHostStartupInfo {
                Name = "RHostScript",
                CranMirrorName = RToolsSettings.Current.CranMirror,
                CodePage = RToolsSettings.Current.RCodePage,
                RHostCommandLineArguments = RToolsSettings.Current.LastActiveConnection.RCommandLineArguments
            }, _clientApp ?? new RHostClientTestApp(), 50000);
        }
예제 #10
0
        public RHostScript(IRSessionProvider sessionProvider, IRSessionCallback clientApp = null)
        {
            SessionProvider = sessionProvider;

            Session = SessionProvider.GetOrCreate(GuidList.InteractiveWindowRSessionGuid);
            Session.IsHostRunning.Should().BeFalse();

            Session.StartHostAsync(new RHostStartupInfo {
                Name      = "RHostScript",
                RBasePath = RToolsSettings.Current.RBasePath,
                RHostCommandLineArguments = RToolsSettings.Current.RCommandLineArguments,
                CranMirrorName            = RToolsSettings.Current.CranMirror,
                CodePage = RToolsSettings.Current.RCodePage
            }, clientApp ?? new RHostClientTestApp(), 50000).Wait();
        }
예제 #11
0
        private async Task StartHostAsyncBackground(RHostStartupInfo startupInfo, IRSessionCallback callback, int timeout)
        {
            await TaskUtilities.SwitchToBackgroundThread();

            _callback    = callback;
            _startupInfo = startupInfo;
            ClearPendingRequests(new RHostDisconnectedException());
            ScheduleAfterHostStarted(startupInfo);

            var initializationTask = _initializationTcs.Task;

            _hostRunTask = CreateAndRunHost(startupInfo, timeout);

            await initializationTask;
        }
예제 #12
0
        private async Task StartHostAsyncBackground(RHostStartupInfo startupInfo, IRSessionCallback callback, int timeout)
        {
            await TaskUtilities.SwitchToBackgroundThread();

            _callback = callback;
            _host     = new RHost(startupInfo != null ? startupInfo.Name : "Empty", this);
            ClearPendingRequests();

            var initializationTask = _initializationTcs.Task;

            _hostRunTask = CreateAndRunHost(startupInfo, timeout);

            ScheduleAfterHostStarted(startupInfo);

            await initializationTask;
        }
예제 #13
0
        public RHostScript(IRSessionProvider sessionProvider, IRSessionCallback clientApp = null)
        {
            SessionProvider = sessionProvider;

            Session = SessionProvider.GetOrCreate(GuidList.InteractiveWindowRSessionGuid);
            if (Session.IsHostRunning)
            {
                Session.StopHostAsync().Wait();
            }

            Session.StartHostAsync(new RHostStartupInfo {
                Name                      = "RHostScript",
                CranMirrorName            = RToolsSettings.Current.CranMirror,
                CodePage                  = RToolsSettings.Current.RCodePage,
                RHostCommandLineArguments = RToolsSettings.Current.LastActiveConnection.RCommandLineArguments
            }, clientApp ?? new RHostClientTestApp(), 50000).Wait();
        }
예제 #14
0
        private async Task StartHostAsync(RHostStartupInfo startupInfo, IRSessionCallback callback, int timeout, bool throwIfStarted, CancellationToken cancellationToken)
        {
            using (_disposeToken.Link(ref cancellationToken)) {
                await TaskUtilities.SwitchToBackgroundThread();

                using (await _initializationLock.WaitAsync(cancellationToken)) {
                    if (_hostStartedTcs.Task.Status != TaskStatus.RanToCompletion || !_isHostRunning)
                    {
                        await StartHostAsyncBackground(startupInfo, callback, timeout, cancellationToken);
                    }
                    else if (throwIfStarted)
                    {
                        throw new InvalidOperationException("Another instance of RHost is running for this RSession. Stop it before starting new one.");
                    }
                }
            }
        }
예제 #15
0
        private async Task ExecuteInSession(string[] inputs, IRSessionCallback app)
        {
            using (var sessionProvider = new RSessionProvider(_services)) {
                await sessionProvider.TrySwitchBrokerAsync(nameof(IdeGraphicsDeviceTest));

                var session = sessionProvider.GetOrCreate(_testMethod.FileSystemSafeName);
                await session.StartHostAsync(new RHostStartupInfo(), app, 50000);

                foreach (var input in inputs)
                {
                    using (var interaction = await session.BeginInteractionAsync()) {
                        await interaction.RespondAsync(input.EnsureLineBreak());
                    }
                }

                await session.StopHostAsync();
            }
        }
예제 #16
0
        private async Task ExecuteInSession(string[] inputs, IRSessionCallback app)
        {
            using (var sessionProvider = new RSessionProvider()) {
                var session = sessionProvider.GetOrCreate(Guid.NewGuid(), _brokerConnector);
                await session.StartHostAsync(new RHostStartupInfo {
                    Name = _testMethod.Name
                }, app, 50000);

                foreach (var input in inputs)
                {
                    using (var interaction = await session.BeginInteractionAsync()) {
                        await interaction.RespondAsync(input + "\n");
                    }
                }

                await session.StopHostAsync();
            }
        }
예제 #17
0
        private async Task StartHostAsyncBackground(RHostStartupInfo startupInfo, IRSessionCallback callback, int timeout, CancellationToken cancellationToken)
        {
            TaskUtilities.AssertIsOnBackgroundThread();

            _callback    = callback;
            _startupInfo = startupInfo ?? new RHostStartupInfo();
            RHost host;

            try {
                var connectionInfo = new HostConnectionInfo(Name, this, _startupInfo.UseRHostCommandLineArguments, timeout);
                host = await BrokerClient.ConnectAsync(connectionInfo, cancellationToken);
            } catch (OperationCanceledException ex) {
                _hostStartedTcs.TrySetCanceled(ex);
                throw;
            } catch (Exception ex) {
                _hostStartedTcs.TrySetException(ex);
                throw;
            }

            await StartHostAsyncBackground(host, cancellationToken);
        }
예제 #18
0
        private async Task StartHostAsyncBackground(RHostStartupInfo startupInfo, IRSessionCallback callback, IBinaryAsyncLockToken lockToken, int timeout)
        {
            await TaskUtilities.SwitchToBackgroundThread();

            _callback    = callback;
            _startupInfo = startupInfo;
            RHost host;

            try {
                host = await BrokerClient.ConnectAsync(startupInfo.Name, this, startupInfo.RHostCommandLineArguments, timeout);
            } catch (OperationCanceledException ex) {
                _initializationTcs.TrySetCanceled(ex);
                lockToken.Reset();
                throw;
            } catch (Exception ex) {
                _initializationTcs.TrySetException(ex);
                lockToken.Reset();
                throw;
            }

            await StartHostAsyncBackground(host, lockToken);
        }
예제 #19
0
 public VsRHostScript(IRSessionProvider sessionProvider, bool async, IRSessionCallback clientApp)
     : base(sessionProvider, async, clientApp) { }
예제 #20
0
 public Task EnsureHostStartedAsync(RHostStartupInfo startupInfo, IRSessionCallback callback, IUIService ui, int timeout = 3000, CancellationToken cancellationToken = default)
 => StartHostAsync(startupInfo, callback, ui, timeout, false, cancellationToken);
예제 #21
0
 public RHostScript(IExportProvider exportProvider, IRHostBrokerConnector brokerConnector, IRSessionCallback clientApp = null)
     : this(exportProvider.GetExportedValue <IRSessionProvider>(), brokerConnector, clientApp)
 {
 }
예제 #22
0
 public Task EnsureHostStartedAsync(RHostStartupInfo startupInfo, IRSessionCallback callback, int timeout = 3000, CancellationToken cancellationToken = default(CancellationToken)) {
     IsHostRunning = true;
     Connected?.Invoke(this, new RConnectedEventArgs(string.Empty));
     return Task.CompletedTask;
 }
예제 #23
0
 public HostBasedInteractiveTest(IRHostBrokerConnector brokerConnector, IRSessionCallback callback = null)
 {
     HostScript = new VsRHostScript(SessionProvider, brokerConnector, callback);
 }
예제 #24
0
 public Task EnsureHostStartedAsync(RHostStartupInfo startupInfo, IRSessionCallback callback, int timeout = 3000)
 {
     IsHostRunning = true;
     Connected?.Invoke(this, new RConnectedEventArgs(string.Empty));
     return(Task.CompletedTask);
 }
예제 #25
0
 public RHostScript(IExportProvider exportProvider, IRSessionCallback clientApp = null)
     : this(exportProvider.GetExportedValue <IRSessionProvider>(), exportProvider.GetExportedValue <IRInteractiveWorkflowProvider>().GetOrCreate().BrokerConnector, clientApp)
 {
 }
예제 #26
0
 public RHostScript(IRSessionProvider sessionProvider, bool async, IRSessionCallback clientApp) {
     SessionProvider = sessionProvider;
     _clientApp = clientApp;
 }
예제 #27
0
 public RHostScript(IRSessionProvider sessionProvider, IRSessionCallback clientApp = null) {
     SessionProvider = sessionProvider;
     _clientApp = clientApp;
     InitializeAsync().Wait();
 }
예제 #28
0
 public Task StartHostAsync(RHostStartupInfo startupInfo, IRSessionCallback callback, int timeout = 3000, CancellationToken cancellationToken = default(CancellationToken))
 {
     IsHostRunning = true;
     Connected?.Invoke(this, new RConnectedEventArgs(string.Empty));
     return(Task.CompletedTask);
 }
예제 #29
0
 public VsRHostScript(IServiceContainer services, IRSessionCallback clientApp = null)
     : base(services, clientApp)
 {
 }
예제 #30
0
 public Task StartHostAsync(RHostStartupInfo startupInfo, IRSessionCallback callback, int timeout = 3000)
 {
     IsHostRunning = true;
     Connected?.Invoke(this, EventArgs.Empty);
     return(Task.CompletedTask);
 }
예제 #31
0
 public VsRHostScript(IRSessionProvider sessionProvider, IRSessionCallback clientApp = null)
     : base(sessionProvider, clientApp) { }
예제 #32
0
 public RHostScript(IRSessionProvider sessionProvider, IRSessionCallback clientApp = null)
 {
     SessionProvider = sessionProvider;
     _clientApp      = clientApp;
     InitializeAsync().Wait();
 }
예제 #33
0
        private async Task ExecuteInSession(string[] inputs, IRSessionCallback app) {
            using (var sessionProvider = new RSessionProvider(TestCoreServices.CreateReal())) {
                await sessionProvider.TrySwitchBrokerAsync(nameof(IdeGraphicsDeviceTest));
                var session = sessionProvider.GetOrCreate(Guid.NewGuid());
                await session.StartHostAsync(new RHostStartupInfo {
                    Name = _testMethod.Name
                }, app, 50000);

                foreach (var input in inputs) {
                    using (var interaction = await session.BeginInteractionAsync()) {
                        await interaction.RespondAsync(input.EnsureLineBreak());
                    }
                }

                await session.StopHostAsync();
            }
        }
예제 #34
0
 public RHostScript(IRSessionProvider sessionProvider, bool async, IRSessionCallback clientApp)
 {
     SessionProvider = sessionProvider;
     _clientApp      = clientApp;
 }
예제 #35
0
 public Task StartHostAsync(RHostStartupInfo startupInfo, IRSessionCallback callback, int timeout = 3000, CancellationToken cancellationToken = default(CancellationToken))
 => StartHostAsync(startupInfo, callback, timeout, true, cancellationToken);
예제 #36
0
 public HostBasedInteractiveTest(IRSessionCallback callback = null)
 {
     HostScript = new VsRHostScript(SessionProvider, callback);
 }
예제 #37
0
 public HostBasedInteractiveTest(bool async, IRSessionCallback callback = null) {
     HostScript = new VsRHostScript(SessionProvider, async, callback);
 }
예제 #38
0
 public VsRHostScript(IRSessionProvider sessionProvider, IRHostBrokerConnector brokerConnector, IRSessionCallback clientApp = null)
     : base(sessionProvider, brokerConnector, clientApp)
 {
 }