Beispiel #1
0
 public void Install()
 {
     if (InstallPackages.Count > 0)
     {
         InstallPackage installPackage = InstallPackages.Dequeue();
         installPackage.SetEventOnFinished((_installPackage) =>
         {
             InstallPackage iinstallPackage = _installPackage as InstallPackage;
             if (iinstallPackage.IsSucess)
             {
                 if (InstallPackages.Count > 0)
                 {
                     Install();
                 }
                 else
                 {
                     IsSucess = true;
                     App.MainThread.Post(OnFinished, this);
                 }
             }
             else
             {
                 IsSucess = false;
                 InstallPackages.Clear();
                 App.MainThread.Post(OnFinished, this);
             }
         });
     }
 }
Beispiel #2
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);
        }
Beispiel #3
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();
        }
Beispiel #4
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();
        }
Beispiel #5
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);
        }
        public InstallService(string extractPath, Package installPackage = null, Package uninstallPackage = null, Package isInstalledPackage = null)
        {
            Mock <IInstallService> mock = new Mock <IInstallService>();

            mock
            .Setup(i => i.Install(It.Is <IPackage>(p => p == InstallPackages[InstallCalled])))
            .Callback(() => InstallCalled.Increment());

            mock
            .Setup(i => i.Uninstall(It.Is <IPackage>(p => p == UninstallPackages[UninstallCalled])))
            .Callback(() => UninstallCalled.Increment());

            mock
            .Setup(i => i.IsInstalled(It.Is <IPackage>(p => p == IsInstalledPackages[IsInstalledCalled])))
            .Callback(() => IsInstalledCalled.Increment())
            .Returns(true);

            mock
            .Setup(i => i.Path)
            .Returns(() => extractPath);

            if (installPackage != null)
            {
                InstallPackages.Add(installPackage.Object);
            }

            if (uninstallPackage != null)
            {
                UninstallPackages.Add(uninstallPackage.Object);
            }

            if (isInstalledPackage != null)
            {
                IsInstalledPackages.Add(isInstalledPackage.Object);
            }

            Object = mock.Object;
        }
Beispiel #7
0
        public void Initialize(string nugetApiKey)
        {
            NugetApiKey = nugetApiKey;
            var outputDir =
                OutputDirectory ?? Path.Combine(Path.GetTempPath(), "ursa", DateTime.Now.Ticks.ToString());

            var ursaAbstractionsPackage = new PackageInfo
            {
                PackageName    = "Ubaba.Abstractions",
                PackageVersion = "0.0.1-beta2"
            };
            var annotationsPackage = new PackageInfo
            {
                PackageName    = "System.ComponentModel.Annotations",
                PackageVersion = "4.7.0"
            };

            if (InstallPackages.All(p => p.PackageName != ursaAbstractionsPackage.PackageName))
            {
                InstallPackages.Add(ursaAbstractionsPackage);
            }

            if (InstallPackages.All(p => p.PackageName != annotationsPackage.PackageName))
            {
                InstallPackages.Add(annotationsPackage);
            }

            var nugetPackageDir = Path.Combine(outputDir, "nuget");

            OutputDir           = outputDir;
            ClientSdkCodePath   = Path.Combine(outputDir, $"{ClassName}.cs");
            ClientSdkCsprojPath = Path.Combine(outputDir, $"{Package.PackageName}.csproj");
            NugetPackageDir     = nugetPackageDir;
            NugetPackagePath    = Path.Combine(nugetPackageDir, $"{Package.PackageName}.{Package.PackageVersion}.nupkg");
            ApiExceptionFullName ??= typeof(UrsaApiException).FullName;
            ApiResponseFullName ??= typeof(NSwagApiResponse).FullName;
        }