public ConfirmationDialog(Project oldProject, Project newProject)
        {
            LocalizationService = ServiceLocator.GetInstance<ILocalizationService>();
            this.oldProject = oldProject;
            this.newProject = newProject;

            InitializeComponent();
            Localize();
        }
        public void CheckInChanges(string solutionDirectoryPath, Project oldProject, Project newProject)
        {
            using(SvnClient svnClient = new SvnClient())
            {
                SvnCommitArgs svnCommitArgs = new SvnCommitArgs { LogMessage = string.Format("Renamed project {0} into {1}", oldProject.ProjectName, newProject.ProjectName) };

                // TODO NKO: Do something with the result
                SvnCommitResult result;
                svnClient.Commit(solutionDirectoryPath, svnCommitArgs, out result);
            }
        }
        public DialogResult ShowConfirmationDialog(Project oldProject, Project newProject)
        {
            ConfirmationDialog confirmationDialog = new ConfirmationDialog(oldProject, newProject);
            DialogResult dialogResult;

            using (confirmationDialog)
            {
                dialogResult = confirmationDialog.ShowDialog();
            }

            return dialogResult;
        }
        public void Cleanup(Project project)
        {
            string targetDirectory = string.Format("{0}{1}", project.ProjectDirectory, Constants.ProjectDirectoryBackupExtension);
            string targetFile = string.Format("{0}{1}", project.SolutionPath, Constants.SolutionBackupExtension);

            if (Directory.Exists(targetDirectory))
            {
                Directory.Delete(targetDirectory, true);
            }

            if (File.Exists(targetFile))
            {
                File.Delete(targetFile);
            }
        }
 private string GetProjectDirectory(Project project)
 {
     // Find exactly one directory within the solution directory, that has the old project name
     var directories = Directory.GetDirectories(solutionDirectoryPath, project.FolderName, SearchOption.TopDirectoryOnly).ToList();
     if(directories.Count != 1)
     {
         // There was no directory found in the solution directory, that contains the old project name.
         string message = string.Format(Constants.NoProjectDirectoryFoundError, context.OldProject.ProjectName);
         throw new ArgumentException(message);
     }
     return directories[0];
 }
 public void Cleanup(Project project)
 {
     // Note: An implementation is not needed here.
 }
        internal bool ValidateParameter(Project oldProject, Project newProject)
        {
            bool valid = true;

            try
            {
                Guard.IsNotNullOrEmpty(oldProject.ProjectName);
                Guard.IsNotNullOrEmpty(newProject.ProjectName);

                if(oldProject.ProjectName.Equals(newProject.ProjectName))
                {
                    valid = false;
                }
                // Note NKO: Add more validation here if needed.
            }
            catch(ArgumentException)
            {
                valid = false;
            }

            return valid;
        }
        private void RenameButtonClick(object sender, EventArgs e)
        {
            Project newProject = new Project { ProjectName = this.newProjectNameTextbox.Text };
            Project oldProject = (Project)oldProjectNamesCombobox.SelectedItem;

            bool isValid = controller.ValidateParameter(oldProject, newProject);

            if(isValid)
            {
                DialogResult dialogResult = ConfirmRename(oldProject, newProject);

                if(dialogResult.Equals(DialogResult.OK))
                {
                    // Disable the rename button to prevent a double click on it while renaming is in progress
                    renameButton.Enabled = false;
                    Cursor = Cursors.WaitCursor;
                    statusLabel.Text = LocalizationService.GetString(LocalizationResourceNames.MainFormStatusLabelRenamingProject);

                    try
                    {
                        bool commitChanges = checkInChangesCheckbox.Checked;
                        bool isUnderVersionControl = isUnderVersionControlCheckbox.Checked;
                        bool adjustFolderNameProjectNameMissmatch = adjustFolderNamesCheckBox.Checked;
                        bool renameMainEntryFile = renameMainEntryFileCheckBox.Checked;

                        controller.Rename(solution, oldProject, newProject, isUnderVersionControl, commitChanges ,adjustFolderNameProjectNameMissmatch, renameMainEntryFile, this);
                    }
                    catch(Exception exception)
                    {
                        controller.HandleError(exception.Message);
                    }
                }
            }
            else
            {
                string message = LocalizationService.GetString(LocalizationResourceNames.MainFormErrorMessageNewProjectNameEqualsOldProjectNameOrIsEmpty);
                controller.HandleError(message);
            }
        }
 private DialogResult ConfirmRename(Project oldProject, Project newProject)
 {
     return controller.ConfirmRename(oldProject, newProject);
 }
 public void CheckInChanges(string solutionDirectoryPath, Project oldProject, Project newProject)
 {
     // Note: An implementation is not needed here.
 }
        internal void Rename(string solution, Project oldProject, Project newProject, bool isUnderVersionControl, bool commitChanges, bool adjustFolderNameProjectNameMissmatch, bool renameMainEntryFile ,MainForm form = null)
        {
            RenameContext context = new RenameContext
                {
                    Solution = solution,
                    OldProject = oldProject,
                    NewProject = newProject,
                    IsUnderVersionControl = isUnderVersionControl,
                    CommitChanges = commitChanges,
                    AdjustFolderNameProjectNameMissmatch = adjustFolderNameProjectNameMissmatch,
                    RenameMainEntryFile = renameMainEntryFile
                };

            if(form != null)
            {
                renamerService.RenameFinished += form.RenameFinished;
            }

            Task.Factory.StartNew(() => renamerService.Rename(context), CancellationToken.None, TaskCreationOptions.None, MyStaTaskScheduler);
        }
        private void CreateBackup(Project oldProject)
        {
            // Copy the original directory and all its content before it is renamed.
            string sourceDirectory = oldProject.ProjectDirectory;
            string targetDirectory = string.Format("{0}{1}", oldProject.ProjectDirectory, Constants.ProjectDirectoryBackupExtension);
            copyService.CopyDirectory(sourceDirectory, targetDirectory);

            // Also make a copy of the original solution file.
            string sourceFile = oldProject.SolutionPath;
            string targetFile = string.Format("{0}{1}", oldProject.SolutionPath, Constants.SolutionBackupExtension);
            copyService.CopyFile(sourceFile, targetFile);
        }
 private void UpdateProjectReferences(Project project)
 {
     Replace(project.ProjectFile, context.OldProject.ProjectName, context.NewProject.ProjectName);
 }
        //Will only look through project code (.cs, .vb, .cshtml, .asax) to do replacements
        //Note: this used to go through using blocks (c++ code still does).  It was just missing a few occurences that I'd like to grab.
        private void ReplaceOccurencesInProjectCodeOnly(Project project)
        {
            string[] files;
            string searchFor;
            string replaceWith;

            if(this.context.OldProject.ProjectType.Equals(ProjectType.Cplusplus))
            {
                files = Directory.GetFiles(project.ProjectDirectory, "*", SearchOption.AllDirectories);

                searchFor = string.Format("{0} {1}{2}", "using namespace", context.OldProject.ProjectName, ";");
                replaceWith = string.Format("{0} {1}{2}", "using namespace", context.NewProject.ProjectName, ";");

                foreach (var file in files.Where(file => !file.EndsWith(".rc") && !file.EndsWith(".ico") && !file.EndsWith(".resX")))
                {
                    Replace(file, searchFor, replaceWith);
                }
            }

            //searchFor = string.Format("{0} {1}", Constants.Using, context.OldProject.ProjectName);
            //replaceWith = string.Format("{0} {1}", Constants.Using, context.NewProject.ProjectName);
            searchFor = string.Format("{0}", context.OldProject.ProjectName);
            replaceWith = string.Format("{0}", context.NewProject.ProjectName);

            files = Directory.GetFiles(project.ProjectDirectory, "*.*", SearchOption.AllDirectories)
                    .Where(file => file.ToLower().EndsWith(project.ClassfileExtension) || file.ToLower().EndsWith("cshtml") || file.ToLower().EndsWith("asax")).ToArray();

            foreach(var file in files)
            {
                Replace(file, searchFor, replaceWith);
            }
        }
        private void ReplaceOccurencesInNameSpacesForProject(Project project)
        {
            string[] files;
            string searchFor;
            string replaceWith;

            // Special treatment of C++ Projects.. // TODO NKO Refactor this
            if(context.OldProject.ProjectType.Equals(ProjectType.Cplusplus))
            {
                files = Directory.GetFiles(project.ProjectDirectory, "*", SearchOption.AllDirectories);

                searchFor = string.Format("{0} {1} {2}", "namespace", context.OldProject.ProjectName, "{");
                replaceWith = string.Format("{0} {1} {2}", "namespace", context.NewProject.ProjectName, "{");

                foreach(string file in files)
                {
                    // Skip these files..
                    if(!file.EndsWith(".rc") && !file.EndsWith(".ico") && !file.EndsWith(".resX"))
                    {
                        Replace(file, searchFor, replaceWith);
                    }
                }

                return;
            }

            // For every other project for now this is the way to go..
            files = Directory.GetFiles(project.ProjectDirectory,
                string.Format("*{0}", project.ClassfileExtension), SearchOption.AllDirectories);

            searchFor = string.Format("{0} {1}", Constants.Namespace, context.OldProject.ProjectName);
            replaceWith = string.Format("{0} {1}", Constants.Namespace, context.NewProject.ProjectName);

            foreach(string file in files)
            {
                Replace(file, searchFor, replaceWith);
            }
        }
        private void ReplaceOccurencesInGlobalDeclarations(Project project)
        {
            string[] files = Directory.GetFiles(project.ProjectDirectory, string.Format("*{0}", project.ClassfileExtension), SearchOption.AllDirectories);

            string searchFor = string.Format("{0}{1}", Constants.Global, context.OldProject.ProjectName);
            string replaceWith = string.Format("{0}{1}", Constants.Global, context.NewProject.ProjectName);

            foreach(string file in files)
            {
                Replace(file, searchFor, replaceWith);
            }
        }
 public DialogResult ConfirmRename(Project oldProject, Project newProject)
 {
     return confirmationDialogService.ShowConfirmationDialog(oldProject, newProject);
 }