public async Task ViewFile(string fileName, string tabName, bool deleteFile, CancellationToken cancellationToken)
        {
            await _coreShell.SwitchToMainThreadAsync(cancellationToken);

            try {
                if (File.Exists(fileName))
                {
                    FileViewer.ViewFile(fileName, tabName);
                    if (deleteFile)
                    {
                        File.Delete(fileName);
                    }
                }
            } catch (Exception ex) when(ex is IOException || ex is UnauthorizedAccessException)
            {
                _coreShell.ShowErrorMessage(ex.Message);
            }
        }
示例#2
0
文件: CodeViewer.cs 项目: jflam/RTVS
        public async Task ViewAsync(string expression, string title)
        {
            var evaluation = await EvaluateAsync(expression, REvaluationResultProperties.ExpressionProperty, null);

            if (evaluation == null || string.IsNullOrEmpty(evaluation.Expression))
            {
                return;
            }

            var functionName = evaluation.Expression;
            var session      = _workflow.RSession;

            string functionCode = await GetFunctionCode(functionName);

            if (!string.IsNullOrEmpty(functionCode))
            {
                string tempFile = Path.ChangeExtension(Path.GetTempFileName(), ".r");
                try {
                    if (File.Exists(tempFile))
                    {
                        File.Delete(tempFile);
                    }

                    using (var sw = new StreamWriter(tempFile)) {
                        sw.Write(functionCode);
                    }

                    await VsAppShell.Current.SwitchToMainThreadAsync();

                    FileViewer.ViewFile(tempFile, functionName);
                    try {
                        File.Delete(tempFile);
                    } catch (IOException) { } catch (UnauthorizedAccessException) { }
                } catch (IOException) { } catch (UnauthorizedAccessException) { }
            }
        }