private void Handle() { var project = _pss.GetSelectedProject <IVsHierarchy>()?.GetDTEProject(); if (project != null) { var sprocFiles = project.GetSProcFiles(_pss); if (sprocFiles.Any()) { try { // Make sure all files are saved and up to date on disk. var dte = _appShell.GetGlobalService <DTE>(typeof(DTE)); dte.ExecuteCommand("File.SaveAll"); var publisher = new SProcPublisher(_appShell, _pss, _fs, _dacServicesProvider.GetDacPackageServices()); var settings = new SqlSProcPublishSettings(_settings); publisher.Publish(settings, sprocFiles); } catch (Exception ex) { _appShell.ShowErrorMessage(string.Format(CultureInfo.InvariantCulture, Resources.SqlPublish_PublishError, ex.Message)); } } else { _appShell.ShowErrorMessage(Resources.SqlPublishDialog_NoSProcFiles); } } }
public static async Task OpenDataCsvApp(IREvaluationResultInfo result, IApplicationShell appShell, IFileSystem fileSystem, IProcessServices processServices) { await appShell.SwitchToMainThreadAsync(); if (Interlocked.Exchange(ref _busy, 1) > 0) { return; } var workflow = appShell.ExportProvider.GetExportedValue <IRInteractiveWorkflowProvider>().GetOrCreate(); var session = workflow.RSession; var folder = GetTempCsvFilesFolder(); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } var pss = appShell.ExportProvider.GetExportedValue <IProjectSystemServices>(); var variableName = result.Name ?? _variableNameReplacement; var csvFileName = MakeCsvFileName(appShell, pss, variableName); var file = pss.GetUniqueFileName(folder, csvFileName, "csv", appendUnderscore: true); string currentStatusText; var statusBar = appShell.GetGlobalService <IVsStatusbar>(typeof(SVsStatusbar)); statusBar.GetText(out currentStatusText); try { statusBar.SetText(Resources.Status_WritingCSV); appShell.ProgressDialog.Show(async(p, ct) => await CreateCsvAndStartProcess(result, session, file, fileSystem, p), Resources.Status_WritingCSV, 100, 500); if (fileSystem.FileExists(file)) { processServices.Start(file); } } catch (Win32Exception ex) { appShell.ShowErrorMessage(string.Format(CultureInfo.InvariantCulture, Resources.Error_CannotOpenCsv, ex.Message)); } catch (IOException ex) { appShell.ShowErrorMessage(string.Format(CultureInfo.InvariantCulture, Resources.Error_CannotOpenCsv, ex.Message)); } finally { statusBar.SetText(currentStatusText); } Interlocked.Exchange(ref _busy, 0); }
private async Task SaveWorkspace(string file) { try { await _rSession.SaveWorkspaceAsync(file); } catch (RException ex) { var message = string.Format(CultureInfo.CurrentCulture, Resources.SaveWorkspaceFailedMessageFormat, file, ex.Message); _appShell.ShowErrorMessage(message); } catch (OperationCanceledException) { } }
public async Task <bool> TryHandleCommandAsync(IImmutableSet <IProjectTree> nodes, long commandId, bool focused, long commandExecuteOptions, IntPtr variantArgIn, IntPtr variantArgOut) { if (commandId == RPackageCommandId.icmdSourceSelectedFiles || commandId == RPackageCommandId.icmdSourceSelectedFilesWithEcho) { bool echo = commandId == RPackageCommandId.icmdSourceSelectedFilesWithEcho; IFileSystem fs = new FileSystem(); IEnumerable <string> rFiles = Enumerable.Empty <string>(); var workflow = _interactiveWorkflowProvider.GetOrCreate(); try { var session = workflow.RSession; if (session.IsRemote) { var files = nodes.GetSelectedNodesPaths().Where(x => Path.GetExtension(x).EqualsIgnoreCase(RContentTypeDefinition.FileExtension) && fs.FileExists(x)); var properties = _configuredProject.Services.ExportProvider.GetExportedValue <ProjectProperties>(); string projectDir = Path.GetDirectoryName(_configuredProject.UnconfiguredProject.FullPath); string projectName = properties.GetProjectName(); string remotePath = await properties.GetRemoteProjectPathAsync(); await SendToRemoteAsync(files, projectDir, projectName, remotePath); rFiles = files.Select(p => p.MakeRelativePath(projectDir).ProjectRelativePathToRemoteProjectPath(remotePath, projectName)); } else { rFiles = nodes.GetSelectedNodesPaths().Where(x => Path.GetExtension(x).EqualsIgnoreCase(RContentTypeDefinition.FileExtension) && fs.FileExists(x)); } workflow.Operations.SourceFiles(rFiles, echo); } catch (IOException ex) { _appShell.ShowErrorMessage(string.Format(CultureInfo.InvariantCulture, Resources.Error_CannotTransferFile, ex.Message)); } catch (RHostDisconnectedException) { workflow.ActiveWindow.InteractiveWindow.WriteErrorLine(Resources.Error_CannotTransferNoRSession); } return(true); } return(false); }
public static async Task OpenDataCsvApp(IREvaluationResultInfo result, IApplicationShell appShell, IFileSystem fileSystem, IProcessServices processServices) { await appShell.SwitchToMainThreadAsync(); if (Interlocked.Exchange(ref _busy, 1) > 0) { return; } var workflow = appShell.ExportProvider.GetExportedValue<IRInteractiveWorkflowProvider>().GetOrCreate(); var session = workflow.RSession; var folder = GetTempCsvFilesFolder(); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } var pss = appShell.ExportProvider.GetExportedValue<IProjectSystemServices>(); var variableName = result.Name ?? _variableNameReplacement; var csvFileName = MakeCsvFileName(appShell, pss, variableName); var file = pss.GetUniqueFileName(folder, csvFileName, "csv", appendUnderscore: true); string currentStatusText; var statusBar = appShell.GetGlobalService<IVsStatusbar>(typeof(SVsStatusbar)); statusBar.GetText(out currentStatusText); try { statusBar.SetText(Resources.Status_WritingCSV); appShell.ProgressDialog.Show(async (p, ct) => await CreateCsvAndStartProcess(result, session, file, fileSystem, p, ct), Resources.Status_WritingCSV, 100, 500); if (fileSystem.FileExists(file)) { processServices.Start(file); } } catch (Exception ex) when (ex is Win32Exception || ex is IOException || ex is UnauthorizedAccessException) { appShell.ShowErrorMessage(string.Format(CultureInfo.InvariantCulture, Resources.Error_CannotOpenCsv, ex.Message)); } finally { statusBar.SetText(currentStatusText); } Interlocked.Exchange(ref _busy, 0); }
protected override void Handle() { // Note that we go through the VS windows rather than the visual components. // Visual components only exist for tool windows that are initialized. // Tool windows that have a visible tab but haven't clicked on yet are not initialized. try { var frames = _shell.EnumerateWindows( __WindowFrameTypeFlags.WINDOWFRAMETYPE_Tool | __WindowFrameTypeFlags.WINDOWFRAMETYPE_AllStates, typeof(PlotDeviceWindowPane).GUID); foreach (var frame in frames) { if (frame.IsVisible() == VSConstants.S_OK) { frame.CloseFrame((int)__FRAMECLOSE.FRAMECLOSE_NoSave); } } } catch (Exception ex) when(!ex.IsCriticalException()) { _appShell.ShowErrorMessage(ex.Message); } }
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); }
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) { _appShell.ShowErrorMessage(Resources.Error_CannotTransferFile.FormatInvariant(ex.Message)); } }