/// <summary> /// Executes the specified SQL script file. /// </summary> /// <param name="scriptFileName">Name of the script file.</param> /// <param name="userName">Name of the database user.</param> /// <param name="password">The database user's password.</param> /// <param name="useDatabase">The database to run the script under. If <c>null</c>, the script will run under /// the default database.</param> /// <returns>The same instance of this <see cref="BuildRunner"/>.</returns> public TRunner ExecuteSqlScriptFile( string scriptFileName, string userName, string password, string useDatabase) { ProgramRunner .AddArgument("-U") .AddArgument(userName) .AddArgument("-P") .AddArgument(password) .AddArgument("-i") .AddArgument(scriptFileName) .AddArgument("-r1") .AddArgument("-m-1"); if (useDatabase != null) { ProgramRunner .AddArgument("-d") .AddArgument(useDatabase); } ProgramRunner.Run(@"C:\Program Files\Microsoft SQL Server\90\Tools\Binn\osql.exe", false); return(ReturnThisTRunner()); }
public static void InitializeClient() { ApiClient = new HttpClient(); path = Generator.GenerateCppFile(); compilePath = CompilerCpp.CompileCppFile(path); word = ProgramRunner.RunProgram(compilePath); }
public async Task Options() { var orgDirectory = Environment.CurrentDirectory; try { using (var testManager = new KubeTestManager()) { using (var runner = new ProgramRunner()) { using (var tempFolder = new TempFolder()) { Environment.CurrentDirectory = tempFolder.Path; //------------------------------------------------- // Verify that the [run] command handles command line options correctly. File.WriteAllText("test.cmd", "echo %* > output.txt"); var result = await runner.ExecuteAsync(Program.Main, "tool", "run", "--", "test.cmd", "-foo", "--bar=foobar", "--hello", "world"); Assert.Equal(0, result.ExitCode); Assert.Contains("-foo --bar=foobar --hello world", File.ReadAllText("output.txt")); } } } } finally { Environment.CurrentDirectory = orgDirectory; } }
static void Main(string[] args) { ConsoleWriter writer = null; try //BugFix #2b { HttpClient httpClient = new HttpClient(); JokeRepository jokeRepository = new JokeRepository(httpClient); NameRepository nameRepository = new NameRepository(httpClient); writer = new ConsoleWriter(); IReader reader = new ConsoleReader(writer); UserQuestions userQuestions = new UserQuestions(reader, writer); UserInteractions userInteractions = new UserInteractions(writer, userQuestions); JokeService jokeService = new JokeService(); ProgramRunner programRunner = new ProgramRunner(userInteractions, jokeRepository, nameRepository, jokeService); programRunner.Run(); } catch (Exception) { if (writer != null) { writer.WriteLine("Something went terribly wrong."); writer.WriteLine("Are you sure you're connected to the internet?"); } } }
public async Task VariableInjectEncrypted() { var orgDirectory = Environment.CurrentDirectory; try { using (var testManager = new KubeTestManager()) { using (var runner = new ProgramRunner()) { using (var tempFolder = new TempFolder()) { Environment.CurrentDirectory = tempFolder.Path; var vault = new NeonVault(Program.LookupPassword); // Create a test password and a [.password-name] file in the // temp test folder. var result = await runner.ExecuteAsync(Program.Main, "tool", "password", "set", "test"); Assert.Equal(0, result.ExitCode); //------------------------------------------------- // Verify that we can inject variables into an // ENCRYPTED file. File.WriteAllText("test.cmd", "type %1 > output.txt"); File.WriteAllText("file.txt", @" $<<TEST_A>> $<<TEST_B>> $<<TEST_C>> $<<TEST_D>> "); File.WriteAllBytes("file.txt", vault.Encrypt("file.txt", "test")); Assert.True(NeonVault.IsEncrypted("file.txt")); result = await runner.ExecuteAsync(Program.Main, "tool", "run", "--TEST_A=A-VALUE", "--TEST_B=B-VALUE", "--TEST_C=C-VALUE", "--TEST_D=D-VALUE", "--", "test.cmd", "_..file.txt"); Assert.Equal(0, result.ExitCode); var output = File.ReadAllText("output.txt"); Assert.Contains("A-VALUE", output); Assert.Contains("B-VALUE", output); Assert.Contains("C-VALUE", output); Assert.Contains("D-VALUE", output); File.Delete("output.txt"); File.Delete("file.txt"); } } } } finally { Environment.CurrentDirectory = orgDirectory; } }
/// <summary> /// Returns a list of paths with dates (part D ) removed /// </summary> /// <param name="dssFilename"></param> /// <returns></returns> public static string[] GetCatalog(string dssFilename) { string dir = Path.GetDirectoryName(dssFilename); string fnScript = FileUtility.GetTempFileNameInDirectory(dir, ".txt"); StreamWriter sw = new StreamWriter(fnScript); if (Path.GetFileName(dssFilename).IndexOf(" ") >= 0) { System.Windows.Forms.MessageBox.Show("Warning: The dss filename has a space. "); } sw.WriteLine(Path.GetFileName(dssFilename)); sw.WriteLine("CA");// create (N)ew (C)ondenced catalog (F)ull batch mode. sw.Close(); string dssutl = HecDssSeries.GetPathToDssUtl(); ProgramRunner pr = new ProgramRunner(); pr.Run(dssutl, "input=" + Path.GetFileName(fnScript), dir); pr.WaitForExit(); return(ParseRawCatalog(pr.Output)); }
public void TestExpectErrorBecauseOnlyOneFileParameter() { var programRunner = new ProgramRunner(new [] { "ResTest/NamespaceDeclarationInjectionTest/MainFile.js" }); var result = programRunner.Run(); Assert.AreEqual(ProgramRunnerExit.Error, result); }
public override Thing Eval(ProgramRunner runner) { //mathfunc eval called EvalArgumentsRecursive(runner); //check both args are number return func(left, right, runner); }
public void Goto_WithNonExistingLineNumber_ThrowsArgumentOutOfRangeException() { var runner = new ProgramRunner(lines); const string nonExistingNumber = "200"; runner.Goto(nonExistingNumber); }
public void SourceNamespace() { using (new KubeTestManager()) { using (var runner = new ProgramRunner()) { // Verify that all types are generated when no targets // are specified. var result = runner.Execute(Program.Main, "generate", "models", $"--source-namespace={typeof(FooBar.Class4).Namespace}", thisAssemblyPath); Assert.Equal(0, result.ExitCode); var sourceCode = result.OutputText; ModelGenerator.Compile(sourceCode, "test-assembly", references => ModelGenTestHelper.ReferenceHandler(references)); Assert.DoesNotContain("class Class1", sourceCode); Assert.DoesNotContain("class Class2", sourceCode); Assert.DoesNotContain("class Class3", sourceCode); Assert.Contains("class Class4", sourceCode); Assert.DoesNotContain("class Service1", sourceCode); Assert.DoesNotContain("class Service2", sourceCode); } } }
public async static Task <int> Main(string[] args2) { RunnerArgs args = RunnerArgs.FromCommandLine(args2); ProgramRunner runner = new ProgramRunner(args); try { await runner.ExecuteAsync(); } catch (ToolException ex) { if (!string.IsNullOrWhiteSpace(ex.StdOut)) { WriteLine(ex.StdOut, ConsoleColor.Red); } if (!string.IsNullOrWhiteSpace(ex.StdErr)) { WriteLine(ex.StdErr, ConsoleColor.Red); } return(-1); } catch (Exception ex) { WriteLine(ex.Message, ConsoleColor.Red); return(-1); } return(0); }
public override Thing Eval(ProgramRunner runner) { //mathfunc eval called EvalArgumentsRecursive(runner); //check both args are number return new Number(func(((Number)left).Value, ((Number)right).Value)); }
public TRunner SourceMonitor() { string sourceMonitorProjectFile = MakePathFromRootDir(ProductId + ".smp"); AssertFileExists("SourceMonitor project file", sourceMonitorProjectFile); string copyOfProjectFile = MakePathFromRootDir(ProductId + ".copy.smp"); CopyFile(sourceMonitorProjectFile, copyOfProjectFile, true); string sourceMonitorCommandFile = MakePathFromRootDir("SourceMonitor.Commands.xml"); string reportDir = EnsureBuildLogsTestDirectoryExists(); string sourceMonitorCommands = ConstructSourceMonitorCommands( copyOfProjectFile, reportDir); File.WriteAllText( sourceMonitorCommandFile, sourceMonitorCommands); ProgramRunner .AddArgument("/C") .AddArgument(sourceMonitorCommandFile) .Run(MakePathFromRootDir(LibDir + @"\SourceMonitor\SourceMonitor.exe")); return(ReturnThisTRunner()); }
private static async Task <FileObject> PerformOneIterationOfPhaseTwoAsync( AnalysisIterationContextPhaseTwo iterationContext) { iterationContext.ThrowIfNull(nameof(iterationContext)); _logger.Info("Preparing to run one iteration of phase two."); var fileDeleter = new FileDeleter(iterationContext.FinalOutputFile); // Contract: the analysis program is located in the same directory as our app. var processLaunchContext = ProcessLaunchContext.Create( file: iterationContext.Args.AnalysisProgramName, args: iterationContext.AnalysisInputArgs, showWindow: iterationContext.LaunchContext.ShowAnalysisWindow ); _logger.Info( $"Starting analysis program. Launch context: {processLaunchContext.ToLogString()}" ); using (var analysisRunner = ProgramRunner.RunProgram(processLaunchContext)) { _logger.Info("Waiting to finish one iteration of phase two."); await analysisRunner.WaitAsync(); } DataObject <OutputFileData> data = iterationContext.FileWorker.ReadDataFile(iterationContext.FinalOutputFile); _logger.Info("Finished one iteration of phase two."); return(new FileObject(fileDeleter, data)); }
public bool AreEqual_Examples(ProgramSpec programSpec, TreeNode <string> root) { var runner = new ProgramRunner(); var examples = Extensions.DeepClone(programSpec.concreteExamples); foreach (var concreteExample in examples) { var inputArgs = concreteExample.Where(x => x.parameterType == ParameterType.Input). Select(x => x.obj).ToArray(); var outputArg = concreteExample.Single(x => x.parameterType == ParameterType.Output); try { var outputResult = runner.ExecuteProgram(root, inputArgs); var check = AreEqual(outputArg, outputResult); return(check); } catch (Exception ex) { return(false); } } return(false); }
public void Password() { ExecuteResponse result; using (new KubeTestManager()) { using (var runner = new ProgramRunner()) { // Verify that [neon password] returns help/usage text: result = runner.Execute(Program.Main, "password"); Assert.Equal(0, result.ExitCode); Assert.Contains("Manages neonKUBE passwords.", result.OutputText); result = runner.Execute(Program.Main, "help", "password"); Assert.Equal(0, result.ExitCode); Assert.Contains("Manages neonKUBE passwords.", result.OutputText); // Verify that the "--help" option does the same thing. result = runner.Execute(Program.Main, "password", "--help"); Assert.Equal(0, result.ExitCode); Assert.Contains("Manages neonKUBE passwords.", result.OutputText); // Verify that an invalid command fails. result = runner.Execute(Program.Main, "password", "bad"); Assert.NotEqual(0, result.ExitCode); Assert.Contains("Unexpected [bad] command.", result.ErrorText); } } }
public async Task Password() { ExecuteResponse result; using (new KubeTestManager()) { using (var runner = new ProgramRunner()) { // Verify that [neon password] returns help/usage text: result = await runner.ExecuteAsync(Program.Main, "tool", "password"); Assert.Equal(0, result.ExitCode); Assert.Contains("Manages neonKUBE passwords.", result.OutputText); result = await runner.ExecuteAsync(Program.Main, "help", "tool", "password"); Assert.Equal(0, result.ExitCode); Assert.Contains("Manages neonKUBE passwords.", result.OutputText); // Verify that an invalid command fails. result = await runner.ExecuteAsync(Program.Main, "tool", "password", "bad"); Assert.NotEqual(0, result.ExitCode); Assert.Contains("Unexpected [bad] command.", result.ErrorText); } } }
public async Task PasswordList() { ExecuteResponse result; using (var testManager = new KubeTestManager()) { using (var runner = new ProgramRunner()) { // Verify that [help] works: result = await runner.ExecuteAsync(Program.Main, "help", "tool", "password", "list"); Assert.Equal(0, result.ExitCode); Assert.Contains("Lists passwords.", result.OutputText); // Add a few passwords: result = await runner.ExecuteAsync(Program.Main, "tool", "password", "rm", "--force", "*"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteWithInputAsync(Program.Main, "one", "tool", "password", "set", "pwd-1", "-"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteWithInputAsync(Program.Main, "two", "tool", "password", "set", "pwd-2", "-"); Assert.Equal(0, result.ExitCode); result = await runner.ExecuteWithInputAsync(Program.Main, "three", "tool", "password", "set", "pwd-3", "-"); Assert.Equal(0, result.ExitCode); // Verify that we can list via: list result = await runner.ExecuteAsync(Program.Main, "tool", "password", "list"); Assert.Equal(0, result.ExitCode); TestHelper.AssertEqualLines( @"pwd-1 pwd-2 pwd-3 ", result.OutputText); // Verify that we can list via: ls result = await runner.ExecuteAsync(Program.Main, "tool", "password", "ls"); Assert.Equal(0, result.ExitCode); TestHelper.AssertEqualLines( @"pwd-1 pwd-2 pwd-3 ", result.OutputText); } } }
/// <summary> /// The main entry point for the application. /// </summary> /// <param name="args">The command-line arguments.</param> public static void Main(string[] args) { var programRunner = new ProgramRunner( ActionToRun, ServiceName, GetServiceToRun); programRunner.RunProgram(args); }
public void MoveNext_WhenRecallAfterComplete_ThrowsInvalidOperationException() { var runner = new ProgramRunner(lines); runner.Complete(); runner.MoveNext(); runner.MoveNext(); }
public void IsBroke_AfterBreak_IsTrue() { var runner = new ProgramRunner(lines); runner.Break(); Assert.IsTrue(runner.IsBroke); }
public override Thing Eval(ProgramRunner runner) { while (!GetCondition(runner)) { ((Function)right).Eval(runner); } return new Until(left, right); }
public void MoveNext_AfterConstructorCall_ReturnsTrue() { var runner = new ProgramRunner(lines); var condition = runner.MoveNext(); Assert.IsTrue(condition); }
// ReSharper disable once InconsistentNaming public void TestBasicHtmlVarWOVars() { var programRunner = new ProgramRunner(new [] { "ResTest/BasicHtmlVarWOVarsTest/MainFile.js", "ResTest/BasicHtmlVarWOVarsTest/MainFile.out.js" }); var result = programRunner.Run(); // var output = programRunner.JsMrgOutput; Assert.AreEqual(ProgramRunnerExit.Done, result); }
public async Task Vault() { using (var runner = new ProgramRunner()) { var result = await runner.ExecuteAsync(Program.Main, "tool", "vault"); Assert.Equal(0, result.ExitCode); } }
public void Vault() { using (var runner = new ProgramRunner()) { var result = runner.Execute(Program.Main, "vault"); Assert.Equal(0, result.ExitCode); } }
public void RunningLine_AfterMoveNext_RetursFirstLine() { var runner = new ProgramRunner(lines); var condition = runner.MoveNext(); var statement = runner.RunningLine.Statement; Assert.IsInstanceOfType(statement, typeof(Rem)); }
public void Goto_WithExistingLineNumber_SetsCurrentStatement() { var runner = new ProgramRunner(lines); const string existingNumberWithRemStatement = "100"; runner.Goto(existingNumberWithRemStatement); var actual = (runner.RunningLine.Statement as Rem).Comment; Assert.AreEqual("The end", actual); }
public void MoveNext_AfterComplete_ReturnsFalse() { var runner = new ProgramRunner(lines); runner.Complete(); var condition = runner.MoveNext(); Assert.IsFalse(condition); }
public void Fork() { using (var runner = new ProgramRunner()) { mainExecuted = false; runner.Fork(Main, "fork"); runner.TerminateFork(); Assert.True(mainExecuted); } }
public double[] ComputeCoefficients(ForecastEquation eq, string pathToR) { var tbl = eq.ComputeHistoricalCoefficients(eq.StartYear, eq.EndYear); // perf.Report("done."); // 1.2 seconds with cache/ 33 seconds without dataFile = FileUtility.GetTempFileName(".csv"); CsvFile.WriteToCSV(tbl, dataFile, false); dataFile = dataFile.Replace("\\", "/"); var rInput = new List <string>(); rInput.Add("# Forecast " + eq.Name); rInput.Add("a <- read.csv(\"" + dataFile + "\")"); rInput.Add("b <- subset(a, select=-Year)"); rInput.Add("cor(b)"); rInput.Add("summary(b)"); string s = "fit <- lm(Y1 ~ "; for (int i = 1; i < tbl.Columns.Count - 1; i++) { s += " + X" + i; } s += ", data=a)"; rInput.Add(s); rInput.Add("options(width=240)"); rInput.Add("summary(fit)"); rInput.Add("coefficients(fit)"); string rFile = FileUtility.GetTempFileName(".txt"); TextFile rtf = new TextFile(rInput.ToArray()); rtf.SaveAs(rFile); rFile = rFile.Replace("\\", "/"); var exe = Path.Combine(pathToR, "R\\bin\\R.exe"); if (!File.Exists(exe)) { throw new Exception("Could not find the R statistic program. It should be in a sub directory R"); } ProgramRunner pr = new ProgramRunner(); pr.Run(exe, "--no-restore --no-save --quiet < \"" + rFile); pr.WaitForExit(); Coefficients = GetCoefficients(pr.Output); Output = pr.Output; return(Coefficients); }
public void TestNamespaceDeclarationInjection() { var programRunner = new ProgramRunner(new [] { "ResTest/NamespaceDeclarationInjectionTest/MainFile.js", "ResTest/NamespaceDeclarationInjectionTest/MainFile.out.js" }); var result = programRunner.Run(); var output = programRunner.JsMrgOutput; Assert.AreEqual(ProgramRunnerExit.Done, result); Assert.True(output.Contains("YTILS.create = { };")); Assert.True(output.Contains("YTILS.defaults = { };")); Assert.True(output.Contains("YTILS.dependency = { };")); }
/// <summary> /// Evaluates all functions in left or right so that they only contain simple types. /// Only called at Runtime /// f:add[n:3][n:4] becomes [n:7]. /// Changes left and right properties /// </summary> protected void EvalArgumentsRecursive(ProgramRunner runner) { if (left.IsType(typeof(Function))) { left = ((Function)left).Eval(runner); } if (right.IsType(typeof(Function))) { right = ((Function)right).Eval(runner); } }
public void MoveNext_AfterGoto_ReturnsTrue() { var runner = new ProgramRunner(lines); const string existingNumber = "30"; runner.Goto(existingNumber); var condition = runner.MoveNext(); Assert.IsTrue(condition); }
public void MoveNext_BeyondTheEndOfProgram_ThrowsInvalidOperationException() { var runner = new ProgramRunner(lines); while (runner.MoveNext()) { ; } runner.MoveNext(); }
public override Thing Eval(ProgramRunner runner) { //eval left down to a simple type if (left.IsType(typeof(Function))) left = ((Function)left).Eval(runner); if (((Number)left).Value > 0) { right = ((Function)right).Eval(runner); } return new If(left, right); }
public override Thing Eval(ProgramRunner runner) { Thing evalRight; if (right.IsType(typeof(Function))) { evalRight = ((Function)right).Eval(runner); } else { evalRight = right; } runner.SetMemory(((Things.String)left).str, evalRight); return new Set(left, right); }
private bool GetCondition(ProgramRunner runner) { if (left.IsType(typeof(Function))) { Number leftNum = (Number)((Function)left).Eval(runner); return leftNum.Value > 0; } else if (left.IsType(typeof(Number))) { return ((Number)left).Value > 0; } else { return false; } }
/// <summary> /// The main entry point for the application. /// </summary> /// <param name="args">The command-line arguments.</param> public static void Main(string[] args) { var logger = Bootstrapper.Resolve<ILogger>(); logger.Info("Starting Windows service."); var programRunner = new ProgramRunner( TheAction, ServiceName, GetServiceToRun); try { programRunner.RunProgram(args); } catch (Exception e) { logger.Error(e, "Unhandled exception in Windows service."); } logger.Info("Stopping Windows service."); }
public override Thing Eval(ProgramRunner runner) { return runner.GetMemory(((Things.String)left).str); }
/// <summary> /// Evaluates function /// </summary> /// <returns>Thing that the function returns</returns> public virtual Thing Eval(ProgramRunner runner) { return new Null(); }