Beispiel #1
0
        static void Main(string[] args)
        {
            command = InstallCommand.None;
            silent = false;

            foreach(string arg in args) {
                if (arg.ToLower() == "/silent") {
                    silent = true;
                } else if (arg.ToLower() == "/install") {
                    command = InstallCommand.Install;
                } else if (arg.ToLower() == "/uninstall") {
                    command = InstallCommand.Uninstall;
                }
            }

            if (!Environment.UserInteractive) silent = true;

            switch (command) {
                case InstallCommand.Install:    Install();
                                                break;
                case InstallCommand.Uninstall:  Uninstall();
                                                break;
                default:                        ServiceBase.Run(new ServiceBase[] {new Service()});
                                                break;
            }
        }
Beispiel #2
0
        private void InstallPackageLocally(string packageId, string workDirectory)
        {
            var install = new InstallCommand(RepositoryFactory, SourceProvider);

            install.Arguments.Add(packageId);
            install.OutputDirectory = workDirectory;
            install.Console         = Console;
            foreach (string source in Sources)
            {
                install.Source.Add(source);
            }
            if (!string.IsNullOrEmpty(Version))
            {
                install.Version = Version;
            }

            install.ExecuteCommand();
        }
        public void CallInstallersPerformOperationMethod_WhenInvoked()
        {
            // arrange
            var installerMock = new Mock <IInstaller <IPackage> >();
            var packageStub   = new Mock <IPackage>();

            installerMock.Setup(x => x.Operation);
            installerMock.Setup(
                x => x.PerformOperation(It.Is <IPackage>(y => y == packageStub.Object)));

            var installCommand = new InstallCommand(installerMock.Object, packageStub.Object);

            // act
            installCommand.Execute();

            // assert
            installerMock.Verify(x => x.PerformOperation(It.Is <IPackage>(y => y == packageStub.Object)), Times.Once);
        }
Beispiel #4
0
        public PackageManagerDialogViewModel()
            : base("Packages")
        {
            _packageManager = new PackageManager(this);

            AvailablePackages = new ObservableCollection <IPackageSearchMetadata>();

            Dispatcher.UIThread.InvokeAsync(async() =>
            {
                InvalidateInstalledPackages();

                await DownloadCatalog();
            });

            InstallCommand = ReactiveCommand.Create();
            InstallCommand.Subscribe(async _ =>
            {
                await PackageManager.InstallPackage(selectedPackage.Identity.Id, selectedPackage.Identity.Version.ToFullString());

                InvalidateInstalledPackages();
            });

            UninstallCommand = ReactiveCommand.Create();
            UninstallCommand.Subscribe(async _ =>
            {
                if (SelectedInstalledPackage != null)
                {
                    await PackageManager.UninstallPackage(SelectedInstalledPackage.Model.Id, SelectedInstalledPackage.Model.Version.ToNormalizedString());

                    InvalidateInstalledPackages();
                }
            });

            OKCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.EnableInterface));

            OKCommand.Subscribe(_ =>
            {
                ShellViewModel.Instance.InvalidateCodeAnalysis();
                Close();
            });

            EnableInterface = true;
        }
Beispiel #5
0
        public PackageManagerDialogViewModel()
            : base("Packages")
        {
            AvailablePackages = new ObservableCollection <PackageReference>();

            DownloadCatalog();

            InstallCommand = ReactiveCommand.Create();
            InstallCommand.Subscribe(async o =>
            {
                EnableInterface = false;

                try
                {
                    await SelectedPackageIndex.Synchronize(SelectedTag, this);

                    //if (fullPackage.Install())
                    //{
                    //    Status = "Package Installed Successfully.";
                    //}
                    //else
                    //{
                    //    Status = "An error occurred trying to install package.";
                    //}
                }
                catch (Exception e)
                {
                    Status = "An error occurred trying to install package. " + e.Message;
                }

                EnableInterface = true;
            });

            OKCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.EnableInterface));

            OKCommand.Subscribe(_ =>
            {
                ShellViewModel.Instance.InvalidateCodeAnalysis();
                Close();
            });

            EnableInterface = true;
        }
 private void DetectInstalledPackage()
 {
     if (Configurator.IsApplicationInstalled(Settings.ApplicationName))
     {
         UninstallEnabled = true;
         view.Dispatcher.Invoke(() =>
         {
             UninstallCommand?.RaiseCanExecuteChanged();
         });
     }
     else
     {
         InstallEnabled = true;
         view.Dispatcher.Invoke(() =>
         {
             InstallCommand?.RaiseCanExecuteChanged();
         });
     }
 }
Beispiel #7
0
            public void MigratesTheFileSystem(
                [Frozen] Mock <IFileSystem> fileSystem, [Frozen] Mock <IFileSystemMigrator> fileSystemMigrator)
            {
                // Arrange
                var sut = new InstallCommand(
                    null,
                    null,
                    false,
                    fileSystem.Object,
                    new Mock <IPackageAssemblyResolver>().Object,
                    new Mock <IPackageInstaller>().Object,
                    new Mock <ILog>().Object,
                    fileSystemMigrator.Object);

                // Act
                sut.Execute();

                // Assert
                fileSystemMigrator.Verify(m => m.Migrate(), Times.Once);
            }
Beispiel #8
0
        public async Task Returns_fail_count_as_exit_code()
        {
            _configServiceMock.Setup(m => m.GetConfigurationAsync(It.IsAny <CommandOptions>()))
            .ReturnsAsync(SampleProjects.ConfigurationDefault)
            .Verifiable();
            _runnerServiceMock.Setup(m => m.InstallAsync(It.IsAny <IList <Project> >(), It.IsAny <CommandOptions>(), It.IsAny <CancellationToken>()))
            .Callback((IList <Project> projects, CommandOptions options, CancellationToken token) =>
            {
                projects[0].Processes.Add(new AppProcess(new Process(), AppTask.Install, AppStatus.Failure));
            })
            .Returns((IList <Project> projects, CommandOptions options, CancellationToken token) => Task.FromResult(projects))
            .Verifiable();

            InstallCommand command = CreateCommand();

            int testProjectCount = await command.OnExecute();

            Assert.Equal(1, testProjectCount);

            _configServiceMock.Verify();
            _runnerServiceMock.Verify();
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            command = InstallCommand.None;
            silent  = false;

            foreach (string arg in args)
            {
                if (arg.ToLower() == "/silent")
                {
                    silent = true;
                }
                else if (arg.ToLower() == "/install")
                {
                    command = InstallCommand.Install;
                }
                else if (arg.ToLower() == "/uninstall")
                {
                    command = InstallCommand.Uninstall;
                }
            }

            if (!Environment.UserInteractive)
            {
                silent = true;
            }

            switch (command)
            {
            case InstallCommand.Install:    Install();
                break;

            case InstallCommand.Uninstall:  Uninstall();
                break;

            default:                        ServiceBase.Run(new ServiceBase[] { new Service() });
                break;
            }
        }
        public void TestInstall_WithExistingLibmanJson_SpecificFiles()
        {
            var command = new InstallCommand(HostEnvironment);

            command.Configure(null);

            string initialContent = @"{
  ""version"": ""1.0"",
  ""defaultProvider"": ""cdnjs"",
  ""defaultDestination"": ""wwwroot"",
  ""libraries"": [
  ]
}";

            File.WriteAllText(Path.Combine(WorkingDir, "libman.json"), initialContent);

            int result = command.Execute("[email protected]", "--files", "jquery.min.js");

            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "libman.json")));

            string actualText   = File.ReadAllText(Path.Combine(WorkingDir, "libman.json"));
            string expectedText = @"{
  ""version"": ""1.0"",
  ""defaultProvider"": ""cdnjs"",
  ""defaultDestination"": ""wwwroot"",
  ""libraries"": [
    {
      ""library"": ""[email protected]"",
      ""files"": [
        ""jquery.min.js""
      ]
    }
  ]
}";

            Assert.AreEqual(StringHelper.NormalizeNewLines(expectedText), StringHelper.NormalizeNewLines(actualText));
        }
        public void TestInstall_CleanDirectory()
        {
            var command = new InstallCommand(HostEnvironment);

            command.Configure(null);

            int result = command.Execute("[email protected]", "--provider", "cdnjs", "--destination", "wwwroot");

            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "libman.json")));

            string text         = File.ReadAllText(Path.Combine(WorkingDir, "libman.json"));
            string expectedText = @"{
  ""version"": ""1.0"",
  ""defaultProvider"": ""cdnjs"",
  ""libraries"": [
    {
      ""library"": ""[email protected]"",
      ""destination"": ""wwwroot""
    }
  ]
}";

            Assert.AreEqual(StringHelper.NormalizeNewLines(expectedText), StringHelper.NormalizeNewLines(text));
        }
        public void TestUpdateCommand_AlreadyUpToDate()
        {
            var command = new UpdateCommand(HostEnvironment);

            command.Configure(null);

            string contents = @"{
  ""version"": ""1.0"",
  ""defaultProvider"": ""cdnjs"",
  ""defaultDestination"": ""wwwroot"",
  ""libraries"": [
  ]
}";

            string libmanjsonPath = Path.Combine(WorkingDir, "libman.json");

            File.WriteAllText(libmanjsonPath, contents);

            var installCommand = new InstallCommand(HostEnvironment);

            installCommand.Configure(null);
            installCommand.Execute("jquery --files jquery.min.js --files jquery.js".Split(' '));

            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js")));
            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js")));

            int result = command.Execute("jquery");

            Assert.AreEqual(0, result);
            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js")));
            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js")));

            var logger = HostEnvironment.Logger as TestLogger;

            Assert.AreEqual("The library \"jquery\" is already up to date", logger.Messages.Last().Value);
        }
        private void InstallPackageLocally(string packageId, string workDirectory)
        {
            InstallCommand install = new InstallCommand(_repositoryFactory, _sourceProvider);
            install.Arguments.Add(packageId);
            install.OutputDirectory = workDirectory;
            install.Console = this.Console;
            foreach (var source in Source)
            {
                install.Source.Add(source);
            }
            if (!string.IsNullOrEmpty(Version))
            {
                install.Version = Version;
            }

            install.ExecuteCommand();
        }
Beispiel #14
0
        public void TestNoResolverReturnsFalse()
        {
            InstallCommand installCommand = new InstallCommand("/", _mLogger.Object);

            Assert.False(installCommand.Execute());
        }
Beispiel #15
0
        public ICommand CreateCommand(ScriptCsArgs args)
        {
            if (args.ScriptName != null)
            {
                var executeCommand = new ExecuteScriptCommand(
                    args.ScriptName,
                    _scriptServiceRoot.FileSystem,
                    _scriptServiceRoot.Executor,
                    _scriptServiceRoot.ScriptPackResolver);

                if (args.Restore)
                {
                    var restoreCommand = new RestoreCommand(
                        args.ScriptName,
                        _scriptServiceRoot.FileSystem,
                        _scriptServiceRoot.PackageAssemblyResolver);

                    return new CompositeCommand(restoreCommand, executeCommand);
                }

                return executeCommand;
            }

            if (args.Install != null)
            {
                var installCommand = new InstallCommand(
                    args.Install,
                    args.AllowPreReleaseFlag,
                    _scriptServiceRoot.FileSystem,
                    _scriptServiceRoot.PackageAssemblyResolver,
                    _scriptServiceRoot.PackageInstaller);

                var restoreCommand = new RestoreCommand(
                    args.Install,
                    _scriptServiceRoot.FileSystem,
                    _scriptServiceRoot.PackageAssemblyResolver);

                return new CompositeCommand(installCommand, restoreCommand);
            }

            if (args.Clean)
            {
                var cleanCommand = new CleanCommand(
                    args.ScriptName,
                    _scriptServiceRoot.FileSystem,
                    _scriptServiceRoot.PackageAssemblyResolver);

                return cleanCommand;
            }

            if (args.Save)
            {
                return new SaveCommand(_scriptServiceRoot.PackageAssemblyResolver);
            }

            if (args.Version)
            {
                return new VersionCommand();
            }

            return new InvalidCommand();
        }
Beispiel #16
0
        static int Main(string[] args)
        {
            Logger logger = new Logger();
            var    app    = new CommandLineApplication();

            app.Name        = "dotnet get";
            app.FullName    = ".NET Core Tools Global Installer";
            app.Description = "Install and use command line tools built on .NET Core";
            app.HelpOption("-h|--help");
            app.VersionOption("-v|--version", GetAssemblyVersion());

            CommandOption verboseOption = app.Option("--verbose", "Enable verbose output", CommandOptionType.NoValue);

            app.OnExecute(() =>
            {
                app.ShowHelp();
                return(0);
            });

            app.Command("install", c =>
            {
                c.Description = "Installs a .NET Core tool";
                c.HelpOption("-h|--help");

                CommandArgument source = c.Argument("<SOURCE>", "The tool to install. Can be a NuGet package");

                c.OnExecute(() =>
                {
                    logger = new Logger(verboseOption.HasValue());
                    if (string.IsNullOrWhiteSpace(source.Value))
                    {
                        logger.LogError("<SOURCE> argument is required. Use -h|--help to see help");
                        return(1);
                    }

                    InstallCommand installCommand = new InstallCommand(source.Value, logger);
                    return(installCommand.Execute() ? 0 : 1);
                });
            });

            app.Command("update", c =>
            {
                c.Description = "Updates a .NET Core tool";
                c.HelpOption("-h|--help");

                CommandArgument source = c.Argument("<SOURCE>", "The tool to update.");

                c.OnExecute(() =>
                {
                    logger = new Logger(verboseOption.HasValue());
                    if (string.IsNullOrWhiteSpace(source.Value))
                    {
                        return(Update(logger) ? 0 : 1);
                    }

                    UpdateCommand updateCommand = new UpdateCommand(source.Value, logger);
                    return(updateCommand.Execute() ? 0 : 1);
                });
            });

            app.Command("list", c =>
            {
                c.Description = "Lists all installed .NET Core tools";
                c.HelpOption("-h|--help");

                c.OnExecute(() =>
                {
                    logger = new Logger(verboseOption.HasValue());
                    ListCommand listCommand = new ListCommand(logger);
                    return(listCommand.Execute() ? 0 : 1);
                });
            });

            app.Command("uninstall", c =>
            {
                c.Description = "Uninstalls a .NET Core tool";
                c.HelpOption("-h|--help");

                CommandArgument source = c.Argument("<SOURCE>", "The tool to uninstall.");

                c.OnExecute(() =>
                {
                    logger = new Logger(verboseOption.HasValue());
                    if (string.IsNullOrWhiteSpace(source.Value))
                    {
                        logger.LogError("<SOURCE> argument is required. Use -h|--help to see help");
                        return(1);
                    }

                    UninstallCommand uninstallCommand = new UninstallCommand(source.Value, logger);
                    return(uninstallCommand.Execute() ? 0 : 1);
                });
            });

            try
            {
                return(app.Execute(args));
            }
            catch (CommandParsingException ex)
            {
                logger.LogWarning(ex.Message);
                app.ShowHelp();
                return(1);
            }
        }