/// <summary> /// Given the absolute full path of a file this returns true if the file can be added to the project /// The follwing cases prevent the file from being added to the project /// 1- The project file does not exist yet /// 2- File is not inside the project folder or one of its sub-folders /// 3- The relative file path is empty /// 4- The file already exists in the project /// 5- The file extension is not accepted /// </summary> /// <param name="filePath">The absolute full path of the file</param> /// <returns></returns> public virtual bool CanAddSourceFile(string filePath) { //The project file does not exist yet! The file can't be added if (ProjectFileExists == false) { return(false); } var parentFolder = ProjectFolderPath.ToLower(); var childPath = filePath.ToLower(); //File is not inside the project folder or one of its sub-folders. The file can't be added if (childPath.Substring(0, parentFolder.Length) != parentFolder) { return(false); } var relativeChildPath = childPath.Substring(parentFolder.Length); //The relative file path is empty! The file can't be added if (string.IsNullOrEmpty(relativeChildPath)) { return(false); } //The file already exists in the project. The file can't be added if (SourceCodeFiles.Exists(file => file.FileRelativePath.ToLower() == relativeChildPath)) { return(false); } var allowedExtensions = AllowedSourceFilesExtensions.Select(e => "." + e.ToLower()).ToList(); var childExtinsion = Path.GetExtension(childPath); //If the file extension is not accepted. The file can't be added return(allowedExtensions.Contains(childExtinsion)); }
IProjectFolder IProjectFolder.GetSubFolderByPath(ProjectFolderPath projectFolderPath) => null;