Пример #1
0
        /// <summary>
        /// Convert the project
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void btnConvert_Click(object sender, EventArgs e)
        {
            ConvertToMSBuildFormat converter = null;
            string project, folder;
            bool isValid = true;

            epErrors.Clear();
            epErrors.SetIconPadding(txtProjectFile, btnSelectProject.Width + 5);
            epErrors.SetIconPadding(txtNewProjectFolder, btnSelectNewFolder.Width + 5);

            project = txtProjectFile.Text.Trim();

            if(txtNewProjectFolder.Enabled)
                folder = txtNewProjectFolder.Text.Trim();
            else
                folder = Path.GetDirectoryName(txtNewProjectFolder.Text);

            if(project.Length == 0)
            {
                epErrors.SetError(txtProjectFile, "A project file must be specified");
                isValid = false;
            }
            else
                if(!File.Exists(project))
                {
                    epErrors.SetError(txtProjectFile, "The specified project file does not exist");
                    isValid = false;
                }

            if(folder.Length == 0)
            {
                epErrors.SetError(txtNewProjectFolder, "An output folder for the converted project must " +
                    "be specified");
                isValid = false;
            }

            if(isValid)
            {
                project = Path.GetFullPath(project);
                folder = Path.GetFullPath(folder);

                if(FolderPath.TerminatePath(Path.GetDirectoryName(project)) == FolderPath.TerminatePath(folder))
                {
                    epErrors.SetError(txtNewProjectFolder, "The output folder cannot match the folder of the " +
                        "original project");
                    isValid = false;
                }
            }

            if(!isValid)
                return;

            try
            {
                this.Cursor = Cursors.WaitCursor;

                switch(cboProjectFormat.SelectedIndex)
                {
                    case 1:
                        if(currentProject == null)
                            converter = new ConvertFromNDoc(txtProjectFile.Text, txtNewProjectFolder.Text);
                        else
                            converter = new ConvertFromNDoc(txtProjectFile.Text, currentProject);
                        break;

                    case 2:
                        if(currentProject == null)
                            converter = new ConvertFromDocProject(txtProjectFile.Text, txtNewProjectFolder.Text);
                        else
                            converter = new ConvertFromDocProject(txtProjectFile.Text, currentProject);
                        break;

                    case 3:
                        if(currentProject == null)
                            converter = new ConvertFromSandcastleGui(txtProjectFile.Text, txtNewProjectFolder.Text);
                        else
                            converter = new ConvertFromSandcastleGui(txtProjectFile.Text, currentProject);
                        break;

                    case 4:
                        if(currentProject == null)
                            converter = new ConvertFromMSExampleGui(txtProjectFile.Text, txtNewProjectFolder.Text);
                        else
                            converter = new ConvertFromMSExampleGui(txtProjectFile.Text, currentProject);
                        break;

                    default:
                        if(currentProject == null)
                            converter = new ConvertFromShfbFile(txtProjectFile.Text, txtNewProjectFolder.Text);
                        else
                            converter = new ConvertFromShfbFile(txtProjectFile.Text, currentProject);
                        break;
                }

                newProjectFilename = converter.ConvertProject();

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch(Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);

                BuilderException bex = ex as BuilderException;

                if(bex != null)
                    MessageBox.Show("Unable to convert project.  Reason: Error " + bex.ErrorCode + ":" +
                        bex.Message, Constants.AppName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                else
                    MessageBox.Show("Unable to convert project.  Reason: " + ex.Message, Constants.AppName,
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                this.Cursor = Cursors.Default;

                if(converter != null)
                    converter.Dispose();
            }
        }
Пример #2
0
        /// <summary>
        /// Convert the project
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void btnConvert_Click(object sender, EventArgs e)
        {
            ConvertToMSBuildFormat converter = null;
            string project, folder;
            bool   isValid = true;

            epErrors.Clear();
            epErrors.SetIconPadding(txtProjectFile, btnSelectProject.Width + 5);
            epErrors.SetIconPadding(txtNewProjectFolder, btnSelectNewFolder.Width + 5);

            project = txtProjectFile.Text.Trim();

            if (txtNewProjectFolder.Enabled)
            {
                folder = txtNewProjectFolder.Text.Trim();
            }
            else
            {
                folder = Path.GetDirectoryName(txtNewProjectFolder.Text);
            }

            if (project.Length == 0)
            {
                epErrors.SetError(txtProjectFile, "A project file must be specified");
                isValid = false;
            }
            else
            if (!File.Exists(project))
            {
                epErrors.SetError(txtProjectFile, "The specified project file does not exist");
                isValid = false;
            }

            if (folder.Length == 0)
            {
                epErrors.SetError(txtNewProjectFolder, "An output folder for the converted project must " +
                                  "be specified");
                isValid = false;
            }

            if (isValid)
            {
                project = Path.GetFullPath(project);
                folder  = Path.GetFullPath(folder);

                if (FolderPath.TerminatePath(Path.GetDirectoryName(project)) == FolderPath.TerminatePath(folder))
                {
                    epErrors.SetError(txtNewProjectFolder, "The output folder cannot match the folder of the " +
                                      "original project");
                    isValid = false;
                }
            }

            if (!isValid)
            {
                return;
            }

            try
            {
                this.Cursor = Cursors.WaitCursor;

                switch (cboProjectFormat.SelectedIndex)
                {
                case 1:
                    if (currentProject == null)
                    {
                        converter = new ConvertFromNDoc(txtProjectFile.Text, txtNewProjectFolder.Text);
                    }
                    else
                    {
                        converter = new ConvertFromNDoc(txtProjectFile.Text, currentProject);
                    }
                    break;

                case 2:
                    if (currentProject == null)
                    {
                        converter = new ConvertFromDocProject(txtProjectFile.Text, txtNewProjectFolder.Text);
                    }
                    else
                    {
                        converter = new ConvertFromDocProject(txtProjectFile.Text, currentProject);
                    }
                    break;

                case 3:
                    if (currentProject == null)
                    {
                        converter = new ConvertFromSandcastleGui(txtProjectFile.Text, txtNewProjectFolder.Text);
                    }
                    else
                    {
                        converter = new ConvertFromSandcastleGui(txtProjectFile.Text, currentProject);
                    }
                    break;

                case 4:
                    if (currentProject == null)
                    {
                        converter = new ConvertFromMSExampleGui(txtProjectFile.Text, txtNewProjectFolder.Text);
                    }
                    else
                    {
                        converter = new ConvertFromMSExampleGui(txtProjectFile.Text, currentProject);
                    }
                    break;

                default:
                    if (currentProject == null)
                    {
                        converter = new ConvertFromShfbFile(txtProjectFile.Text, txtNewProjectFolder.Text);
                    }
                    else
                    {
                        converter = new ConvertFromShfbFile(txtProjectFile.Text, currentProject);
                    }
                    break;
                }

                newProjectFilename = converter.ConvertProject();

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);

                BuilderException bex = ex as BuilderException;

                if (bex != null)
                {
                    MessageBox.Show("Unable to convert project.  Reason: Error " + bex.ErrorCode + ":" +
                                    bex.Message, Constants.AppName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    MessageBox.Show("Unable to convert project.  Reason: " + ex.Message, Constants.AppName,
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            finally
            {
                this.Cursor = Cursors.Default;

                if (converter != null)
                {
                    converter.Dispose();
                }
            }
        }