Exemplo n.º 1
0
        public override CommandResult Invoke(Guid group, int id, object inputArg, ref object outputArg)
        {
            if (!TaskAvailable())
            {
                return(CommandResult.Disabled);
            }

            IMarkdownFlavorPublishHandler flavorHandler = GetFlavorHandler(TextView.TextBuffer);

            if (flavorHandler != null)
            {
                if (!InstallPackages.IsInstalled(flavorHandler.RequiredPackageName, 5000, RToolsSettings.Current.RBasePath))
                {
                    VsAppShell.Current.ShowErrorMessage(string.Format(CultureInfo.InvariantCulture, Resources.Error_PackageMissing, flavorHandler.RequiredPackageName));
                    return(CommandResult.Disabled);
                }

                if (!CheckPrerequisites())
                {
                    return(CommandResult.Disabled);
                }

                // Save the file
                var document = EditorExtensions.FindInProjectedBuffers <MdEditorDocument>(TextView.TextBuffer, MdContentTypeDefinition.ContentType);
                var tb       = document.TextBuffer;
                if (!tb.CanBeSavedInCurrentEncoding())
                {
                    if (MessageButtons.No == VsAppShell.Current.ShowMessage(Resources.Warning_SaveInUtf8, MessageButtons.YesNo))
                    {
                        return(CommandResult.Executed);
                    }
                    tb.Save(new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
                }
                else
                {
                    tb.Save();
                }

                var inputFilePath = tb.GetFilePath();
                _outputFilePath = Path.ChangeExtension(inputFilePath, FileExtension);

                try {
                    File.Delete(_outputFilePath);
                } catch (IOException ex) {
                    VsAppShell.Current.ShowErrorMessage(ex.Message);
                    return(CommandResult.Executed);
                }

                inputFilePath = inputFilePath.Replace('\\', '/');
                string outputFilePath = _outputFilePath.Replace('\\', '/');

                string arguments = flavorHandler.GetCommandLine(inputFilePath, outputFilePath, Format, tb.GetEncoding());
                var    session   = _workflowProvider.GetOrCreate().RSession;
                _lastCommandTask = session.ExecuteAsync(arguments).ContinueWith(t => LaunchViewer());
            }
            return(CommandResult.Executed);
        }
Exemplo n.º 2
0
        public void InstallPackages_BaseTest()
        {
            var          svl  = new SupportedRVersionRange(3, 2, 3, 2);
            RInstallData data = RInstallation.GetInstallationData(string.Empty, svl);

            data.Status.Should().Be(RInstallStatus.OK);
            bool result = InstallPackages.IsInstalled("base", Int32.MaxValue, data.Path);

            result.Should().BeTrue();
        }
Exemplo n.º 3
0
        public void InstallPackages_BaseTest()
        {
            RInstallData data = RInstallation.GetInstallationData(string.Empty,
                                                                  SupportedRVersionList.MinMajorVersion, SupportedRVersionList.MinMinorVersion,
                                                                  SupportedRVersionList.MaxMajorVersion, SupportedRVersionList.MaxMinorVersion);

            data.Status.Should().Be(RInstallStatus.OK);
            bool result = InstallPackages.IsInstalled("base", Int32.MaxValue, data.Path);

            result.Should().BeTrue();
        }
Exemplo n.º 4
0
        public override CommandResult Invoke(Guid group, int id, object inputArg, ref object outputArg)
        {
            if (!TaskAvailable())
            {
                return(CommandResult.Disabled);
            }

            IMarkdownFlavorPublishHandler flavorHandler = GetFlavorHandler(TextView.TextBuffer);

            if (flavorHandler != null)
            {
                if (!InstallPackages.IsInstalled(flavorHandler.RequiredPackageName, 5000, RToolsSettings.Current.RBasePath))
                {
                    VsAppShell.Current.ShowErrorMessage(string.Format(CultureInfo.InvariantCulture, Resources.Error_PackageMissing, flavorHandler.RequiredPackageName));
                    return(CommandResult.Disabled);
                }

                // Save the file
                TextView.TextBuffer.Save();
                var inputFilePath = TextView.TextBuffer.GetFilePath();

                var buffer = new StringBuilder(NativeMethods.MAX_PATH);
                NativeMethods.GetShortPathName(inputFilePath, buffer, NativeMethods.MAX_PATH);

                inputFilePath   = buffer.ToString();
                _outputFilePath = Path.ChangeExtension(inputFilePath, FileExtension);

                try {
                    File.Delete(_outputFilePath);
                } catch (IOException ex) {
                    PublishLog.Current.WriteFormatAsync(MessageCategory.Error, Resources.Error_CannotDeleteFile, _outputFilePath, ex.Message);
                    return(CommandResult.Executed);
                }

                inputFilePath = inputFilePath.Replace('\\', '/');
                string outputFilePath = _outputFilePath.Replace('\\', '/');

                string arguments = flavorHandler.GetCommandLine(inputFilePath, outputFilePath, Format);

                _lastCommand = RCommand.ExecuteRExpressionAsync(arguments, PublishLog.Current, RToolsSettings.Current.RBasePath);
                _lastCommand.Task.ContinueWith((Task t) => LaunchViewer(t));
            }
            return(CommandResult.Executed);
        }