/// <summary> /// Handles if create project button gets clicked. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void SaveProject_Click(object sender, RoutedEventArgs e) { //Get data from GUI string destination = Destination_textbox.Text; string filename = Filename_textbox.Text; //Event to fire back StateEventArgs stateeventargs = new StateEventArgs(); //Path 1: Empty project if (ValidateInput.EmptyFilename(filename) && ValidateInput.EmptyDestination(destination)) { Prompt("Empty fields", "You must input both the filename and the destination"); return; } //Path 2: else if (ValidateInput.EmptyFilename(filename) && !ValidateInput.EmptyDestination(destination)) { Prompt("No file name entered.", "No filename given, please enter a file name or empty destination."); return; } //Path 3: else if (!ValidateInput.EmptyFilename(filename) && ValidateInput.EmptyDestination(destination)) { Prompt("No destination entered.", "No destination is given, please enter a destination or empty the filename."); return; } //Path 4: Named and destined project else { //Path 4_1 if (!ValidateInput.ValidFileName(filename) && !ValidateInput.ValidDestination(destination)) { Prompt("Invalid file name and destination", "Invalid file name and destination, choose another file name and destination."); return; } //Path 4_2 else if (!ValidateInput.ValidFileName(filename) && ValidateInput.ValidDestination(destination)) { Prompt("Invalid file name", "Invalid file name, choose another file name."); return; } //Path 4_3 else if (ValidateInput.ValidFileName(filename) && !ValidateInput.ValidDestination(destination)) { Prompt("Invalid destination", "Invalid destination, choose another destination."); return; } //Path 4_4 else if (ValidateInput.FileNameExists(filename, destination)) { Prompt("File already exists", "The file already exists for this destination, choose another file name."); return; } //Right Path else { //Save project try { //update givenprojectstate this.givenprojectstate.Destination = destination; this.givenprojectstate.FileName = filename; this.givenprojectstate.Active = true; this.givenprojectstate.Saved = true; //create and save DiffusionCurves.Storage.CreateProject.Create(this.givenprojectstate.FileName, this.givenprojectstate.Destination); DiffusionCurves.Storage.SaveProject.Save(this.givenprojectstate, this.framescontainer); //Set FILENAME and Path in mainwindow stateeventargs.DESTINATION = destination; stateeventargs.FILENAME = filename; //Set ACTIVE and SAVED in mainwindow stateeventargs.ACTIVE = true; stateeventargs.SAVED = true; //Return values to caller if (ProjectSaved != null) { ProjectSaved(this, stateeventargs); } //Dispose NewProject dialog this.Close(); return; } catch (Exception ex) { Prompt("Application error", ex.Message); return; } } } }
/// <summary> /// Handles if create project button gets clicked. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void CreateProject_Click(object sender, RoutedEventArgs e) { //Get data from GUI string destination = Destination_textbox.Text; string filename = Filename_textbox.Text; //Event to fire back StateEventArgs stateeventargs = new StateEventArgs(); //Get width, height Tuple <bool, int> width = ValidateInput.ValidateAndConvertToInt(this.Width.Text); Tuple <bool, int> height = ValidateInput.ValidateAndConvertToInt(this.Height.Text); //Invalid width height gets checked first because it is always mandatory. if (width.Item1 == false) { Prompt("No valid filename for width", "Some non digit characters were caught in the width textbox or it was negative, please reenter correctly."); return; } else if (height.Item1 == false) { Prompt("No valid filename for height", "Some non digit characters were caught in the height textbox or it was negative, please reenter correctly."); return; } //Path 1: Empty project if (ValidateInput.EmptyFilename(filename) && ValidateInput.EmptyDestination(destination)) { //Set new project to _active and _saved to false stateeventargs.ACTIVE = true; stateeventargs.SAVED = false; //Set FILENAME and Path in mainwindow stateeventargs.DESTINATION = string.Empty; //Check on this for dealing with an empty project stateeventargs.FILENAME = "Unsaved Project"; //Set width, height stateeventargs.WIDTH = width.Item2; stateeventargs.HEIGHT = height.Item2; //Return values to caller // Check if there are any Subscribers if (ProjectCreated != null) { ProjectCreated(this, stateeventargs); } this.Close(); } //Path 2: else if (ValidateInput.EmptyFilename(filename) && !ValidateInput.EmptyDestination(destination)) { Prompt("No file name entered.", "No filename given, please enter a file name or empty destination."); return; } //Path 3: else if (!ValidateInput.EmptyFilename(filename) && ValidateInput.EmptyDestination(destination)) { Prompt("No destination entered.", "No destination is given, please enter a destination or empty the filename."); return; } //Path 4: Named and destined project else { //Path 4_1 if (!ValidateInput.ValidFileName(filename) && !ValidateInput.ValidDestination(destination)) { Prompt("Invalid file name and destination", "Invalid file name and destination, choose another file name and destination."); return; } //Path 4_2 else if (!ValidateInput.ValidFileName(filename) && ValidateInput.ValidDestination(destination)) { Prompt("Invalid file name", "Invalid file name, choose another file name."); return; } //Path 4_3 else if (ValidateInput.ValidFileName(filename) && !ValidateInput.ValidDestination(destination)) { Prompt("Invalid destination", "Invalid destination, choose another destination."); return; } //Path 4_4 else if (ValidateInput.FileNameExists(filename, destination)) { Prompt("File already exists", "The file already exists for this destination, choose another file name."); return; } //Right Path else { //Create new project try { Storage.CreateProject.Create(filename, destination); //Set FILENAME and Path in mainwindow stateeventargs.DESTINATION = destination; stateeventargs.FILENAME = filename; //Set ACTIVE and SAVED in mainwindow stateeventargs.ACTIVE = true; stateeventargs.SAVED = true; //Set width, height stateeventargs.WIDTH = width.Item2; stateeventargs.HEIGHT = height.Item2; //Return values to caller if (ProjectCreated != null) { ProjectCreated(this, stateeventargs); } //Dispose NewProject dialog this.Close(); return; } catch (Exception ex) { Prompt("Application error", ex.Message); return; } } } }
public void TestEmptyFilenameOK2() { Assert.True(ValidateInput.EmptyFilename("<name or leave empty>")); }
public void TestEmptyFilenameNotOK() { Assert.False(ValidateInput.EmptyFilename("This is definitely not where I parked my car.")); }
public void TestEmptyFilenameOK1() { Assert.True(ValidateInput.EmptyFilename("")); }