private static void readOutput(WorkSettings settings, string value) { if (value.Length > 0) { settings.FileNameForReport = value; } }
private static void readInclude(WorkSettings settings, string value) { if (value.Length > 0) { settings.includeItems.Add(value); } }
private static void readSettingsFile(WorkSettings settings, string value) { if (!File.Exists(value)) { throw new SettingsException("Cannot find settings file (" + value + ")"); } settings.settingsFile = value; }
private static void readTargetWorkDir(WorkSettings settings, string value) { if (!Directory.Exists(value)) { throw new SettingsException("Cannot find target working dir (" + value + ")"); } settings.TargetWorkingDir = Path.GetFullPath(value); }
private static void readTarget(WorkSettings settings, string value) { if (!File.Exists(value)) { throw new SettingsException("Cannot find target (" + value + ")"); } settings.TargetPath = Path.GetFullPath(value); }
private static void readLogLevel(WorkSettings settings, string value) { try { settings.logLevel = int.Parse(value, CultureInfo.InvariantCulture); } catch (Exception ex) { throw new SettingsException("Wrong value for --log (" + ex.Message + ")"); } }
private void btnLoad_Click(object sender, EventArgs e) { dlgOpen.Filter = "Settings files (*.xml)|*.xml"; if (dlgOpen.ShowDialog(this) != DialogResult.OK) { return; } var settings = new WorkSettings { SettingsFile = dlgOpen.FileName }; try { settings.ReadSettingsFile(); } catch (Exception ex) { ShowInformation("Cannot load settings (" + ex.Message + ")"); return; } tbPath.Text = settings.TargetPath; tbWorkingDir.Text = settings.TargetWorkingDir; tbArgs.Text = settings.TargetArgs; SetLoggingEnabled(chkLoggingDumpMethod, settings.LogLevel, Logging.DumpMethod); SetLoggingEnabled(chkLoggingDumpInstrumentation, settings.LogLevel, Logging.DumpInstrumentation); SetLoggingEnabled(chkLoggingInstrumentMessages, settings.LogLevel, Logging.MethodInstrumentation); SetLoggingEnabled(chkLoggingMethodInner, settings.LogLevel, Logging.MethodInner); SetLoggingEnabled(chkLoggingSkipByRule, settings.LogLevel, Logging.SkipByRules); SetLoggingEnabled(chkLoggingSkipByState, settings.LogLevel, Logging.SkipByState); ckbFlattenDomains.Checked = settings.DisableFlattenDomains; tbRules.Text = string.Empty; foreach (var s in settings.IncludeItems) { if (tbRules.Text.Length > 0) tbRules.Text = tbRules.Text + "\r\n"; tbRules.Text = tbRules.Text + "+" + s; } foreach (var s in settings.ExcludeItems) { if (tbRules.Text.Length > 0) tbRules.Text = tbRules.Text + "\r\n"; tbRules.Text = tbRules.Text + "-" + s; } }
private static void readTargetWorkDir(WorkSettings settings, string value) { if (!Directory.Exists(value)) throw new SettingsException("Cannot find target working dir (" + value + ")"); settings.TargetWorkingDir = Path.GetFullPath(value); }
private static void readHelp(WorkSettings settings) { settings.printLongHelp = true; }
private static void readVersion(WorkSettings settings) { settings.printVersion = true; }
private static void register(WorkSettings settings) { settings.Register = true; }
private static void readGenerateSettingsFile(WorkSettings settings, string value) { settings.generateSettingsFileName = value; }
private static void readDisableDomainFlatten(WorkSettings settings) { settings.DisableFlattenDomains = true; }
private static void readInclude(WorkSettings settings, string value) { if (value.Length > 0) settings.includeItems.Add(value); }
private static void readSettingsFile(WorkSettings settings, string value) { if (!File.Exists(value)) throw new SettingsException("Cannot find settings file (" + value + ")"); settings.settingsFile = value; }
private static void readTargetArgs(WorkSettings settings, string value) { settings.TargetArgs = value; }
private static void readOutput(WorkSettings settings, string value) { if (value.Length > 0) settings.FileNameForReport = value; }
private static void readErrorsToStdOut(WorkSettings settings) { settings.ErrorsToStdout = true; }
private static void readTarget(WorkSettings settings, string value) { if (!File.Exists(value)) throw new SettingsException("Cannot find target (" + value + ")"); settings.TargetPath = Path.GetFullPath(value); }
private void btnSave_Click(object sender, EventArgs e) { var settings = new WorkSettings { TargetPath = TargetPath, TargetArgs = TargetArgs, TargetWorkingDir = TargetWorkingDir, FileNameForReport = FileNameForReport, LogLevel = ((int)LogLevel), DisableFlattenDomains = ckbFlattenDomains.Checked }; settings.IncludeRules(IncludeItems); settings.ExcludeRules(ExcludeItems); dlgSave.Filter = "Settings files (*.xml)|*.xml"; if (dlgSave.ShowDialog(this) != DialogResult.OK) { return; } try { settings.GenerateSettingsFileName = dlgSave.FileName; settings.GenerateSettingsFile(); ShowInformation("Settings were saved!"); } catch (Exception ex) { ShowInformation("Cannot save settings (" + ex.Message + ")"); } }
static int Main(string[] args) { try { var settings = new WorkSettings(); if (!settings.InitializeFromCommandLine(args)) { return -1; } if (settings.ErrorsToStdout) { Console.SetError(Console.Out); } using (Registration.Create(settings.Register ? System.Reflection.Assembly.GetExecutingAssembly().Location : null)) { //Console.ReadLine(); var connector = new Connector(); connector.StatusMessageReceived += connector_StatusMessageReceived; connector.LogEntryReceived += connector_LogEntryReceived; connector.UseFileLogging(true); connector.UsePipeLogging(true); connector.SetLogging((Logging)settings.LogLevel); foreach (var item in settings.IncludeItems) { try { connector.IncludeItem(item); } catch (ArgumentException) { Console.Error.WriteLine("Item '" + item + "' have wrong format"); } } foreach (var item in settings.ExcludeItems) { try { connector.ExcludeItem(item); } catch (ArgumentException) { Console.Error.WriteLine("Item '" + item + "' have wrong format"); } } var options = new SessionRunOptions { TargetPath = settings.TargetPath, TargetDirectory = settings.TargetWorkingDir, TargetArguments = settings.TargetArgs, RedirectOutput = true, DelayClose = false, FlattenDomains = !settings.DisableFlattenDomains }; connector.Options = options; connector.StartTarget(); try { var writer = settings.OutputToFile ? new XmlTextWriter(File.CreateText(settings.FileNameForReport)) : new XmlTextWriter(Console.Out); using (writer) { writer.Formatting = Formatting.Indented; writer.Indentation = 1; writer.IndentChar = ' '; ReportSerializer.Save(writer, connector.Report); } } catch (Exception ex) { Console.Error.WriteLine("Can't save report (" + ex.Message + ")"); } #if DEBUG WriteListOfSkippedItems(connector.Report); #endif if (connector.TargetExitCode.HasValue) return connector.TargetExitCode.Value; } // end using } catch (SettingsException ex) { Console.Error.WriteLine(ex.Message); return -1; } catch (Exception ex) { Console.Error.WriteLine(ex.Message); Console.Error.WriteLine(ex.StackTrace); return -1; } return 0; }