public IDisposable AddItem(UIElement element) { _shell.AssertIsOnMainThread(); EnsureItemsControlCreated(); _itemsControl.Items.Insert(0, element); return(Disposable.Create(() => _shell.DispatchOnUIThread(() => _itemsControl.Items.Remove(element)))); }
private void TargetTypeList_SelectionChanged(object sender, SelectionChangedEventArgs e) { _model.SelectTargetTypeAsync(TargetTypeList.SelectedIndex).ContinueWith(t => { _appShell.DispatchOnUIThread(() => { TargetList.SelectedIndex = _model.SelectedTargetIndex; _model.SelectTarget(TargetList.SelectedIndex); }); }).DoNotWait(); }
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); }); } } }
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 { // TODO: progress and cancellation handling appShell.DispatchOnUIThread(() => { statusBar?.Progress(ref cookie, 1, Resources.Info_MarkdownSendingInputFile.FormatInvariant(Path.GetFileName(inputFilePath)), 0, 3); }); var rmd = await fts.SendFileAsync(inputFilePath, true, null, CancellationToken.None); 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, true, null, CancellationToken.None); 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); }); } } }
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); }