| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. |
| 2 | |
| 3 | using System; |
| 4 | using System.Collections.Generic; |
| 5 | using System.Linq; |
| 6 | using System.Text; |
| 7 | |
| 8 | namespace TestExe |
| 9 | { |
| 10 | class Program |
| 11 | { |
| 12 | static List<Task> tasks; |
| 13 | static int exitCodeToReturn = 0; |
| 14 | |
| 15 | static int Main(string[] args) |
| 16 | { |
| 17 | tasks = TaskParser.ParseTasks(args); |
| 18 | |
| 19 | if (tasks.Count == 0) |
| 20 | { |
| 21 | Usage(); |
| 22 | } |
| 23 | |
| 24 | foreach (Task t in tasks) |
| 25 | { |
| 26 | // special case for the ExitCodeTask |
| 27 | if (t.GetType() == typeof(ExitCodeTask)) |
| 28 | { |
| 29 | exitCodeToReturn = int.Parse(t.data); |
| 30 | } |
| 31 | else |
| 32 | { |
| 33 | t.RunTask(); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | Console.WriteLine("Exiting with ExitCode = {0}", exitCodeToReturn); |
| 38 | return exitCodeToReturn; |
| 39 | } |
| 40 | |
| 41 | static void Usage() |
| 42 | { |
| 43 | Console.WriteLine(@"TestExe.exe"); |
| 44 | Console.WriteLine(@""); |
| 45 | Console.WriteLine(@"TestExe can be passed various switches to define how it will behave and what tasks it will perform."); |
| 46 | Console.WriteLine(@"All switches are optional."); |
| 47 | Console.WriteLine(@"Any # of switches can be combined in any order."); |
| 48 | Console.WriteLine(@"Switches can be specified multiple times."); |
| 49 | Console.WriteLine(@"The order of the switches listed is the order they will be processed."); |
| 50 | Console.WriteLine(@"Info is written to stdout to describe what tasks are being performed as they are executed."); |
| 51 | Console.WriteLine(@""); |
| 52 | Console.WriteLine(@"Usage: TestExe.exe [tasks...]"); |
| 53 | Console.WriteLine(@""); |
| 54 | Console.WriteLine(@""); |
| 55 | Console.WriteLine(@"/ec # Exit code to return. Can only be specified once. If not specified, 0 will be returned. Example: “/ec 3010” would return 3010"); |
| 56 | Console.WriteLine(@"/s # Milliseconds to sleep before continuing. Example: “/s 5000” would sleep 5 seconds."); |
| 57 | Console.WriteLine(@"/sr #-# Random range of Milliseconds to sleep before continuing. Example: “/sr 5000-10000” would sleep between 5-10 seconds."); |
| 58 | Console.WriteLine(@"/log filename Create a log file called filename. Contents of the log are static text. Example: “/log %temp%\test.log” would create a %temp%\test.log file."); |
| 59 | Console.WriteLine(@"/Pinfo filename Create an xml file containing information about the process: PID, start time, user running the process, etc."); |
| 60 | Console.WriteLine(@"/fe filename Wait for a file to exist before continuing. Example: “/fe %temp%\cache\file.msi” would wait until %temp%\cache\file.msi exists."); |
| 61 | Console.WriteLine(@"/regw regkey,name,type,value (Re)writes a registry key with the specified value"); |
| 62 | Console.WriteLine(@"/regd regkey,[name] Deletes registry key name or key and all of its children (subkeys and values)"); |
| 63 | Console.WriteLine(@""); |
| 64 | Console.WriteLine(@"Example: "); |
| 65 | Console.WriteLine(@""); |
| 66 | Console.WriteLine(@"TestExe.exe /ec 1603 /Pinfo %temp%\Pinfo1.xml /s 1000 /log %temp%\log1.log /sr 5000-10000 /log %temp%\log2.log"); |
| 67 | Console.WriteLine(@""); |
| 68 | Console.WriteLine(@"This would result in the following execution:"); |
| 69 | Console.WriteLine(@" - Create an xml file with the current process info in it."); |
| 70 | Console.WriteLine(@" - Sleep 1 seconds"); |
| 71 | Console.WriteLine(@" - Create log1.log"); |
| 72 | Console.WriteLine(@" - Sleep between 5-10 seconds"); |
| 73 | Console.WriteLine(@" - Create log2.log"); |
| 74 | Console.WriteLine(@" - Exit with 1603"); |
| 75 | Console.WriteLine(@""); |
| 76 | } |
| 77 | } |
| 78 | } |