private void ThrowIfInvalidParameter() { if (string.IsNullOrWhiteSpace(Query)) { throw new ArgumentException("Query cannot be null, empty or blank."); } if (Targets == null) { throw new ArgumentException("Targets cannot be null."); } if (!Targets.Databases.Any()) { throw new ArgumentException("Targets' databases cannot be empty."); } foreach (var database in Targets.Databases) { if (string.IsNullOrWhiteSpace(database.ServerName)) { throw new ArgumentException("ServerName cannot be null, empty or blank."); } if (string.IsNullOrWhiteSpace(database.DatabaseName)) { throw new ArgumentException("DatabaseName cannot be null, empty or blank."); } } if (Targets.ExtraValueTitles == null) { throw new ArgumentException("Targets' ExtraValueTitles cannot be null."); } if (!Directory.Exists(OutputDirectory)) { throw new ArgumentException("OutputDirectory does not exist."); } if (!Overwrite && File.Exists(OutputDirectory + "\\" + OutputFile)) { throw new ArgumentException("OutputFile already exists in directory."); } if (ConnectionTimeout < 0) { throw new ArgumentException("Connection timeout cannot be negative."); } if (ConnectionTimeout == 0) { throw new ArgumentException("Connection timeout cannot be 0 (infinite)."); } if (ConnectionTimeout > 604800) { throw new ArgumentException("Connection timeout cannot be more than 604800 seconds (one week)."); } if (CommandTimeout < 0) { throw new ArgumentException("Command timeout cannot be negative."); } if (CommandTimeout > 604800) { throw new ArgumentException("Command timeout cannot be more than 604800 seconds (one week)."); } if (Parallelism < 1) { throw new ArgumentException("Parallelism cannot be less than 1."); } if (Parallelism > 32) { throw new ArgumentException("Parallelism cannot be more than 32."); } uint nullsColorValue; if (!uint.TryParse(NullsColor, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out nullsColorValue)) { throw new ArgumentException("NullsColor is not a valid hexadecimal value."); } if (nullsColorValue > 0xFFFFFF) { throw new ArgumentException("NullsColor is not a valid 24bits RGB color value."); } if (SheetLabels == null) { throw new ArgumentException("SheetLabels cannot be null."); } foreach (var label in SheetLabels) { if (string.IsNullOrWhiteSpace(label)) { throw new ArgumentException("Sheet label cannot be null, empty or blank."); } } if (!string.IsNullOrEmpty(ApplicationName) && ApplicationName.Trim() == string.Empty) { throw new ArgumentException("ApplicationName cannot be white spaces."); } }
private void ThrowIfInvalidParameter() { if (string.IsNullOrWhiteSpace(Query)) { throw new ArgumentException("Query cannot be null, empty or blank."); } if (Targets == null) { throw new ArgumentException("Targets cannot be null."); } if (!Targets.Databases.Any()) { throw new ArgumentException("Targets' databases cannot be empty."); } foreach (var database in Targets.Databases) { if (string.IsNullOrWhiteSpace(database.ServerName)) { throw new ArgumentException("ServerName cannot be null, empty or blank."); } if (string.IsNullOrWhiteSpace(database.DatabaseName)) { throw new ArgumentException("DatabaseName cannot be null, empty or blank."); } } if (Targets.ExtraValueTitles == null) { throw new ArgumentException("Targets' ExtraValueTitles cannot be null."); } if (!Directory.Exists(OutputDirectory)) { throw new ArgumentException("OutputDirectory does not exist."); } var outputFilePath = Path.Combine(OutputDirectory, OutputFile); if (!Overwrite && File.Exists(outputFilePath)) { throw new ArgumentException("OutputFile already exists in directory."); } if (ConnectionTimeout < 0) { throw new ArgumentException("Connection timeout cannot be negative."); } if (ConnectionTimeout == 0) { throw new ArgumentException("Connection timeout cannot be 0 (infinite)."); } if (ConnectionTimeout > 604800) { throw new ArgumentException("Connection timeout cannot be more than 604800 seconds (one week)."); } if (CommandTimeout < 0) { throw new ArgumentException("Command timeout cannot be negative."); } if (CommandTimeout > 604800) { throw new ArgumentException("Command timeout cannot be more than 604800 seconds (one week)."); } if (Parallelism < 1) { throw new ArgumentException("Parallelism cannot be less than 1."); } if (Parallelism > 32) { throw new ArgumentException("Parallelism cannot be more than 32."); } if (!uint.TryParse(NullsColor, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var nullsColorValue)) { throw new ArgumentException("NullsColor is not a valid hexadecimal value."); } if (nullsColorValue > 0xFFFFFF) { throw new ArgumentException("NullsColor is not a valid 24bits RGB color value."); } if (SheetLabels == null) { throw new ArgumentException("SheetLabels cannot be null."); } foreach (var label in SheetLabels) { if (string.IsNullOrWhiteSpace(label)) { throw new ArgumentException("Sheet label cannot be null, empty or blank."); } } if (!string.IsNullOrEmpty(ApplicationName) && ApplicationName.Trim().Length == 0) { throw new ArgumentException("ApplicationName cannot be white spaces."); } if (Exporter != ExporterType.Excel && Exporter != ExporterType.Csv) { throw new ArgumentException("Exporter must be either \"csv\" or \"excel\"."); } if (string.IsNullOrEmpty(CsvDelimiter)) { throw new ArgumentException("CSV delimiter cannot be empty."); } if (CsvDelimiter.Length != 1) { throw new ArgumentException("CSV delimiter must be only one character."); } if (Base10Threshold < 0) { throw new ArgumentException("Base 10 threshold cannot be negative."); } if (Base16Threshold < 0) { throw new ArgumentException("Base 16 threshold cannot be negative."); } if (Base64Threshold < 0) { throw new ArgumentException("Base 64 threshold cannot be negative."); } }