Exemplo n.º 1
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));
            }
        }
Exemplo n.º 2
0
        public static IEnumerable <MenuCommand> GetCommands(IServiceContainer services)
        {
            var interactiveWorkflowProvider = services.GetService <IRInteractiveWorkflowVisualProvider>();
            var interactiveWorkflow         = interactiveWorkflowProvider.GetOrCreate();
            var projectServiceAccessor      = services.GetService <IProjectServiceAccessor>();
            var textViewTracker             = services.GetService <IActiveWpfTextViewTracker>();
            var replTracker         = services.GetService <IActiveRInteractiveWindowTracker>();
            var debuggerModeTracker = services.GetService <IDebuggerModeTracker>();
            var pss      = services.GetService <IProjectSystemServices>();
            var pcsp     = services.GetService <IProjectConfigurationSettingsProvider>();
            var dbcs     = services.GetService <IDbConnectionService>();
            var settings = services.GetService <IRSettings>();
            var ui       = services.UI();
            var shell    = services.GetService <ICoreShell>();
            var console  = new InteractiveWindowConsole(interactiveWorkflow);

            return(new List <MenuCommand> {
                new GoToOptionsCommand(services),
                new GoToEditorOptionsCommand(services),
                new ImportRSettingsCommand(services),
                new InstallRClientCommand(services),
                new SurveyNewsCommand(services),
                new SetupRemoteCommand(),

                new ReportIssueCommand(services),
                new SendSmileCommand(services),
                new SendFrownCommand(services),

                CreateRCmdSetCommand(RPackageCommandId.icmdRDocsIntroToR, new OpenDocumentationCommand(interactiveWorkflow, OnlineDocumentationUrls.CranIntro, LocalDocumentationPaths.CranIntro)),
                CreateRCmdSetCommand(RPackageCommandId.icmdRDocsDataImportExport, new OpenDocumentationCommand(interactiveWorkflow, OnlineDocumentationUrls.CranData, LocalDocumentationPaths.CranData)),
                CreateRCmdSetCommand(RPackageCommandId.icmdRDocsWritingRExtensions, new OpenDocumentationCommand(interactiveWorkflow, OnlineDocumentationUrls.CranExtensions, LocalDocumentationPaths.CranExtensions)),
                CreateRCmdSetCommand(RPackageCommandId.icmdRDocsTaskViews, new OpenDocumentationCommand(interactiveWorkflow, OnlineDocumentationUrls.CranViews)),
                CreateRCmdSetCommand(RPackageCommandId.icmdRtvsDocumentation, new OpenDocumentationCommand(interactiveWorkflow, OnlineDocumentationUrls.RtvsDocumentation)),
                CreateRCmdSetCommand(RPackageCommandId.icmdRtvsSamples, new OpenDocumentationCommand(interactiveWorkflow, OnlineDocumentationUrls.RtvsSamples)),
                CreateRCmdSetCommand(RPackageCommandId.icmdCheckForUpdates, new OpenDocumentationCommand(interactiveWorkflow, OnlineDocumentationUrls.CheckForRtvsUpdates)),
                CreateRCmdSetCommand(RPackageCommandId.icmdMicrosoftRProducts, new OpenDocumentationCommand(interactiveWorkflow, OnlineDocumentationUrls.MicrosoftRProducts)),

                new LoadWorkspaceCommand(shell, interactiveWorkflow, projectServiceAccessor),
                new SaveWorkspaceCommand(shell, interactiveWorkflow, projectServiceAccessor),

                new AttachDebuggerCommand(interactiveWorkflow),
                new AttachToRInteractiveCommand(interactiveWorkflow),
                new StopDebuggingCommand(interactiveWorkflow),
                new ContinueDebuggingCommand(interactiveWorkflow),
                new StepOverCommand(interactiveWorkflow),
                new StepOutCommand(interactiveWorkflow),
                new StepIntoCommand(interactiveWorkflow),

                CreateRCmdSetCommand(RPackageCommandId.icmdSourceRScript, new SourceRScriptCommand(interactiveWorkflow, textViewTracker, false)),
                CreateRCmdSetCommand(RPackageCommandId.icmdSourceRScriptWithEcho, new SourceRScriptCommand(interactiveWorkflow, textViewTracker, true)),

                new RunShinyAppCommand(interactiveWorkflow),
                new StopShinyAppCommand(interactiveWorkflow),

                CreateRCmdSetCommand(RPackageCommandId.icmdInterruptR, new InterruptRCommand(interactiveWorkflow, debuggerModeTracker)),
                CreateRCmdSetCommand(RPackageCommandId.icmdTerminateR, new TerminateRCommand(interactiveWorkflow, ui)),
                CreateRCmdSetCommand(RPackageCommandId.icmdSessionInformation, new SessionInformationCommand(interactiveWorkflow, console)),
                CreateRCmdSetCommand(RPackageCommandId.icmdDeleteProfile, new DeleteProfileCommand(interactiveWorkflow)),

                new ResetReplCommand(interactiveWorkflow),
                new PrevHistoryReplCommand(interactiveWorkflow),
                new NextHistoryReplCommand(interactiveWorkflow),

                // Directory management
                new SetDirectoryToSourceCommand(interactiveWorkflow, textViewTracker),
                new SetDirectoryToProjectCommand(interactiveWorkflow, pss),
                new SelectWorkingDirectoryCommand(interactiveWorkflow),

                new ImportDataSetTextFileCommand(services, interactiveWorkflow.RSession),
                new ImportDataSetUrlCommand(services, interactiveWorkflow.RSession),
                new DeleteAllVariablesCommand(interactiveWorkflow),
                new AddDbConnectionCommand(dbcs, pss, pcsp, interactiveWorkflow),
                new AddDsnCommand(shell, interactiveWorkflow),
                new ManageDsnCommand(shell, interactiveWorkflow),

                // Window commands
                new ShowRInteractiveWindowsCommand(interactiveWorkflowProvider),
                new ShowVariableWindowCommand(),

                new ShowToolWindowCommand <HelpWindowPane>(RPackageCommandId.icmdShowHelpWindow),
                new ShowToolWindowCommand <HistoryWindowPane>(RPackageCommandId.icmdShowHistoryWindow),
                new ShowToolWindowCommand <ConnectionManagerWindowPane>(RPackageCommandId.icmdShowConnectionsWindow),
                new ShowToolWindowCommand <PackageManagerWindowPane>(RPackageCommandId.icmdShowPackagesWindow),
                new ShowToolWindowCommand <PlotHistoryWindowPane>(RPackageCommandId.icmdPlotHistoryWindow),

                new ShowHelpOnCurrentCommand(interactiveWorkflow, textViewTracker, replTracker),
                new SearchWebForCurrentCommand(interactiveWorkflow, textViewTracker, replTracker),
                new GotoEditorWindowCommand(textViewTracker, services),
                new GotoSolutionExplorerCommand(shell),

                // Plot commands
                CreateRCmdSetCommand(RPackageCommandId.icmdNewPlotWindow, new PlotDeviceNewCommand(interactiveWorkflow)),
                CreateRCmdSetCommand(RPackageCommandId.icmdShowPlotWindow, new ShowMainPlotWindowCommand(interactiveWorkflow)),
                CreateRCmdSetCommand(RPackageCommandId.icmdPlotWindowsDynamicStart, new ShowPlotWindowCommand(shell, interactiveWorkflow)),
                new HideAllPlotWindowsCommand(shell),

                // Connection manager commands
                CreateRCmdSetCommand(RPackageCommandId.icmdReconnect, new ReconnectCommand(interactiveWorkflow)),
                CreateRCmdSetCommand(RPackageCommandId.icmdMruConnectionsDynamicStart, new SwitchToConnectionCommand(interactiveWorkflow, settings))
            });
        }