コード例 #1
0
        private async Task AfterHostStarted(RHostStartupInfo startupInfo)
        {
            var evaluator = new BeforeInitializedRExpressionEvaluator(this);

            try {
                // Load RTVS R package before doing anything in R since the calls
                // below calls may depend on functions exposed from the RTVS package
                var libPath = IsRemote ? "." : Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetAssemblyPath());

                await LoadRtvsPackage(evaluator, libPath);

                var wd = startupInfo.WorkingDirectory;
                if (!IsRemote && !string.IsNullOrEmpty(wd) && wd.HasReadPermissions())
                {
                    try {
                        await evaluator.SetWorkingDirectoryAsync(wd);
                    } catch (REvaluationException) {
                        await evaluator.SetDefaultWorkingDirectoryAsync();
                    }
                }
                else
                {
                    await evaluator.SetDefaultWorkingDirectoryAsync();
                }

                var callback = _callback;
                if (callback != null)
                {
                    await evaluator.SetVsGraphicsDeviceAsync();

                    string mirrorUrl = callback.CranUrlFromName(startupInfo.CranMirrorName);

                    try {
                        await evaluator.SetVsCranSelectionAsync(mirrorUrl);
                    } catch (REvaluationException ex) {
                        await WriteErrorAsync(Resources.Error_SessionInitializationMirror, mirrorUrl, ex.Message);
                    }

                    try {
                        await evaluator.SetCodePageAsync(startupInfo.CodePage);
                    } catch (REvaluationException ex) {
                        await WriteErrorAsync(Resources.Error_SessionInitializationCodePage, startupInfo.CodePage, ex.Message);
                    }

                    try {
                        await evaluator.SetROptionsAsync();
                    } catch (REvaluationException ex) {
                        await WriteErrorAsync(Resources.Error_SessionInitializationOptions, ex.Message);
                    }

                    await evaluator.OverrideFunctionAsync("setwd", "base");

                    await evaluator.SetFunctionRedirectionAsync();

                    try {
                        await evaluator.OptionsSetWidthAsync(startupInfo.TerminalWidth);
                    } catch (REvaluationException ex) {
                        await WriteErrorAsync(Resources.Error_SessionInitializationOptions, ex.Message);
                    }

                    if (startupInfo.EnableAutosave)
                    {
                        try {
                            // Only enable autosave for this session after querying the user about any existing file.
                            // This way, if they happen to disconnect while still querying, we don't save the new empty
                            // session and overwrite the old file.
                            bool deleteExisting = await evaluator.QueryReloadAutosaveAsync();

                            await evaluator.EnableAutosaveAsync(deleteExisting);
                        } catch (REvaluationException ex) {
                            await WriteErrorAsync(Resources.Error_SessionInitializationAutosave, ex.Message);
                        }
                    }

                    Interactive?.Invoke(this, EventArgs.Empty);
                }

                _initializedTcs.SetResult(null);
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
#if DEBUG
                // Detailed exception information in REPL is not particularly useful to the end user.
                await WriteErrorAsync(Resources.Error_SessionInitialization, ex);
#endif
                if (!(ex is RHostDisconnectedException))
                {
                    StopHostAsync().DoNotWait();
                }

                var oce = ex as OperationCanceledException;
                if (oce != null)
                {
                    _initializedTcs.SetCanceled(oce);
                }
                else
                {
                    _initializedTcs.SetException(ex);
                }
            }
        }
コード例 #2
0
ファイル: RSession.cs プロジェクト: Ikuyadeu/RTVS
        private async Task AfterHostStarted(RHostStartupInfo startupInfo)
        {
            var evaluator = new BeforeInitializedRExpressionEvaluator(this);

            try {
                await LoadRtvsPackage(evaluator, IsRemote);

                var suggest_mro = await evaluator.EvaluateAsync <bool>("!exists('Revo.version')", REvaluationKind.Normal);

                if (suggest_mro)
                {
                    await WriteOutputAsync(Resources.Message_SuggestMRO);
                }

                var wd = startupInfo.WorkingDirectory;
                if (!IsRemote && !string.IsNullOrEmpty(wd))
                {
                    try {
                        await evaluator.SetWorkingDirectoryAsync(wd);
                    } catch (REvaluationException) {
                        await evaluator.SetDefaultWorkingDirectoryAsync();
                    }
                }
                else
                {
                    await evaluator.SetDefaultWorkingDirectoryAsync();
                }

                if (!startupInfo.IsInteractive || IsRemote)
                {
                    // If session is non-interactive (such as intellisense) or it is remote
                    // we need to set up UI suppression overrides.
                    try {
                        await SuppressUI(evaluator);
                    } catch (REvaluationException) { }
                }

                var callback = _callback;
                if (callback != null)
                {
                    await evaluator.SetVsGraphicsDeviceAsync();

                    string mirrorUrl = callback.CranUrlFromName(startupInfo.CranMirrorName);

                    try {
                        await evaluator.SetVsCranSelectionAsync(mirrorUrl);
                    } catch (REvaluationException ex) {
                        await WriteErrorAsync(Resources.Error_SessionInitializationMirror, mirrorUrl, ex.Message);
                    }

                    try {
                        await evaluator.SetCodePageAsync(startupInfo.CodePage);
                    } catch (REvaluationException ex) {
                        await WriteErrorAsync(Resources.Error_SessionInitializationCodePage, startupInfo.CodePage, ex.Message);
                    }

                    try {
                        await evaluator.SetROptionsAsync();
                    } catch (REvaluationException ex) {
                        await WriteErrorAsync(Resources.Error_SessionInitializationOptions, ex.Message);
                    }

                    await evaluator.OverrideFunctionAsync("setwd", "base");

                    await evaluator.SetFunctionRedirectionAsync();

                    await evaluator.SetGridEvalModeAsync(startupInfo.GridDynamicEvaluation);

                    try {
                        await evaluator.OptionsSetWidthAsync(startupInfo.TerminalWidth);
                    } catch (REvaluationException ex) {
                        await WriteErrorAsync(Resources.Error_SessionInitializationOptions, ex.Message);
                    }

                    if (startupInfo.EnableAutosave)
                    {
                        try {
                            // Only enable autosave for this session after querying the user about any existing file.
                            // This way, if they happen to disconnect while still querying, we don't save the new empty
                            // session and overwrite the old file.
                            bool deleteExisting = await evaluator.QueryReloadAutosaveAsync();

                            await evaluator.EnableAutosaveAsync(deleteExisting);
                        } catch (REvaluationException ex) {
                            await WriteErrorAsync(Resources.Error_SessionInitializationAutosave, ex.Message);
                        }
                    }

                    Interactive?.Invoke(this, EventArgs.Empty);
                }

                _initializedTcs.SetResult(null);
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
#if DEBUG
                // Detailed exception information in REPL is not particularly useful to the end user.
                await WriteErrorAsync(Resources.Error_SessionInitialization, ex);
#endif
                if (!(ex is RHostDisconnectedException))
                {
                    StopHostAsync().DoNotWait();
                }

                if (ex is OperationCanceledException oce)
                {
                    _initializedTcs.SetCanceled(oce);
                }
                else
                {
                    _initializedTcs.SetException(ex);
                }
            }
        }