Esempio n. 1
0
        /// <summary>
        /// Rename project
        /// </summary>
        /// <param name="projectConfig">Project configuration</param>
        /// <param name="newName">New project name</param>
        static public void RenameProject(ProjectConfiguration projectConfig, string newName, ProjectCatalog catalog)
        {
            // check if project name is empty
            if (newName.Length == 0)
            {
                throw new NotSupportedException(Properties.Resources.ProjectNameCannotBeEmpty);
            }

            // check that project name is correct
            if (!FileHelpers.IsFileNameCorrect(newName))
            {
                throw new NotSupportedException(Properties.Resources.ProjectNameIsNotCorrect);
            }

            // check if project with such name already exists
            bool nameExisted = false;

            foreach (ProjectConfiguration cfg in catalog.Projects)
            {
                if (newName.Equals(cfg.Name, StringComparison.OrdinalIgnoreCase))
                {
                    nameExisted = true;
                }
            }
            if (nameExisted)
            {
                throw new NotSupportedException(Properties.Resources.ProjectNameIsAlreadyExists);
            }

            // todo: check that you have write rename/delete access to the files
            string newProjectPath = Path.Combine(projectConfig.FolderPath, newName);
            //if (!FileHelpers.CheckWriteAccess(newProjectPath))
            //    throw new NotSupportedException(Properties.Resources.WriteAccessDenied);

            string oldDatabasePath = projectConfig.DatabasePath;
            string newDBFileName   = ProjectConfiguration.GetDatabaseFileName(newName);
            string oldDBFileName   = Path.GetFileName(oldDatabasePath);
            int    indexStart      = oldDatabasePath.Length - oldDBFileName.Length;
            string newDBFilePath   = oldDatabasePath.Remove(indexStart);

            newDBFilePath = newDBFilePath + newDBFileName;

            string newDBAbsolutePath = ProjectConfiguration.GetDatabaseAbsolutPath(projectConfig.FolderPath, newDBFilePath);

            File.Move(oldDatabasePath, newDBAbsolutePath);

            string oldProjectFilePath = projectConfig.FilePath;

            projectConfig.Name         = newName;
            projectConfig.DatabasePath = newDBFilePath;
            projectConfig.Save(projectConfig.FilePath);
            File.Delete(oldProjectFilePath);
        }
        /// <summary>
        /// Rename project
        /// </summary>
        /// <param name="projectConfig">Project configuration</param>
        /// <param name="newName">New project name</param>
        public static void RenameProject(ProjectConfiguration projectConfig, string newName, ProjectCatalog catalog)
        {
            // check if project name is empty
            if (newName.Length == 0)
                throw new NotSupportedException(Properties.Resources.ProjectNameCannotBeEmpty);

            // check that project name is correct
            if (!FileHelpers.IsFileNameCorrect(newName))
                throw new NotSupportedException(Properties.Resources.ProjectNameIsNotCorrect);

            // check if project with such name already exists
            bool nameExisted = false;
            foreach (ProjectConfiguration cfg in catalog.Projects)
            {
                if (newName.Equals(cfg.Name, StringComparison.OrdinalIgnoreCase))
                {
                    nameExisted = true;
                }
            }
            if (nameExisted)
                throw new NotSupportedException(Properties.Resources.ProjectNameIsAlreadyExists);

            // todo: check that you have write rename/delete access to the files
            string newProjectPath = Path.Combine(projectConfig.FolderPath, newName);
            //if (!FileHelpers.CheckWriteAccess(newProjectPath))
            //    throw new NotSupportedException(Properties.Resources.WriteAccessDenied);

            string oldDatabasePath = projectConfig.DatabasePath;
            string newDBFileName = ProjectConfiguration.GetDatabaseFileName(newName);
            string oldDBFileName = Path.GetFileName(oldDatabasePath);
            int indexStart = oldDatabasePath.Length - oldDBFileName.Length;
            string newDBFilePath = oldDatabasePath.Remove(indexStart);
            newDBFilePath = newDBFilePath + newDBFileName;

            string newDBAbsolutePath = ProjectConfiguration.GetDatabaseAbsolutPath(projectConfig.FolderPath, newDBFilePath);
            File.Move(oldDatabasePath, newDBAbsolutePath);

            string oldProjectFilePath = projectConfig.FilePath;
            projectConfig.Name = newName;
            projectConfig.DatabasePath = newDBFilePath;
            projectConfig.Save(projectConfig.FilePath);
            File.Delete(oldProjectFilePath);
        }