/// <summary> /// Create a new instance of a ProjectFile object. /// </summary> /// <param name="fileName"></param> /// <param name="projectType"></param> public ProjectFile(string fileName, DataManager.ProjectTypeEnum projectType) { // set the FileName this.FullFilePath = fileName; // Set the project type this.ProjectType = projectType; }
/// <summary> /// This method updates the files for a project that are of the /// same project type. /// </summary> /// <param name="project"></param> /// <param name="files"></param> /// <param name="projectTypeEnum"></param> /// <returns></returns> private static int UpdateProject(EnvDTE.Project project, List <ProjectFile> files, DataManager.ProjectTypeEnum projectType) { // initial value int newFilesAddedCount = 0; // locals bool abort = false; try { // verify all objects exist if ((project != null) && (project.ProjectItems != null) && (files != null) && (files.Count > 0)) { // iterate collection of ProjectFiles foreach (ProjectFile projectFile in files) { // reset abort = false; // if this file should go in this project if (projectFile.ProjectType == projectType) { try { // check if the file already exists abort = CheckIfFileExistsInProject(project.ProjectItems, projectFile); // if we should continue if (!abort) { // add this file project.ProjectItems.AddFromFile(projectFile.FullFilePath); // increment newFilesAddedCount newFilesAddedCount++; } } catch (Exception error) { // for debugging only (for now) string err = error.ToString(); } } } } } catch (Exception error) { // for debugging only (for now) string err = error.ToString(); } // return value return(newFilesAddedCount); }
/// <summary> /// This method updates the files for a project that are of the /// same project type. /// </summary> /// <param name="project"></param> /// <param name="files"></param> /// <param name="projectTypeEnum"></param> /// <returns></returns> private static int RemoveFilesFromProject(EnvDTE.Project project, List <ProjectFile> files, DataManager.ProjectTypeEnum projectType) { // initial value int filesRemoved = 0; // locals bool fileRemoved = false; try { // verify all objects exist if ((project != null) && (project.ProjectItems != null) && (files != null) && (files.Count > 0)) { // iterate collection of ProjectFiles foreach (ProjectFile projectFile in files) { // reset fileRemoved = false; // if this file should go in this project if (projectFile.ProjectType == projectType) { try { // check if the file already exists fileRemoved = RemoveFileIfFileExistsInProject(project, project.ProjectItems, projectFile); // if the file was removed if (fileRemoved) { // Increment the value for filesRemoved filesRemoved++; } } catch (Exception error) { // for debugging only (for now) string err = error.ToString(); } } } } } catch (Exception error) { // for debugging only (for now) string err = error.ToString(); } // return value return(filesRemoved); }