private void CreateProject(DialogResult result)
        {
            lblError.Text       = "";
            _newProjectLocation = txtNewProjectLocation.Text.Trim();
            NewProjectName      = txtNewProjectName.Text.Trim();
            NewProjectType      = (ProjectType)cbxProjectType.SelectedValue;

            if (string.IsNullOrEmpty(NewProjectName) || string.IsNullOrEmpty(_newProjectLocation) || !Directory.Exists(_newProjectLocation))
            {
                lblError.Text = "Error: Please enter a valid project name and location";
            }
            else
            {
                try
                {
                    NewProjectPath = Path.Combine(_newProjectLocation, NewProjectName);
                    bool isInvalidProjectName = new[] { @"/", @"\" }.Any(c => NewProjectName.Contains(c));
                    if (isInvalidProjectName)
                    {
                        throw new Exception("Illegal characters in path");
                    }

                    if (!Directory.Exists(NewProjectPath))
                    {
                        Directory.CreateDirectory(NewProjectPath);
                        Action       = ProjectAction.CreateProject;
                        DialogResult = result;
                    }
                    else
                    {
                        lblError.Text = "Error: Project already exists";
                    }
                }
                catch (Exception ex)
                {
                    lblError.Text = "Error: " + ex.Message;
                }
            }
        }
Beispiel #2
0
        private void btnCreateProject_Click(object sender, EventArgs e)
        {
            string newProjectLocation = txtNewProjectLocation.Text.Trim();

            NewProjectName = txtNewProjectName.Text.Trim();

            if (string.IsNullOrEmpty(NewProjectName) || string.IsNullOrEmpty(newProjectLocation) || !Directory.Exists(newProjectLocation))
            {
                lblError.Text = "Error: Please enter a valid project name and location";
            }
            else
            {
                try {
                    NewProjectPath = Path.Combine(newProjectLocation, NewProjectName);
                    bool isInvalidProjectName = new[] { @"/", @"\" }.Any(c => NewProjectName.Contains(c));
                    if (isInvalidProjectName)
                    {
                        throw new Exception("Illegal characters in path");
                    }

                    if (!Directory.Exists(NewProjectPath))
                    {
                        Directory.CreateDirectory(NewProjectPath);
                        CreateProject = true;
                        DialogResult  = DialogResult.OK;
                    }
                    else
                    {
                        lblError.Text = "Error: Project already exists";
                    }
                }
                catch (Exception ex)
                {
                    lblError.Text = "Error: " + ex.Message;
                }
            }
        }