Exemplo n.º 1
0
 /// <summary>
 /// Create a clone of the given project with the given name.
 /// </summary>
 /// <param name="toClone">The project to clone</param>
 /// <param name="name">The name to give the clone</param>
 /// <param name="error">A description of the error</param>
 /// <returns>True if the clone succeeded,</returns>
 public bool CloneProject(Project toClone, string name, ref string error)
 {
     if (!Project.ValidateProjectName(name))
     {
         error = "The project name was invalid!";
         return(false);
     }
     lock (EditingSessionLock)
     {
         var repository = Runtime.Configuration.ProjectRepository;
         // Make sure the name is unique
         if ((from project in Runtime.Configuration.ProjectRepository.Projects
              where project.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)
              select project as Project).Any())
         {
             error = "A project with that name already existed!";
             return(false);
         }
         var clonedProject = toClone.CreateCloneProject(false);
         clonedProject.Name = name;
         // if we are able to save, add it to the project repository
         if (clonedProject.Save(ref error))
         {
             repository.AddProject(clonedProject);
             return(true);
         }
         return(false);
     }
 }
Exemplo n.º 2
0
 public bool RenameProject(IProject project, string newName, ref string error)
 {
     if (project == null)
     {
         throw new ArgumentNullException(nameof(project));
     }
     // make sure that the new project name is valid
     lock (this)
     {
         if (!Project.ValidateProjectName(newName))
         {
             error = $"The project name {newName} was invalid!";
             return(false);
         }
         if (Projects.Any(p => p.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase)))
         {
             error = $"The project name {newName} already exists!";
             return(false);
         }
         var oldName = project.Name;
         try
         {
             Directory.Move(Path.Combine(Configuration.ProjectDirectory, oldName),
                            Path.Combine(Configuration.ProjectDirectory, newName));
         }
         catch (IOException e)
         {
             error = e.Message;
             return(false);
         }
         project.Name = newName;
     }
     return(true);
 }
Exemplo n.º 3
0
        public bool RenameProject(IProject project, string newName)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            // make sure that the new project name is valid
            lock (this)
            {
                if (!Project.ValidateProjectName(newName) || this.Projects.Any((p) => (p.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase))))
                {
                    return(false);
                }

                var oldName = project.Name;
                try
                {
                    Directory.Move(Path.Combine(this.Configuration.ProjectDirectory, oldName),
                                   Path.Combine(this.Configuration.ProjectDirectory, newName));
                }
                catch
                {
                    return(false);
                }
                project.Name = newName;
            }
            return(true);
        }
Exemplo n.º 4
0
 public bool ValidateProjectName(string name)
 {
     if (!Project.ValidateProjectName(name))
     {
         return(false);
     }
     foreach (var project in Projects)
     {
         if (project.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase))
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 5
0
        private bool ValidateProjectName(IProject project)
        {
            var projects = Projects;

            // make sure there are no projects with the same name
            for (var i = 0; i < projects.Count; i++)
            {
                // we need to ignore case because of the Windows directory code since
                // they do not distinguish between case due to FAT32's structure
                if (projects[i].Name.Equals(project.Name, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(false);
                }
            }
            // Make sure that there are no invalid characters for a project name
            return(Project.ValidateProjectName(project.Name));
        }
Exemplo n.º 6
0
 /// <summary>
 /// Makes a copy of the model system with the given new name
 /// </summary>
 /// <param name="modelSystem">The model system to create a clone of</param>
 /// <param name="newName">The name to give the model system</param>
 /// <param name="error">An error message if the operation fails</param>
 /// <returns>True if successful, false otherwise with an error message.</returns>
 public bool CloneModelSystem(ModelSystem modelSystem, string newName, ref string error)
 {
     if (!Project.ValidateProjectName(newName))
     {
         error = "The new name contained characters that are not valid!";
         return(false);
     }
     lock (RepositoryLock)
     {
         lock (EditingLock)
         {
             // as long as it isn't being edited
             if (EditingSessions.Any((session) => session.IsEditing(modelSystem as ModelSystem)))
             {
                 // we can't delete a model system that is currently being edited
                 error = "A model system can not be cloned while being edited!";
                 return(false);
             }
             return(Repository.CloneModelSystem(modelSystem, newName, ref error));
         }
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Validate a name to make sure it is a valid possible model system
 /// </summary>
 /// <param name="name">The potential name of the model system to check</param>
 /// <returns>True if the name is alright</returns>
 private static bool ValidateName(string name)
 {
     return(Project.ValidateProjectName(name));
 }
Exemplo n.º 8
0
 public bool ValidateProjectName(string name)
 {
     return(Project.ValidateProjectName(name));
 }
Exemplo n.º 9
0
 internal bool ValidateProjectName(string name)
 {
     return(Project.ValidateProjectName(name));
 }