public override InputValidationResult ValidateInput() { if (FileName.IsNullOrWhiteSpace()) { return(InputValidationResult.Error(Resources.StaticCommands.PathCannotBeEmpty)); } try { new FileInfo(FileName); } catch (Exception) { return(InputValidationResult.Error(Resources.StaticCommands.InvalidFilename)); } if (!Verb.IsNullOrWhiteSpace() && !new ProcessStartInfo(FileName).Verbs.Contains(Verb)) { return (new InputValidationResult( Resources.StaticCommands.System_ExecuteProcessCommand_ValidateInput_VerbDoesNotExist, ValidationState.WarningYesNo)); } return(InputValidationResult.Successful); }
protected string RequestInput(string message, Func <string, InputValidationResult> inputValidator = null) { System.Console.WriteLine(message); string input = System.Console.ReadLine(); if (inputValidator != null) { while (true) { InputValidationResult result = inputValidator.Invoke(input); if (!result.IsSuccessful) { System.Console.WriteLine("Input error:"); foreach (string error in result.ErrorMessages) { System.Console.WriteLine($"- {error}"); } System.Console.WriteLine(message); input = System.Console.ReadLine(); } else { break; } } } return(input); }
public override InputValidationResult ValidateInput() { if (Path.IsNullOrWhiteSpace()) { return(new InputValidationResult(Resources.StaticCommands.PathCannotBeEmpty, ValidationState.Error)); } var file = new FileInfo(Path); if (!file.Exists) { return (InputValidationResult.Error(string.Format(Resources.StaticCommands.TheFileDoesnotExist, file.Name))); } if (file.Length > 1024 * 1024 * 5) { return (new InputValidationResult( string.Format(Resources.StaticCommands.WarningFileAbove5MiB, file.Name), ValidationState.WarningYesNo)); } return(InputValidationResult.Successful); }
protected string RequestInput(string message, Func <string, InputValidationResult> inputValidator = null) { Console.WriteLine(message); // Get input from console. string input = Console.ReadLine(); if (inputValidator != null) { while (true) { // Validate input. InputValidationResult result = inputValidator.Invoke(input); if (!result.IsSuccessful) { // Display error. Console.WriteLine("Input error:"); foreach (string error in result.ErrorMessages) { System.Console.WriteLine($"- {error}"); } Console.WriteLine(message); input = Console.ReadLine(); } else { // Input is valid. break; } } } return(input); }
private InputValidationResult ValidateInput() { InputValidationResult result = InputValidationResult.VALID; if (!chkCPP.Checked && !chkCSharp.Checked && !chkJava.Checked && !chkPython.Checked && !radMySQL.Checked && !radOracle.Checked && !radTSQL.Checked) { result = InputValidationResult.NO_OUTPUT; } else if (String.IsNullOrWhiteSpace(txtEntityName.Text)) { result = InputValidationResult.INVALID_ENTITY_NAME; } else { // Finally, validate the attribute list foreach (var attribute in attributeList) { if (result != InputValidationResult.VALID) { break; } result = attribute.ValidateInput(); } } return(result); }
public override InputValidationResult ValidateInput(List <IBuilderProperty> currentBuilderProperties, ConnectionBuilderProperty currentBuilderProperty) { if (currentBuilderProperty.IpAddresses.Count == 0) { return(InputValidationResult.Error("@ErrorIpAddress")); } return(InputValidationResult.Successful); }
public override InputValidationResult ValidateInput() { if (Text.IsNullOrWhiteSpace()) { return(InputValidationResult.Error(Resources.StaticCommands.ShowMessageBoxCommand_ValidateInput_TextCannotBeEmpty)); } return(InputValidationResult.Successful); }
public override InputValidationResult ValidateInput(List <IBuilderProperty> currentBuilderProperties, ChangeIconBuilderProperty currentBuilderProperty) { if (currentBuilderProperty.ChangeIcon && string.IsNullOrWhiteSpace(IconPath)) { return(InputValidationResult.Error((string)Application.Current.Resources["ErrorIcon"])); } return(InputValidationResult.Successful); }
public override InputValidationResult ValidateInput() { if (Text.IsNullOrWhiteSpace()) { return(InputValidationResult.Error(Resources.StaticCommands.Interaction_ShowBalloonTooltipCommand_ValidateInput_TextCannotBeEmpty)); } return(InputValidationResult.Successful); }
public override InputValidationResult ValidateInput(List <IBuilderProperty> currentBuilderProperties, RespawnTaskBuilderProperty currentBuilderProperty) { if (string.IsNullOrWhiteSpace(currentBuilderProperty.TaskName)) { return(InputValidationResult.Error((string)Application.Current.Resources["ErrorRespawnTaskName"])); } return(InputValidationResult.Successful); }
public override InputValidationResult ValidateInput(List <IBuilderProperty> currentBuilderProperties, DataFolderBuilderProperty currentBuilderProperty) { if (string.IsNullOrEmpty(currentBuilderProperty.Path)) { return(InputValidationResult.Error((string)Application.Current.Resources["ErrorDataFolder"])); } return(InputValidationResult.Successful); }
public override InputValidationResult ValidateInput(List <IBuilderProperty> currentBuilderProperties, MutexBuilderProperty currentBuilderProperty) { if (string.IsNullOrWhiteSpace(Mutex)) { return(InputValidationResult.Error((string)Application.Current.Resources["ErrorMutex"])); } return(InputValidationResult.Successful); }
public override InputValidationResult ValidateInput(List <IBuilderProperty> currentBuilderProperties, WatchdogBuilderProperty currentBuilderProperty) { if (currentBuilderProperty.IsEnabled && string.IsNullOrWhiteSpace(currentBuilderProperty.Name)) { return(InputValidationResult.Error((string)Application.Current.Resources["ErrorWatchdogFilename"])); } return(InputValidationResult.Successful); }
public override InputValidationResult ValidateInput() { if (WallpaperUrl.IsNullOrWhiteSpace()) { return (InputValidationResult.Error( Resources.StaticCommands.System_ChangeWallpaperCommand_ValidateInput_WallpaperUrlCannotBeEmpty)); } return(InputValidationResult.Successful); }
public override InputValidationResult ValidateInput(List <IBuilderProperty> currentBuilderProperties, InstallationLocationBuilderProperty currentBuilderProperty) { if (string.IsNullOrWhiteSpace(currentBuilderProperty.Path) && currentBuilderProperties.OfType <InstallBuilderProperty>().First().Install) { return(InputValidationResult.Error((string)Application.Current.Resources["ErrorInstallation"])); } return(InputValidationResult.Successful); }
public override InputValidationResult ValidateInput(List <IBuilderProperty> currentBuilderProperties, ClientTagBuilderProperty currentBuilderProperty) { if (currentBuilderProperty.ClientTag == null) { return (InputValidationResult.Error( "The client tag can not be null. If you see this message, please report it to the developer because that shouldn't be possible")); } return(InputValidationResult.Successful); }
public override InputValidationResult ValidateInput() { if (DownloadUrl.IsNullOrWhiteSpace()) { return(new InputValidationResult(Resources.StaticCommands.UrlCannotBeEmpty, ValidationState.Error)); } if (!string.IsNullOrEmpty(Hash) && (Hash?.Length != 64 || !Hash.IsHex())) { return(InputValidationResult.Error(Resources.StaticCommands.InvalidSHA256HashValueHex)); } return(InputValidationResult.Successful); }
public override async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { string productId = RequestInput("Enter product ID:", input => { if (Guid.TryParse(input, out Guid i)) { return(InputValidationResult.Success); } return(InputValidationResult.WithErrors("Invalid product ID.")); }); await _commandDelegator.SendAsync(new DeactivateProductCommand(Guid.Parse(productId))); System.Console.WriteLine("Product deactivated."); }
public override async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { int productId = RequestInput <int>("Enter ID of product to activate:", input => { if (int.TryParse(input, out int i)) { return(InputValidationResult.Success); } return(InputValidationResult.WithErrors("Invalid product ID.")); }); await _commandDispatcher.SendAsync(new ActivateProductCommand(productId)); Console.WriteLine("Product activated."); }
private void ShowInputErrorDialog(InputValidationResult result) { var message = "Generic Error"; switch (result) { case InputValidationResult.NO_OUTPUT: message = "You must select a language to generate."; break; case InputValidationResult.INVALID_ENTITY_NAME: message = "You must provide an entity name."; break; case InputValidationResult.INVALID_SCHEMA_NAME: message = "You must provide a schema name."; break; case InputValidationResult.INVALID_NAMESPACE: message = "You must provide a namespace."; break; case InputValidationResult.INVALID_ATTRIBUTE_NAME: message = "You must provide a name for each attribute."; break; case InputValidationResult.INVALID_ATTRIBUTE_SIZE: message = "One or more of your attributes have an invalid size."; break; case InputValidationResult.INVALID_ATTRIBUTE_REF_ENTITY: message = "Foreign Keys require a reference entity/table."; break; case InputValidationResult.INVALID_ATTRIBUTE_REF_ATTRIBUTE: message = "Foreign Keys require an entity's primary key as a reference attribute."; break; default: message = "A generic error occurred. Please review your configuration and report bugs to [email protected]"; break; } // Display error dialog with a message for the result MessageBox.Show(this, message, "Input Validation Error", MessageBoxButtons.OKCancel); }
public override async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { string productId = RequestInput("Enter ID of product to display:", input => { if (int.TryParse(input, out int i)) { return(InputValidationResult.Success); } return(InputValidationResult.WithErrors("Invalid product ID.")); }); Product product = await _queryDispatcher.DispatchAsync <QueryProductById, Product>(new QueryProductById(int.Parse(productId))); System.Console.WriteLine($"Product ID: {product.Id}, Product Name: {product.Name}, IsActive: {product.IsActive}"); System.Console.WriteLine(Environment.NewLine); }
public override InputValidationResult ValidateInput() { Uri outUri; if (!Uri.TryCreate(Url, UriKind.Absolute, out outUri) || (outUri.Scheme != Uri.UriSchemeHttp && outUri.Scheme != Uri.UriSchemeHttps)) { return(new InputValidationResult(Resources.StaticCommands.System_OpenWebsiteCommand_ValidateInput_InvalidUrl, ValidationState.WarningYesNo)); } if (Times <= 0) { return(InputValidationResult.Error(Resources.StaticCommands.System_OpenWebsiteCommand_ValidateInput_Times)); } return(InputValidationResult.Successful); }
public override async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { string id = RequestInput("Enter product ID:", input => { if (int.TryParse(input, out int i)) { return(InputValidationResult.Success); } return(InputValidationResult.WithErrors("Invalid product ID.")); }); string productName = RequestInput("Enter product name:"); await _commandDelegator.SendAsync(new RegisterProductCommand(int.Parse(id), productName)); System.Console.WriteLine($"{productName} registered."); }
public override async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { int productId = RequestInput <int>("Enter ID of product to display:", input => { if (int.TryParse(input, out int i)) { return(InputValidationResult.Success); } return(InputValidationResult.WithErrors("Invalid product ID.")); }); ProductReadModel product = await _productReadSideRepository.GetProductByIdAsync(productId); if (product == null) { Console.WriteLine("Product not found."); return; } Console.WriteLine($"Product ID: {product.ProductId}, Product Name: {product.ProductName}, IsActive: {product.IsActive}"); }
public override InputValidationResult ValidateInput(List <IBuilderProperty> currentBuilderProperties, AutostartBuilderProperty currentBuilderProperty) { if (currentBuilderProperty.AutostartMethod == StartupMethod.Disable) { return(InputValidationResult.Successful); } if ((currentBuilderProperty.TryAllAutostartMethodsOnFail || currentBuilderProperty.AutostartMethod == StartupMethod.TaskScheduler) && string.IsNullOrWhiteSpace(currentBuilderProperty.TaskSchedulerTaskName)) { return(InputValidationResult.Error((string)Application.Current.Resources["ErrorTaskAutostart"])); } if ((currentBuilderProperty.TryAllAutostartMethodsOnFail || currentBuilderProperty.AutostartMethod == StartupMethod.Registry) && string.IsNullOrWhiteSpace(currentBuilderProperty.RegistryKeyName)) { return(InputValidationResult.Error((string)Application.Current.Resources["ErrorAutostart"])); } if ((currentBuilderProperty.TryAllAutostartMethodsOnFail || currentBuilderProperty.AutostartMethod == StartupMethod.TaskScheduler)) { //we check if the tasks have the same name which would fail because they would override each other var respawnTaskBuilderProperty = currentBuilderProperties.OfType <RespawnTaskBuilderProperty>().FirstOrDefault(); if (respawnTaskBuilderProperty != null && respawnTaskBuilderProperty.IsEnabled && respawnTaskBuilderProperty.TaskName.Equals(currentBuilderProperty.TaskSchedulerTaskName, StringComparison.OrdinalIgnoreCase)) { return(InputValidationResult.Error((string)Application.Current.Resources["ErrorTasksHaveSameName"])); } } return(InputValidationResult.Successful); }
public override async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { string productId = RequestInput("Enter ID of product to display:", input => { if (Guid.TryParse(input, out Guid i)) { return(InputValidationResult.Success); } return(InputValidationResult.WithErrors("Invalid product ID.")); }); ProductReadModel product = await _queryDispatcher.DispatchAsync <QueryProductById, ProductReadModel>(new QueryProductById(Guid.Parse(productId))); if (product != null) { System.Console.WriteLine($"Product ID: {product.ProductId}, Product Name: {product.ProductName}, IsActive: {product.IsActive}"); } else { System.Console.WriteLine($"Product with ID {productId} was not found."); } }
private void btnGenerate_Click(object sender, EventArgs e) { // First, validate each input InputValidationResult validationResult = ValidateInput(); if (validationResult != InputValidationResult.VALID) { ShowInputErrorDialog(validationResult); } else { // Build DALEntity and DALAttributes DALEntity entity = new DALEntity(txtEntityName.Text, txtDatabaseName.Text, txtSchemaName.Text, txtNamespace.Text); foreach (SQLAttributePicker attributePicker in attributeList) { DALAttributes attribute = new DALAttributes(attributePicker.AttributeName, attributePicker.DataType, attributePicker.AttributeSize, attributePicker.IsPrimaryKey, attributePicker.AutoIncrement, attributePicker.IsForeignKey, attributePicker.ReferenceEntity, attributePicker.ReferenceAttribute); entity.Attributes.Add(attribute); } String outputPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); if (entity.Attributes.Where(x => x.IsPrimaryKey).Count() < 1) { DialogResult result = MessageBox.Show("No primary key has been selected for this entity. Without a primary key several DAL method such as Load and Update cannot function appropriately. For this reason, only a class library will be generated. Would you like to continue?", "Warning", MessageBoxButtons.OKCancel); if (result == DialogResult.Cancel) { return; } } if (radTSQL.Checked) { // Generate TSQL Create Table and Stored Procedure scripts. var tsqlGenerator = new TSQLTemplate(); tsqlGenerator.GenerateContent(entity, outputPath); } if (radMySQL.Checked) { // Generate MySQL Create Table and Stored Procedure scripts. var mysqlGenerator = new MySQLTemplate(); mysqlGenerator.GenerateContent(entity, outputPath); } if (radOracle.Checked) { // Generate Oracle Create Table and Stored Procedure scripts. } if (chkCPP.Checked) { // Generate C++ DAL } if (chkCSharp.Checked) { // Generate C# DAL } if (chkJava.Checked) { // Generate Java DAL } if (chkPython.Checked) { // Generate Python DAL } if (chkPHP.Checked) { // Generate PHP DAL var phpGenerator = new PHPTemplate(); phpGenerator.GenerateContent(entity, outputPath); } MessageBox.Show(this, "Success", "Content Generated Successfully", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void btnGenerate_Click(object sender, EventArgs e) { // First, validate each input InputValidationResult validationResult = ValidateInput(); if (validationResult != InputValidationResult.VALID) { ShowInputErrorDialog(validationResult); } else { // Build DALEntity and DALAttributes DALEntity entity = new DALEntity(txtEntityName.Text, txtDatabaseName.Text, txtSchemaName.Text, txtNamespace.Text); foreach (SQLAttributePicker attributePicker in attributeList) { DALAttributes attribute = new DALAttributes(attributePicker.AttributeName, attributePicker.DataType, attributePicker.AttributeSize, attributePicker.IsPrimaryKey, attributePicker.AutoIncrement, attributePicker.IsForeignKey, attributePicker.ReferenceEntity, attributePicker.ReferenceAttribute); entity.Attributes.Add(attribute); } String outputPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); if (radTSQL.Checked) { // Generate TSQL Create Table and Stored Procedure scripts. var tsqlGenerator = new TSQLTemplate(); tsqlGenerator.GenerateContent(entity, outputPath); } if (radMySQL.Checked) { // Generate MySQL Create Table and Stored Procedure scripts. var mysqlGenerator = new MySQLTemplate(); mysqlGenerator.GenerateContent(entity, outputPath); } if (radOracle.Checked) { // Generate Oracle Create Table and Stored Procedure scripts. } if (chkCPP.Checked) { // Generate C++ DAL } if (chkCSharp.Checked) { // Generate C# DAL } if (chkJava.Checked) { // Generate Java DAL } if (chkPython.Checked) { // Generate Python DAL } if (chkPHP.Checked) { // Generate PHP DAL var phpGenerator = new PHPTemplate(); phpGenerator.GenerateContent(entity, outputPath); } MessageBox.Show(this, "Success", "Content Generated Successfully", MessageBoxButtons.OK, MessageBoxIcon.Information); } }