private static bool TryGetOrCreateProjectFolder( RelativePath relativeFilePath, IProject project, IProjectModelTransactionCookie transaction, out IProjectFolder projectFolder) { RelativePath subFolderRelativePath = SolutionFilePathHelpers.GetProjectSubFolderRelativePath(relativeFilePath, project); if (!SolutionFilePathHelpers.TryGetProjectFolder(subFolderRelativePath, project, out projectFolder)) { string message = $"There is not folder '{subFolderRelativePath}' in project '{project.Name}'.{Environment.NewLine}" + "Do you want to create it?"; if (!MessageBox.ShowYesNo(message)) { return(false); } FileSystemPath fileSystemPath = subFolderRelativePath.MakeAbsoluteBasedOn(project.Location); projectFolder = project.GetOrCreateProjectFolder(fileSystemPath, transaction); } return(true); }
public static bool TryCreateFile( string filePath, ISolution solution, IProjectFile sourceFile, IProjectModelTransactionCookie transaction, out IProjectFile file) { file = null; string failReason; if (!SolutionFilePathHelpers.TryParseFilePath(filePath, out RelativePath relativeFilePath, out failReason)) { MessageBox.ShowError(failReason); return(false); } if (!SolutionFilePathHelpers.TryGetProject(solution, relativeFilePath, out IProject project, out failReason)) { MessageBox.ShowError(failReason); return(false); } if (!TryGetOrCreateProjectFolder(relativeFilePath, project, transaction, out IProjectFolder projectFolder)) { return(false); } return(TryEnsureFileExists(relativeFilePath, projectFolder, sourceFile, transaction, out file)); }
private static bool TryProcessFilePaths( ISolution solution, List <FileGeneratorOutput> fileGeneratorOutputs, out List <FileGeneratorOutput> notFoundProjectFolderOutputs) { var stopExecutionReasons = new HashSet <string>(); notFoundProjectFolderOutputs = new List <FileGeneratorOutput>(); foreach (FileGeneratorOutput output in fileGeneratorOutputs) { string failReason; if (!SolutionFilePathHelpers.TryParseFilePath(output.FilePath, out RelativePath relativeFilePath, out failReason)) { stopExecutionReasons.Add(failReason); continue; } output.FileName = relativeFilePath.Name; if (!SolutionFilePathHelpers.TryGetProject(solution, relativeFilePath, out IProject project, out failReason)) { stopExecutionReasons.Add(failReason); continue; } output.Project = project; if (stopExecutionReasons.Count > 0) { continue; } output.SubFolderRelativePath = SolutionFilePathHelpers.GetProjectSubFolderRelativePath(relativeFilePath, project); if (SolutionFilePathHelpers.TryGetProjectFolder(output.SubFolderRelativePath, project, out IProjectFolder projectFolder)) { output.ProjectFolder = projectFolder; } else { notFoundProjectFolderOutputs.Add(output); } } if (stopExecutionReasons.Count > 0) { MessageBox.ShowError(string.Join(Environment.NewLine, stopExecutionReasons)); return(false); } return(true); }