public static void AppendLogger(string loggerPath, IEnumerable <string> componentPaths, ILog log) { var baseDirectory = Path.GetDirectoryName(loggerPath); var loggerName = Path.GetFileName(loggerPath); var extractor = new ShellRunner(new ShellRunnerSettings("jar") { Arguments = $"-xf {loggerName} org", WorkingDirectory = baseDirectory }, log); var updateTasks = componentPaths.Select(x => { var filename = Path.GetFileName(x); var updater = new ShellRunner(new ShellRunnerSettings("jar") { Arguments = $"-uf {filename} org", WorkingDirectory = baseDirectory }, log); return(updater.RunAsync(TimeSpan.FromSeconds(30), CancellationToken.None)); }).ToArray(); extractor.Run(TimeSpan.FromSeconds(30), CancellationToken.None); Task.WaitAll(updateTasks); }
public AgentRunner(AgentRunnerConfiguration configuration, ILoggerFactory loggerFactory) { this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); this.loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)); logger = loggerFactory.CreateLogger <AgentRunner>(); shellRunner = new ShellRunner(); }
protected ShellRunner CreateRunner() { var runner = new ShellRunner(TestUtility.BuildServiceProvider()); runner.Context.SetDefaultConnection(_engineProvider.ProviderConnectionString); return(runner); }
public async Task Can_run_command_async() { var output = await ShellRunner.RunCommandAsync("youtube-dl", "-e", "--get-duration", "-g", "https://www.youtube.com/watch?v=guaEK62mxno"); var lines = output.Split("\n"); }
public GitProject(GitProjectInformation gitProjectInformation, ILoggerFactory loggerFactory, ShellRunner shellRunner) { this.gitProjectInformation = gitProjectInformation ?? throw new ArgumentNullException(nameof(gitProjectInformation)); this.loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)); this.shellRunner = shellRunner ?? throw new ArgumentNullException(nameof(shellRunner)); this.logger = loggerFactory.CreateLogger <GitProject>(); }
private static int Main(string[] args) { var services = new ServiceCollection(); ConfigureServices(services); var serviceProvider = services.BuildServiceProvider(); ConfigureLogging(serviceProvider); var logger = serviceProvider.GetService <ILogger <Program> >(); var runner = new ShellRunner(serviceProvider); try { runner.LoadFile(args[0]); for (int i = 1; i < args.Length; i++) { if (args[i].StartsWith("--")) { string name = args[i].Substring(2); i++; if (i >= args.Length) { break; } runner.Context.SetVariable(name, args[i]); } else if (args[i] == "/sqlconn") { i++; if (i >= args.Length) { break; } string sqlconn = args[i]; runner.Context.SetDefaultConnection("sqlserver://" + sqlconn); } } } catch (Exception err) { logger.LogError(err, "DBSH-00146 Error loading input DbShell script"); return(1); } try { runner.Run(); } catch (Exception err) { logger.LogError(err, "DBSH-00147 Error running process"); return(2); } return(0); }
private static void CreateNewBranchInTempRepo(TempDirectory url, string branchName) { using (new DirectoryJumper(url.Path)) { var runner = new ShellRunner(); runner.Run("git branch " + branchName); } }
public TestEnvironment() { runner = new ShellRunner(); WorkingDirectory = new TempDirectory(); Directory.CreateDirectory(Path.Combine(WorkingDirectory.Path, ".cement")); RemoteWorkspace = Path.Combine(WorkingDirectory.Path, "remote"); Directory.CreateDirectory(Path.Combine(RemoteWorkspace, ".cement")); PackageFile = Path.Combine(WorkingDirectory.Path, "package.cmpkg"); Helper.SetWorkspace(WorkingDirectory.Path); }
public UsagesGrep() : base(new CommandSettings { LogPerfix = "USAGES-GREP", LogFileName = "usages-grep", MeasureElapsedTime = true, Location = CommandSettings.CommandLocation.RootModuleDirectory }) { runner = new ShellRunner(Log); }
private static void CommitIntoTempRepo(TempDirectory url, string branch) { using (new DirectoryJumper(url.Path)) { var runner = new ShellRunner(); runner.Run("git checkout " + branch); File.WriteAllText(Path.Combine(url.Path, "content.txt"), "README"); runner.Run("git add content.txt"); runner.Run(@"git commit -am added"); } }
private static void CreateTempRepo(TempDirectory url) { using (new DirectoryJumper(url.Path)) { File.WriteAllText(Path.Combine(url.Path, "README.txt"), "README"); var runner = new ShellRunner(); runner.Run("git init"); runner.Run("git add README.txt"); runner.Run(@"git commit -am initial"); } }
public void Run_should_work() { var runner = new ShellRunner( new ShellRunnerSettings("ping") { Arguments = "google.com -n 2" }, new SynchronousConsoleLog()); runner.RunAsync(5.Seconds(), CancellationToken.None) .Wait(5.Seconds()).Should().BeTrue(); }
public void Run_should_stop_after_timeout() { var runner = new ShellRunner( new ShellRunnerSettings("ping") { Arguments = "google.com -n 100" }, new SynchronousConsoleLog()); runner.RunAsync(5.Seconds(), CancellationToken.None) .ContinueWith(_ => {}) .Wait(10.Seconds()).Should().BeTrue(); }
protected override int Execute() { var cwd = Directory.GetCurrentDirectory(); var moduleName = Path.GetFileName(cwd); configuration = configuration ?? "full-build"; if (!new ConfigurationParser(new FileInfo(cwd)).ConfigurationExists(configuration)) { ConsoleWriter.Shared.WriteError($"Configuration '{configuration}' was not found in {moduleName}."); return(-1); } var cleanerLogger = LogManager.GetLogger <Cleaner>(); var shellRunner = new ShellRunner(LogManager.GetLogger <ShellRunner>()); var consoleWriter = ConsoleWriter.Shared; var cleaner = new Cleaner(cleanerLogger, shellRunner, consoleWriter); var buildYamlScriptsMaker = new BuildYamlScriptsMaker(); var builder = new ModuleBuilder(Log, buildSettings, buildYamlScriptsMaker); var builderInitTask = Task.Run(() => builder.Init()); var modulesOrder = new BuildPreparer(Log).GetModulesOrder(moduleName, configuration); var builtStorage = BuildInfoStorage.Deserialize(); builtStorage.RemoveBuildInfo(moduleName); builderInitTask.Wait(); var module = new Dep(moduleName, null, configuration); if (FeatureFlags.CleanBeforeBuild || buildSettings.CleanBeforeBuild) { if (cleaner.IsNetStandard(module)) { cleaner.Clean(module); } } BuildDepsCommand.TryNugetRestore(new List <Dep> { module }, builder); if (!builder.Build(module)) { builtStorage.Save(); return(-1); } builtStorage.AddBuiltModule(module, modulesOrder.CurrentCommitHashes); builtStorage.Save(); return(0); }
public void Play() { var result = ShellRunner.ExecuteShellCommand("./dbuscontrol.sh", "play", 10000) .GetAwaiter() .GetResult(); if (result.ExitCode == 0) { log.Debug("play"); return; } log.Warn("Can not run play command. Code: {0}. Out: {1}", result.ExitCode, result.Output); }
private async Task StartInternalAsync(CancellationToken token) { while (!token.IsCancellationRequested) { if (playbackQueue.TryTake(out var content)) { await ShellRunner.RunCommandAsync("omxplayer", content.Source.ToString()); } else { await Task.Delay(2000, token); } } }
public void Next() { var result = ShellRunner.ExecuteShellCommand("./dbuscontrol.sh", ">", 10000) .GetAwaiter() .GetResult(); if (result.ExitCode == 0) { log.Debug(nameof(Next)); return; } log.Warn("Can not run 'next' command. Code: {0}. Out: {1}", result.ExitCode, result.Output); }
internal HerculesProcess(HerculesComponentSettings componentSettings, ILog log) { BaseDirectory = componentSettings.BaseDirectory; JarFileName = componentSettings.JarFileName; Log = log = log.ForContext(componentSettings.JarFileName); shellRunner = new ShellRunner( new ShellRunnerSettings("java") { Arguments = $"-jar {JarFileName} application.properties=file://{PropertiesFileName} " + componentSettings.Arguments, WorkingDirectory = BaseDirectory }, log); }
internal KafkaInstance(string baseDirectory, int port, ILog log) { log = log.ForContext("KafkaLocal"); Port = port; BaseDirectory = baseDirectory; healthChecker = new KafkaHealthChecker(log, $"localhost:{port}"); shellRunner = new ShellRunner( new ShellRunnerSettings("java") { Arguments = BuildKafkaArguments(), WorkingDirectory = BaseDirectory }, log); }
public void TestGitTreeishOnTag() { using (var tempRepo = new TempDirectory()) { CreateTempRepo(tempRepo); using (new DirectoryJumper(tempRepo.Path)) { var runner = new ShellRunner(); runner.Run("git tag testTag"); runner.Run("git checkout testTag"); } var repo = new GitRepository(Path.GetFileName(tempRepo.Path), Directory.GetParent(tempRepo.Path).FullName, Log); Assert.AreEqual("testTag", repo.CurrentLocalTreeish().Value); Assert.AreEqual(TreeishType.Tag, repo.CurrentLocalTreeish().Type); } }
public ZooKeeperInstance(int id, string baseDirectory, int clientPort, int peerPort, int electionPort, ILog log) { this.log = log = log.ForContext($"Instance-{id}"); Id = id; BaseDirectory = baseDirectory; ClientPort = clientPort; PeerPort = peerPort; ElectionPort = electionPort; healthChecker = new ZooKeeperHealthChecker(log, "localhost", clientPort); runner = new ShellRunner(new ShellRunnerSettings("java") { Arguments = BuildZooKeeperArguments(), WorkingDirectory = BinDirectory }, log); }
protected override int Execute() { var cwd = Directory.GetCurrentDirectory(); var moduleName = Path.GetFileName(cwd); configuration = string.IsNullOrEmpty(configuration) ? "full-build" : configuration; var cleanerLogger = LogManager.GetLogger <Cleaner>(); var shellRunner = new ShellRunner(LogManager.GetLogger <ShellRunner>()); var consoleWriter = ConsoleWriter.Shared; var cleaner = new Cleaner(cleanerLogger, shellRunner, consoleWriter); var buildYamlScriptsMaker = new BuildYamlScriptsMaker(); var builder = new ModuleBuilder(Log, buildSettings, buildYamlScriptsMaker); var builderInitTask = Task.Run(() => builder.Init()); var modulesOrder = new BuildPreparer(Log).GetModulesOrder(moduleName, configuration ?? "full-build"); var modulesToBuild = modulesOrder.UpdatedModules; if (rebuild) { modulesToBuild = modulesOrder.BuildOrder.ToList(); } if (modulesToBuild.Count > 0 && modulesToBuild[modulesToBuild.Count - 1].Name == moduleName) { modulesToBuild.RemoveAt(modulesToBuild.Count - 1); //remove root } var builtStorage = BuildInfoStorage.Deserialize(); foreach (var dep in modulesToBuild) { builtStorage.RemoveBuildInfo(dep.Name); } builderInitTask.Wait(); if (FeatureFlags.CleanBeforeBuild || buildSettings.CleanBeforeBuild) { TryCleanModules(modulesToBuild, cleaner); } TryNugetRestore(modulesToBuild, builder); var isSuccessful = parallel ? BuildDepsParallel(modulesOrder, builtStorage, modulesToBuild, builder) : BuildDepsSequential(modulesOrder, builtStorage, modulesToBuild, builder); return(isSuccessful ? 0 : -1); }
protected override int Execute() { var modulePath = Helper.GetModuleDirectory(Directory.GetCurrentDirectory()); var moduleName = Path.GetFileName(modulePath); project = Yaml.GetProjectFileName(project, moduleName); configuration = configuration ?? "full-build"; var buildData = Yaml.BuildParser(moduleName).Get(configuration).FirstOrDefault(t => !t.Target.IsFakeTarget()); var projectPath = Path.GetFullPath(project); var csproj = new ProjectFile(projectPath); var deps = new DepsParser(modulePath).Get(configuration); ConsoleWriter.WriteInfo("patching csproj"); var patchedDocument = csproj.CreateCsProjWithNugetReferences(deps.Deps, preRelease); var backupFileName = Path.Combine(Path.GetDirectoryName(projectPath) ?? "", "backup." + Path.GetFileName(projectPath)); if (File.Exists(backupFileName)) { File.Delete(backupFileName); } File.Move(projectPath, backupFileName); try { XmlDocumentHelper.Save(patchedDocument, projectPath, "\n"); var shellRunner = new ShellRunner(LogManager.GetLogger <ShellRunner>()); var cleaner = new Cleaner(shellRunner); var moduleBuilder = new ModuleBuilder(Log, buildSettings); moduleBuilder.Init(); ConsoleWriter.WriteInfo("start pack"); if (!moduleBuilder.DotnetPack(modulePath, projectPath, buildData?.Configuration ?? "Release")) { return(-1); } } finally { if (File.Exists(projectPath)) { File.Delete(projectPath); } File.Move(backupFileName, projectPath); } return(0); }
public void Start_Stop_should_work() { var runner = new ShellRunner( new ShellRunnerSettings("ping") { Arguments = "google.com -n 100" }, new SynchronousConsoleLog()); runner.Start(); Thread.Sleep(5.Seconds()); runner.Stop(); Thread.Sleep(5.Seconds()); }
public void TestGitTreeishDetached() { using (var tempRepo = new TempDirectory()) { CreateTempRepo(tempRepo); string sha1; using (new DirectoryJumper(tempRepo.Path)) { var runner = new ShellRunner(); runner.Run("git rev-parse HEAD"); sha1 = runner.Output.Trim(); runner.Run("git checkout " + sha1); } var repo = new GitRepository(Path.GetFileName(tempRepo.Path), Directory.GetParent(tempRepo.Path).FullName, Log); Assert.AreEqual(sha1, repo.CurrentLocalTreeish().Value); Assert.AreEqual(TreeishType.CommitHash, repo.CurrentLocalTreeish().Type); } }
public async Task <MediaContent> GetMediaContent(Uri url) { var source = url.ToString(); var result = await ShellRunner.ExecuteShellCommand( "youtube-dl", $"-e --get-duration -g -f best {source}", 30000); if (result.ExitCode != 0) { throw new Exception($"Failed to load content. {result.Output}"); } var lines = result.Output.Split("\n"); var info = new MediaContent(); info.Title = lines[0]; info.Source = new Uri(lines[1]); info.Duration = lines.Last(); return(info); }
public GitRepository(ShellRunner shellRunner, string directory, ILogger <GitRepository> logger) { Directory = directory ?? throw new ArgumentNullException(nameof(directory)); this.shellRunner = shellRunner ?? throw new ArgumentNullException(nameof(shellRunner)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); }