Beispiel #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);
                    });
                }
            }
        }
Beispiel #2
0
        private async Task<bool> SendToRemoteWorkerAsync(IEnumerable<string> files, string projectDir, string projectName, string remotePath, IVsStatusbar statusBar, CancellationToken cancellationToken) {
            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);
                    }), cancellationToken);

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

                    _appShell.DispatchOnUIThread(() => {
                        outputWindow.WriteLine(Resources.Info_TransferringFilesDone);
                    });
                }
            } catch(Exception ex) when (ex is UnauthorizedAccessException || ex is IOException) {
                _appShell.ShowErrorMessage(Resources.Error_CannotTransferFile.FormatInvariant(ex.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;
        }
Beispiel #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);
                    });
                }
            }
        }
        public override void DeployDot()
        {
            try
            {
                int    fFrozen = 1;
                string msg;

                if (m_statusBar != null &&
                    m_statusBar.IsFrozen(out fFrozen) == Utility.COM_HResults.S_OK &&
                    fFrozen != 1 &&
                    m_statusBar.GetText(out msg) == Utility.COM_HResults.S_OK
                    )
                {
                    m_statusBar.SetText(msg + ".");
                }
            }
            catch (InvalidOperationException)
            {
            }
        }
Beispiel #5
0
        //<Snippet1>
        void FeedbackRegionExample()
        {
            IVsStatusbar statusBar =
                (IVsStatusbar)GetService(typeof(SVsStatusbar));
            int frozen;

            statusBar.IsFrozen(out frozen);

            if (frozen == 0)
            {
                // Set the status bar text and make its display static.
                statusBar.SetText("Here's some static text.");
                statusBar.FreezeOutput(1);

                // Retrieve the status bar text.
                string text;
                statusBar.GetText(out text);
                System.Windows.Forms.MessageBox.Show(text);

                // Clear the status bar text.
                statusBar.FreezeOutput(0);
                statusBar.Clear();
            }
        }
Beispiel #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);
        }