private static List <string> readParameter(Options o) { // Check if there is a @INI Merge file on command line // If yes, and if it contains system environment variables we will expand those // and replace that parameter by a (temp) file we generated List <string> newParameters = new List <string>(); foreach (String p in o.OtherStuff) { if (p[0] == '@') { MgMergeFile mgMergeFile = new MgMergeFile(); int nModifications = mgMergeFile.ReadFile(p.Substring(1)); if (nModifications > 0) { // Our (generated) copy differs from the original file. Effectively this means // that it did contain system environment variables which we did expand // We change the commandline parameter to our version newParameters.Add('@' + mgMergeFile.GetFilenameTemp()); } else { newParameters.Add(p); } } else { // Neither @INIs nor parameter (Otions) for XpaRunner. We just forward these newParameters.Add(p); } } return(newParameters); }
static void Main(string[] args) { // Read .settings before evaluating command line parametrs which have precedence Options options = new Options(); // Parse the commandline into Dictionary Options ... var parser = new Parser(with => with.EnableDashDash = true); var results = CommandLine.Parser.Default.ParseArguments <Options>(args); CommandLine.Parser.Default.ParseArguments <Options>(args) .WithParsed(r => { options = r; }); List <string> ParametersOtherStuff = new List <string>(); if (options.OtherStuff != null) { // Check if there is a @INI Merge file on command line // If yes, and if it contains system environment variables we will expand those // and replace that parameter by a (temp) file we generated ParametersOtherStuff = readParameter(options); } string appname = Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName); string appsettings = Directory.GetCurrentDirectory() + "\\" + appname + ".settings"; // appsettings = "C:\\magic.xpa\\samples\\xpatest\\XpaRunner.settings"; bool shadowCopyFiles = false; ReadSettings(options, appsettings, ref shadowCopyFiles); if (!String.IsNullOrEmpty(options.parameters)) { ParametersParser Parameters = new ParametersParser(options.parameters); foreach (var parameter in Parameters) { if (parameter.Bruto.Length > 0 && parameter.Bruto[0] == '@') { MgMergeFile mgMergeFile = new MgMergeFile(); int nModifications = mgMergeFile.ReadFile(parameter.Bruto.Substring(1)); if (nModifications > 0) { // Our (generated) copy differs from the original file. Effectively this means // that it did contain system environment variables which we did expand // We change the commandline parameter to our version ParametersOtherStuff.Add('@' + mgMergeFile.GetFilenameTemp()); } else { ParametersOtherStuff.Add(parameter.Bruto); } } else { ParametersOtherStuff.Add(parameter.Bruto); } } } try { CreateProcess(shadowCopyFiles, options, ParametersOtherStuff); } catch (Exception ex) { using (var sw = new StringWriter()) { sw.WriteLine("Failed: " + ex.Message); sw.WriteLine("ExeFile=" + options.exeFile); sw.WriteLine("WorkingDirectory=" + options.workingDir); sw.WriteLine("Shadow Copy Files=" + (shadowCopyFiles ? "Y" : "N")); } } }
static void Main(string[] args) { // Read .settings before evaluating command line parametrs which have precedence Options options = new Options(); // Parse the commandline into Dictionary Options ... var parser = new Parser(with => with.EnableDashDash = true); var results = CommandLine.Parser.Default.ParseArguments <Options>(args); CommandLine.Parser.Default.ParseArguments <Options>(args) .WithParsed(r => { options = r; }); List <string> ParametersOtherStuff = new List <string>(); if (options.OtherStuff != null) { // Check if there is a @INI Merge file on command line // If yes, and if it contains system environment variables we will expand those // and replace that parameter by a (temp) file we generated ParametersOtherStuff = readParameter(options); } string exefilename = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; string directoryName = Path.GetDirectoryName(exefilename); string fileNameWoExtension = Path.GetFileNameWithoutExtension(exefilename); string settingsFilename = directoryName + Path.DirectorySeparatorChar + fileNameWoExtension + ".settings"; Console.WriteLine("Read settings from: {0}", settingsFilename); ReadSettings(options, settingsFilename); if (!String.IsNullOrEmpty(options.parameters)) { ParametersParser Parameters = new ParametersParser(options.parameters); foreach (var parameter in Parameters) { if (parameter.Bruto.Length > 0 && parameter.Bruto[0] == '@') { MgMergeFile mgMergeFile = new MgMergeFile(); int nModifications = mgMergeFile.ReadFile(parameter.Bruto.Substring(1)); if (nModifications > 0) { // Our (generated) copy differs from the original file. Effectively this means // that it did contain system environment variables which we did expand // We change the commandline parameter to our version ParametersOtherStuff.Add('@' + mgMergeFile.GetFilenameTemp()); } else { ParametersOtherStuff.Add(parameter.Bruto); } } else { ParametersOtherStuff.Add(parameter.Bruto); } } } try { CreateProcess(options, ParametersOtherStuff); } catch (Exception ex) { using (var sw = new StringWriter()) { sw.WriteLine("Failed: " + ex.Message); sw.WriteLine("ExeFile=" + options.exeFile); sw.WriteLine("WorkingDirectory=" + options.workingDir); } } }