Пример #1
0
        private async Task RMarkdownRenderAsync(IRSession session, IFileSystem fs, string inputFilePath, string outputFilePath, string format, int codePage, IApplicationShell appShell)
        {
            using (var fts = new DataTransferSession(session, fs)) {
                string       currentStatusText = string.Empty;
                uint         cookie            = 0;
                IVsStatusbar statusBar         = null;
                appShell.DispatchOnUIThread(() => {
                    statusBar = appShell.GetGlobalService <IVsStatusbar>(typeof(SVsStatusbar));
                    statusBar.GetText(out currentStatusText);
                    statusBar.Progress(ref cookie, 1, "", 0, 0);
                });

                try {
                    appShell.DispatchOnUIThread(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownSendingInputFile.FormatInvariant(Path.GetFileName(inputFilePath)), 0, 3); });
                    var rmd = await fts.SendFileAsync(inputFilePath);

                    appShell.DispatchOnUIThread(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownPublishingFile.FormatInvariant(Path.GetFileName(inputFilePath)), 1, 3); });
                    var publishResult = await session.EvaluateAsync <ulong>($"rtvs:::rmarkdown_publish(blob_id = {rmd.Id}, output_format = {format.ToRStringLiteral()}, encoding = 'cp{codePage}')", REvaluationKind.Normal);

                    appShell.DispatchOnUIThread(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownGetOutputFile.FormatInvariant(Path.GetFileName(outputFilePath)), 2, 3); });
                    await fts.FetchFileAsync(new RBlobInfo(publishResult), outputFilePath);

                    appShell.DispatchOnUIThread(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownPublishComplete.FormatInvariant(Path.GetFileName(outputFilePath)), 3, 3); });
                } finally {
                    appShell.DispatchOnUIThread(() => {
                        statusBar?.Progress(ref cookie, 0, "", 0, 0);
                        statusBar?.SetText(currentStatusText);
                    });
                }
            }
        }
Пример #2
0
        private async Task SendProjectAsync(EnvDTE.Project project, string remotePath, string filterString, CancellationToken cancellationToken)
        {
            Console.WriteLine(Resources.Info_PreparingProjectForTransfer);

            var projectDir  = Path.GetDirectoryName(project.FullName);
            var projectName = Path.GetFileNameWithoutExtension(project.FullName);

            string[] filterSplitter = { ";" };
            Matcher  matcher        = new Matcher(StringComparison.InvariantCultureIgnoreCase);

            matcher.AddIncludePatterns(filterString.Split(filterSplitter, StringSplitOptions.RemoveEmptyEntries));

            Console.WriteLine(Resources.Info_RemoteDestination.FormatInvariant(remotePath));
            Console.WriteLine(Resources.Info_FileTransferFilter.FormatInvariant(filterString));
            Console.WriteLine(Resources.Info_CompressingFiles);

            var compressedFilePath = FileSystem.CompressDirectory(projectDir, matcher, new Progress <string>((p) => {
                Console.WriteLine(Resources.Info_LocalFilePath.FormatInvariant(p));
                string dest = p.MakeRelativePath(projectDir).ProjectRelativePathToRemoteProjectPath(remotePath, projectName);
                Console.WriteLine(Resources.Info_RemoteFilePath.FormatInvariant(dest));
            }), CancellationToken.None);

            using (var fts = new DataTransferSession(Session, FileSystem)) {
                Console.WriteLine(Resources.Info_TransferringFiles);
                var remoteFile = await fts.SendFileAsync(compressedFilePath, true, null, cancellationToken);

                await Session.EvaluateAsync <string>($"rtvs:::save_to_project_folder({remoteFile.Id}, {projectName.ToRStringLiteral()}, '{remotePath.ToRPath()}')", REvaluationKind.Normal, cancellationToken);
            }

            Console.WriteLine(Resources.Info_TransferringFilesDone);
        }
Пример #3
0
        private async Task RMarkdownRenderAsync(IRSession session, string inputFilePath, string outputFilePath, string format, int codePage, IServiceContainer services)
        {
            using (var fts = new DataTransferSession(session, services.FileSystem())) {
                string       currentStatusText = string.Empty;
                uint         cookie            = 0;
                IVsStatusbar statusBar         = null;
                services.MainThread().Post(() => {
                    statusBar = services.GetService <IVsStatusbar>(typeof(SVsStatusbar));
                    statusBar.GetText(out currentStatusText);
                    statusBar.Progress(ref cookie, 1, "", 0, 0);
                });

                try {
                    // TODO: progress and cancellation handling
                    services.MainThread().Post(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownSendingInputFile.FormatInvariant(Path.GetFileName(inputFilePath)), 0, 3); });
                    var rmd = await fts.SendFileAsync(inputFilePath, true, null, CancellationToken.None);

                    services.MainThread().Post(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownPublishingFile.FormatInvariant(Path.GetFileName(inputFilePath)), 1, 3); });
                    var publishResult = await session.EvaluateAsync <ulong>($"rtvs:::rmarkdown_publish(blob_id = {rmd.Id}, output_format = {format.ToRStringLiteral()}, encoding = 'cp{codePage}')", REvaluationKind.Normal);

                    services.MainThread().Post(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownGetOutputFile.FormatInvariant(Path.GetFileName(outputFilePath)), 2, 3); });
                    await fts.FetchFileAsync(new RBlobInfo(publishResult), outputFilePath, true, null, CancellationToken.None);

                    services.MainThread().Post(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownPublishComplete.FormatInvariant(Path.GetFileName(outputFilePath)), 3, 3); });
                } finally {
                    services.MainThread().Post(() => {
                        statusBar?.Progress(ref cookie, 0, "", 0, 0);
                        statusBar?.SetText(currentStatusText);
                    });
                }
            }
        }
Пример #4
0
        private async Task RMarkdownRenderAsync(IRSession session, IFileSystem fs, string inputFilePath, string outputFilePath, string format, int codePage)
        {
            using (var fts = new DataTransferSession(session, fs)) {
                var rmd = await fts.SendFileAsync(inputFilePath);

                var publishResult = await session.EvaluateAsync <ulong>($"rtvs:::rmarkdown_publish(blob_id = {rmd.Id}, output_format = {format.ToRStringLiteral()}, encoding = 'cp{codePage}')", REvaluationKind.Normal);

                await fts.FetchFileAsync(new RBlobInfo(publishResult), outputFilePath);
            }
        }
Пример #5
0
        private async Task RMarkdownRenderAsync(IRSession session, string inputFilePath, string outputFilePath, string format, int codePage, IServiceContainer services)
        {
            using (var fts = new DataTransferSession(session, services.FileSystem())) {
                var statusBar = services.GetService <IStatusBar>();
                using (var progress = await statusBar.ShowProgressAsync(3)) {
                    // TODO: cancellation handling
                    progress.Report(new StatusBarProgressData(Resources.Info_MarkdownSendingInputFile.FormatInvariant(Path.GetFileName(inputFilePath)), 0));

                    var rmd = await fts.SendFileAsync(inputFilePath, true, null, CancellationToken.None);

                    progress.Report(new StatusBarProgressData(Resources.Info_MarkdownPublishingFile.FormatInvariant(Path.GetFileName(inputFilePath)), 1));

                    var publishResult = await session.EvaluateAsync <ulong>($"rtvs:::rmarkdown_publish(blob_id = {rmd.Id}, output_format = {format.ToRStringLiteral()}, encoding = 'cp{codePage}')", REvaluationKind.Normal);

                    progress.Report(new StatusBarProgressData(Resources.Info_MarkdownGetOutputFile.FormatInvariant(Path.GetFileName(outputFilePath)), 2));
                    await fts.FetchFileAsync(new RBlobInfo(publishResult), outputFilePath, true, null, CancellationToken.None);

                    progress.Report(new StatusBarProgressData(Resources.Info_MarkdownPublishComplete.FormatInvariant(Path.GetFileName(outputFilePath)), 3));
                }
            }
        }
Пример #6
0
        private async Task <bool> SendToRemoteWorkerAsync(IEnumerable <string> files, string projectDir, string projectName, string remotePath, IVsStatusbar statusBar)
        {
            await TaskUtilities.SwitchToBackgroundThread();

            string currentStatusText;

            statusBar.GetText(out currentStatusText);

            var  workflow     = _interactiveWorkflowProvider.GetOrCreate();
            var  outputWindow = workflow.ActiveWindow.InteractiveWindow;
            uint cookie       = 0;

            try {
                var session = workflow.RSession;
                statusBar.SetText(Resources.Info_CompressingFiles);
                statusBar.Progress(ref cookie, 1, "", 0, 0);

                int    count = 0;
                uint   total = (uint)files.Count() * 2; // for compressing and sending
                string compressedFilePath = string.Empty;
                await Task.Run(() => {
                    compressedFilePath = _fs.CompressFiles(files, projectDir, new Progress <string>((p) => {
                        Interlocked.Increment(ref count);
                        statusBar.Progress(ref cookie, 1, string.Format(Resources.Info_CompressingFile, Path.GetFileName(p)), (uint)count, total);
                        string dest = p.MakeRelativePath(projectDir).ProjectRelativePathToRemoteProjectPath(remotePath, projectName);
                        _appShell.DispatchOnUIThread(() => {
                            outputWindow.WriteLine(string.Format(Resources.Info_LocalFilePath, p));
                            outputWindow.WriteLine(string.Format(Resources.Info_RemoteFilePath, dest));
                        });
                    }), CancellationToken.None);
                    statusBar.Progress(ref cookie, 0, "", 0, 0);
                });

                using (var fts = new DataTransferSession(session, _fs)) {
                    cookie = 0;
                    statusBar.SetText(Resources.Info_TransferringFiles);

                    total = (uint)_fs.FileSize(compressedFilePath);

                    var remoteFile = await fts.SendFileAsync(compressedFilePath, true, new Progress <long>((b) => {
                        statusBar.Progress(ref cookie, 1, Resources.Info_TransferringFiles, (uint)b, total);
                    }));

                    statusBar.SetText(Resources.Info_ExtractingFilesInRHost);
                    await session.EvaluateAsync <string>($"rtvs:::save_to_project_folder({remoteFile.Id}, {projectName.ToRStringLiteral()}, '{remotePath.ToRPath()}')", REvaluationKind.Normal);

                    _appShell.DispatchOnUIThread(() => {
                        outputWindow.WriteLine(Resources.Info_TransferringFilesDone);
                    });
                }
            } catch (UnauthorizedAccessException uaex) {
                _appShell.ShowErrorMessage(string.Format(CultureInfo.InvariantCulture, Resources.Error_CannotTransferFile, uaex.Message));
            } catch (IOException ioex) {
                _appShell.ShowErrorMessage(string.Format(CultureInfo.InvariantCulture, Resources.Error_CannotTransferFile, ioex.Message));
            } catch (RHostDisconnectedException rhdex) {
                _appShell.DispatchOnUIThread(() => {
                    outputWindow.WriteErrorLine(Resources.Error_CannotTransferNoRSession.FormatInvariant(rhdex.Message));
                });
            } finally {
                statusBar.Progress(ref cookie, 0, "", 0, 0);
                statusBar.SetText(currentStatusText);
            }

            return(true);
        }
Пример #7
0
        private async Task SendToRemoteWorkerAsync(IEnumerable <string> files, string projectDir, string projectName, string remotePath, IProgress <ProgressDialogData> progress, CancellationToken ct)
        {
            await TaskUtilities.SwitchToBackgroundThread();

            var      workflow = _interactiveWorkflowProvider.GetOrCreate();
            IConsole console  = new InteractiveWindowConsole(workflow);

            try {
                var session = workflow.RSession;
                int count   = 0;
                int total   = files.Count();

                progress.Report(new ProgressDialogData(0, Resources.Info_CompressingFiles));

                if (ct.IsCancellationRequested)
                {
                    return;
                }

                List <string> paths = new List <string>();
                // Compression phase : 1 of 3 phases.
                string compressedFilePath = string.Empty;
                compressedFilePath = _fs.CompressFiles(files, projectDir, new Progress <string>((p) => {
                    Interlocked.Increment(ref count);
                    int step = (count * 100 / total) / 3; // divide by 3, this is for compression phase.
                    progress.Report(new ProgressDialogData(step, Resources.Info_CompressingFile.FormatInvariant(Path.GetFileName(p), _fs.FileSize(p))));
                    string dest = p.MakeRelativePath(projectDir).ProjectRelativePathToRemoteProjectPath(remotePath, projectName);
                    paths.Add($"{Resources.Info_LocalFilePath.FormatInvariant(p)}{Environment.NewLine}{Resources.Info_RemoteFilePath.FormatInvariant(dest)}");
                }), ct);

                if (ct.IsCancellationRequested)
                {
                    return;
                }

                using (var fts = new DataTransferSession(session, _fs)) {
                    long size = _fs.FileSize(compressedFilePath);

                    // Transfer phase: 2 of 3 phases
                    var remoteFile = await fts.SendFileAsync(compressedFilePath, true, new Progress <long>((b) => {
                        int step = 33;                                         // start with 33% to indicate compression phase is done.
                        step += (int)((((double)b / (double)size) * 100) / 3); // divide by 3, this is for transfer phase.
                        progress.Report(new ProgressDialogData(step, Resources.Info_TransferringFilesWithSize.FormatInvariant(b, size)));
                    }), ct);

                    if (ct.IsCancellationRequested)
                    {
                        return;
                    }

                    // Extract phase: 3 of 3 phases
                    // start with 66% completion to indicate compression and transfer phases are done.
                    progress.Report(new ProgressDialogData(66, Resources.Info_ExtractingFilesInRHost));
                    await session.EvaluateAsync <string>($"rtvs:::save_to_project_folder({remoteFile.Id}, {projectName.ToRStringLiteral()}, '{remotePath.ToRPath()}')", REvaluationKind.Normal, ct);

                    progress.Report(new ProgressDialogData(100, Resources.Info_TransferringFilesDone));

                    paths.ForEach((s) => console.WriteLine(s));
                }
            } catch (TaskCanceledException) {
                console.WriteErrorLine(Resources.Info_FileTransferCanceled);
            } catch (RHostDisconnectedException rhdex) {
                console.WriteErrorLine(Resources.Error_CannotTransferNoRSession.FormatInvariant(rhdex.Message));
            } catch (Exception ex) when(ex is UnauthorizedAccessException || ex is IOException)
            {
                _ui.ShowErrorMessage(Resources.Error_CannotTransferFile.FormatInvariant(ex.Message));
            }
        }