Exemple #1
0
 public static StatusCode LaunchProcess(string executable, string[] args, string pwd)
 {
     Logger.CallStart(executable, args, pwd);
     try
     {
         using (var process = ProcessWrapper.Execute(executable, args, pwd))
         {
             process.Process.WaitForExit();
             if (process.Process.ExitCode != 0)
             {
                 Logger.CallFailed($"{process.Process.StartInfo.FileName} failed with exitCode={process.Process.ExitCode};" +
                                   " combined output:\n" + process.CombinedOutput);
                 return(StatusCode.ChildProcessFailedError);
             }
             else
             {
                 Logger.CallSucceeded();
                 return(StatusCode.Success);
             }
         }
     }
     catch (Exception e)
     {
         Logger.LogException(e);
         return(StatusCode.Failure);
     }
 }
        private void RunLanguageTool(string pathtoLanguagePacks, DatabaseComponent databaseComponent)
        {
            if (Directory.Exists(pathtoLanguagePacks))
            {
                Logger.Instance.Log(LogLevel.Info, "\nApplying language packs to ({0}):\n", databaseComponent.Id);

                foreach (string languageCodeFolder in Directory.GetDirectories(pathtoLanguagePacks))
                {
                    string languageCode = languageCodeFolder.Substring(languageCodeFolder.LastIndexOf('\\') + 1);

                    foreach (string pathToLanguageToolConfig in Directory.GetFiles(languageCodeFolder, "ImportConfig.xml", SearchOption.AllDirectories))
                    {
                        string pathToLanguagePacksXmlDir = Path.Combine(Path.GetDirectoryName(pathToLanguageToolConfig), "xml");

                        int languageToolResultCode = ProcessWrapper.Execute(LogLevel.None, Properties.PathToLanguageTool,
                                                                            "-import -config_file:\"{0}\" -folder:\"{1}\" -language_code:\"{2}\" -server:\"{3}\" -db:\"{4}\" -login:\"{5}\" -pwd:\"{6}\"",
                                                                            pathToLanguageToolConfig,
                                                                            pathToLanguagePacksXmlDir,
                                                                            languageCode,
                                                                            databaseComponent.SqlServer,
                                                                            databaseComponent.DatabaseName,
                                                                            databaseComponent.InnovatorLogin,
                                                                            databaseComponent.InnovatorPassword.Value);
                        if (languageToolResultCode != 0)
                        {
                            throw new Exception(string.Format(CultureInfo.InvariantCulture, "Failed to apply Language packs from {0}, LangugeTool.exe returned exit code {1}.", pathtoLanguagePacks, languageToolResultCode));
                        }
                    }
                }
            }
        }
Exemple #3
0
 public void StopWindowsService()
 {
     if (ProcessWrapper.Execute("sc", "\\\\{0} stop \"{1}\"", ServerName, ServiceName) == 0)
     {
         Thread.Sleep(30000);
     }
 }
Exemple #4
0
        public void CopyDirectory(string sourceDirectoryPath, IFileSystem targetFileSystem, string targetDirectoryPath, bool overwrite = true)
        {
            string robocopyPath           = "robocopy";
            int    robocopySearchExitCode = ProcessWrapper.Execute(LogLevel.None, "cmd", "/C where {0}", robocopyPath);
            bool   useRobocopy            = robocopySearchExitCode == 0;

            if (useRobocopy)
            {
                //robocopy options explanation:
                // /E :: copy subdirectories, including Empty ones.
                // /NP :: No Progress - don't display percentage copied.
                // /NFL::No File List -don't log file names.
                // /NDL::No Directory List -don't log directory names.
                // /NJH::No Job Header.
                ProcessWrapper.Execute(robocopyPath, "\"{0}\" \"{1}\" /E /NP /NJH /NFL /NDL", GetFullPath(sourceDirectoryPath), targetFileSystem.GetFullPath(targetDirectoryPath));
            }
            else
            {
                Logger.Instance.Log(LogLevel.Info, "\tCopying files from '{0}' to '{1}'...", GetFullPath(sourceDirectoryPath), targetFileSystem.GetFullPath(targetDirectoryPath));

                int copiedFilesAmount = CopyFilesRecursively(sourceDirectoryPath, targetFileSystem, targetDirectoryPath, overwrite);

                Logger.Instance.Log(LogLevel.Info, "\t{0} files were copied", copiedFilesAmount);
            }
        }
Exemple #5
0
 public void should_make_the_process_nonexistent_after_killing_it()
 {
     var pw = new ProcessWrapper("ruby", @"-e ""system(\""ruby -e 'sleep 300'\"")""");
     pw.Execute();
     var processId = pw.Id;
     pw.Dispose();
     Assert.That(ProcessHasExited(processId));
 }
Exemple #6
0
 public void ProtectedSpinloopReturns()
 {
     using (var repl = new ProcessWrapper())
     {
         repl.Execute(@"try { while(true); } finally { while(true); }");
         Assert.True(true);
     }
 }
Exemple #7
0
 public void CanExecuteCode()
 {
     using (var repl = new ProcessWrapper())
     {
         Assert.Equal("[(4, 20)]", repl.Execute(@"Tuple.Create(4,20);"));
         repl.Kill();
     }
 }
Exemple #8
0
        private void RunArasUpdateCmdForComponent(Component component, Dictionary <string, string> propertyNameMapper = null)
        {
            Logger.Instance.Log(LogLevel.Info, "\nDeploying component ({0}):\n", component.Id);

            if (ProcessWrapper.Execute(Properties.PathToArasUpdateCmd, ObtainArasUpdateCmdArguments(component, propertyNameMapper)) != 0)
            {
                throw new Exception(string.Format(CultureInfo.InvariantCulture, "Failed to apply Aras Update package to component({0}).", component.Id));
            }
        }
        protected void SetupNtfsPermissionsToFolder(string pathToFolder)
        {
            if (!TargetFileSystem.DirectoryExists(pathToFolder))
            {
                TargetFileSystem.CreateDirectory(pathToFolder);
            }

            ProcessWrapper.Execute("icacls", "\"{0}\" /grant *S-1-5-11:(OI)(CI)(M)", TargetFileSystem.GetFullPath(pathToFolder));
        }
Exemple #10
0
 public void should_capture_std_error_output()
 {
     var err = new StringBuilder();
     var pw = new ProcessWrapper("ruby", "-e '$stderr.puts(\"fle\")'");
     pw.OnErrorOutput += output => err.Append(output);
     pw.Execute();
     pw.WaitForProcess(5000);
     pw.Dispose();
     Assert.That(err.ToString(), Is.Not.Empty);
 }
Exemple #11
0
 public void ProtectedSpinloopKillsProcess()
 {
     using (var repl = new ProcessWrapper())
     {
         repl.Execute(@"try { while(true); } finally { while(true); }");
         while (repl.IsProcessAlive)
             Thread.Sleep(500);
         Assert.True(true);
     }
 }
Exemple #12
0
        public void CantAssertNewPermissions()
        {
            if (File.Exists("c:\\test.txt"))
                File.Delete("c:\\test.txt");

            using (var repl = new ProcessWrapper())
            {
                repl.Execute(@"new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted).Assert(); System.IO.File.WriteAllText(@""c:\test.txt"", ""test"");");
                repl.Kill();
                Assert.False(File.Exists("c:\\test.txt"));
            }
        }
Exemple #13
0
        public void should_indicate_no_cpu_usage_when_process_does_nothing()
        {
            var pw = new ProcessWrapper("ruby", "-e 'sleep 30'");
            pw.Execute();
            pw.WaitForProcess(1000);
            var tpt = pw.ProcessTreeCPUUsageId;
            pw.WaitForProcess(2000);
            var tpt1 = pw.ProcessTreeCPUUsageId;
            pw.Dispose();

            Assert.That(tpt, Is.EqualTo(tpt1));
        }
Exemple #14
0
        public void should_indicate_cpu_usage_when_process_consumes_one()
        {
            var pw = new ProcessWrapper("ruby", "-e '100000000.times {|e| e}'");
            pw.Execute();
            pw.WaitForProcess(1);
            var tpt = pw.ProcessTreeCPUUsageId;
            pw.WaitForProcess(500);
            var tpt1 = pw.ProcessTreeCPUUsageId;
            pw.Dispose();

            Assert.That(tpt, Is.Not.EqualTo(tpt1));
        }
Exemple #15
0
        public void should_capture_std_output()
        {
            var std = new StringBuilder();
            var pw = new ProcessWrapper("ruby", "-e 'puts \"ff\"'");
            pw.OnStdOutput += output => std.Append(output);

            pw.Execute();
            pw.WaitForProcess(5000);
            pw.Dispose();

            Assert.That(std.ToString(), Is.Not.Empty);
        }
Exemple #16
0
 public static string UnixTotalProcessorTime(int processId)
 {
     var p = new ProcessWrapper("python",string.Format("{0} {1}", Path.Combine(Locations.SupportScriptsLocation, "cpu_times.py"), processId));
     var processStrings = new List<String>();
     var errorStrings = new List<String>();
     p.OnStdOutput += s => { if (!s.IsNullOrEmpty()) processStrings.Add(s); };
     p.OnErrorOutput += s => { if (!s.IsNullOrEmpty()) errorStrings.Add(s); };
     p.Execute();
     p.WaitForProcess(10000);
     p.Dispose();
     return ParseCPUTreeUsageInfo(processStrings, errorStrings);
 }
Exemple #17
0
        public void CantWriteFile()
        {
            if (File.Exists("c:\\test.txt"))
                File.Delete("c:\\test.txt");

            using (var repl = new ProcessWrapper())
            {
                repl.Execute(@"System.IO.File.WriteAllText(@""c:\test.txt"", ""test"");");
                repl.Kill();

                Assert.False(File.Exists("c:\\test.txt"));
            }
        }
Exemple #18
0
 public CheckoutInfo GetSourceRevision(string revision, string workingArea)
 {
     var scriptPath = Path.Combine(Locations.GitProductionScriptsLocation, "git_fetch.rb");
     var process = new ProcessWrapper("ruby",
                                      scriptPath + " \"" + repoUrl + "\" " + revision + " " + " \"" + workingArea+"\"");
     var log = "";
     process.OnStdOutput += s => { if (!s.IsNullOrEmpty()) log = s; };
     string err_log = "";
     process.OnErrorOutput += s => err_log += s;
     process.Execute();
     process.WaitForProcess(GitTimeoutInMs);
     var exitcode = process.Dispose();
     if (exitcode != 0)
         throw new InvalidProgramException("script failed: "+err_log);
     return new CheckoutInfo {Comment = log, Revision = revision};
 }
        private void RunConsoleUpgrade(string pathToAmlPackages, DatabaseComponent databaseComponent)
        {
            if (Directory.Exists(pathToAmlPackages))
            {
                Logger.Instance.Log(LogLevel.Info, "\nApplying AML packages to ({0}):\n", databaseComponent.Id);

                int consoleUpgradeResultCode = ProcessWrapper.Execute(LogLevel.None, Properties.PathToConsoleUpgrade,
                                                                      "database=\"{0}\" server=\"{1}\" login=\"root\" password=\"{2}\" release=\"{3}\" mfFile=\"{4}\" import verbose merge dir=\"{5}\" log=\"{6}\" timeout=\"1000000\"",
                                                                      databaseComponent.DatabaseName,
                                                                      databaseComponent.InnovatorUrl,
                                                                      databaseComponent.PasswordOfRootInnovatorUser.Value,
                                                                      Properties.InnovatorVersion, Path.Combine(pathToAmlPackages, databaseComponent.AmlPackagesManifest),
                                                                      pathToAmlPackages,
                                                                      databaseComponent.PathToConsoleUpgradeLogFile);
                if (consoleUpgradeResultCode != 0)
                {
                    throw new Exception(string.Format(CultureInfo.InvariantCulture, "Failed to apply AML packages from {0}, consoleUpgrade.exe returned exit code {1}.", pathToAmlPackages, consoleUpgradeResultCode));
                }
            }
        }
Exemple #20
0
 public RevisionInfo GetLatestRevision()
 {
     string scriptPath = Path.Combine(Locations.GitProductionScriptsLocation, "git_remote_latest_rev.rb");
     var process = new ProcessWrapper("ruby",
                                      scriptPath + " \"" + repoUrl+"\"");
     string result = "";
     process.OnStdOutput +=
         s =>
             {
                 if (result.Length == 0 && !s.IsNullOrEmpty())
                 {
                     if (Regex.IsMatch(s, RevisionExtractingRegex))
                         result = Regex.Match(s, RevisionExtractingRegex).Groups[1].Value;
                 }
             };
     process.Execute();
     process.WaitForProcess(GitTimeoutInMs);
     var exitcode = process.Dispose();
     if (exitcode != 0)
         throw new InvalidProgramException(string.Format("script failed with exit code {1}: {0}", 1, exitcode));
     if (result.IsNullOrEmpty())
         throw new InvalidProgramException("Failed to retrieve repo revision");
     return new RevisionInfo {Revision = result};
 }
Exemple #21
0
 public void should_throw_an_exception_when_trying_to_get_process_snapshot_for_process_that_has_died()
 {
     var pw = new ProcessWrapper("ruby", @"-e exit 0");
     pw.Execute();
     pw.WaitForProcess(1000);
     var processId = pw.Id;
     //            pw.Dispose();
     Assert.That(ProcessHasExited(processId));
     try
     {
         var tpt = pw.ProcessTreeCPUUsageId;
         Assert.Fail("the process should have been gone, operation should have failed");
     }
     catch(InvalidOperationException)
     {
         // that's what we are aiming for ;)
     }
     pw.Dispose();
 }
Exemple #22
0
 public void StartWindowsService()
 {
     ProcessWrapper.Execute("sc", "\\\\{0} start \"{1}\"", ServerName, ServiceName);
 }
Exemple #23
0
 public void SpinloopDoesNotKillProcess()
 {
     using (var repl = new ProcessWrapper())
     {
         repl.Execute(@"while(true);");
         Thread.Sleep(10000);
         Assert.True(repl.IsProcessAlive);
     }
 }
Exemple #24
0
        private void RemoveWindowsService()
        {
            StopWindowsService();

            ProcessWrapper.Execute("sc", "\\\\{0} delete \"{1}\"", ServerName, ServiceName);
        }
Exemple #25
0
 private void SetupWindowsService()
 {
     ProcessWrapper.Execute("sc", "\\\\{0} create \"{1}\" binPath= \"{2}\" start= \"{3}\" DisplayName= \"{4}\"", ServerName, ServiceName, PathToExecutable, StartMode, DisplayServiceName);
 }
Exemple #26
0
 private void SetupVaultServerConfig()
 {
     Directory.CreateDirectory(PathToVaultFolder);
     TargetFileSystem.XmlHelper.XmlPoke(PathToConfig, "/configuration/appSettings/add[@key = 'LocalPath']/@value", PathToVaultFolder);
     ProcessWrapper.Execute("icacls", "{0} /grant *S-1-5-11:(OI)(CI)(M)", TargetFileSystem.GetFullPath(PathToVaultFolder));
 }
Exemple #27
0
 public void SpinloopReturns()
 {
     using (var repl = new ProcessWrapper())
     {
         repl.Execute(@"while(true);");
         Assert.True(true);
     }
 }
Exemple #28
0
 public void should_throw_exception_when_executable_not_found()
 {
     var pw = new ProcessWrapper("rubyyyyyy", "-e '$stderr.puts(\"fle\")'");
     try
     {
         pw.Execute();
         Assert.Fail("Should have thrown an exception");
     }
     catch (ApplicationNotFoundException)
     {
     }
 }
Exemple #29
0
 public void should_run_when_no_std_error_output_is_captured()
 {
     var pw = new ProcessWrapper("ruby", "-e '$stderr.puts(\"fle\")'");
     pw.Execute();
     pw.WaitForProcess(5000);
 }