コード例 #1
0
        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);
        }
コード例 #2
0
 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();
 }
コード例 #3
0
        protected ShellRunner CreateRunner()
        {
            var runner = new ShellRunner(TestUtility.BuildServiceProvider());

            runner.Context.SetDefaultConnection(_engineProvider.ProviderConnectionString);
            return(runner);
        }
コード例 #4
0
        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");
        }
コード例 #5
0
 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>();
 }
コード例 #6
0
        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);
        }
コード例 #7
0
 private static void CreateNewBranchInTempRepo(TempDirectory url, string branchName)
 {
     using (new DirectoryJumper(url.Path))
     {
         var runner = new ShellRunner();
         runner.Run("git branch " + branchName);
     }
 }
コード例 #8
0
 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);
 }
コード例 #9
0
 public UsagesGrep()
     : base(new CommandSettings
 {
     LogPerfix          = "USAGES-GREP",
     LogFileName        = "usages-grep",
     MeasureElapsedTime = true,
     Location           = CommandSettings.CommandLocation.RootModuleDirectory
 })
 {
     runner = new ShellRunner(Log);
 }
コード例 #10
0
 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");
     }
 }
コード例 #11
0
 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");
     }
 }
コード例 #12
0
        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();
        }
コード例 #13
0
        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();
        }
コード例 #14
0
        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);
        }
コード例 #15
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);
        }
コード例 #16
0
 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);
         }
     }
 }
コード例 #17
0
        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);
        }
コード例 #18
0
        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);
        }
コード例 #19
0
        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);
        }
コード例 #20
0
 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);
     }
 }
コード例 #21
0
        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);
        }
コード例 #22
0
        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);
        }
コード例 #23
0
        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);
        }
コード例 #24
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());
        }
コード例 #25
0
 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);
     }
 }
コード例 #26
0
        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);
        }
コード例 #27
0
 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));
 }