/// <summary> /// Return the <see cref="ProjectFileName"/> instance of the project file <paramref name="relativePath"/>. /// Returns the default value if <paramref name="relativePath"/> is invalid or not part of a project. /// </summary> public static ProjectFileName CreateProjectFileNameFromRelativePath( this IFileSystemNameFactory fileSystemNameFactory, IProject project, string relativePath) { if (project == null) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(relativePath)) { return(default(ProjectFileName)); } var directoryName = fileSystemNameFactory.CreateAbsoluteDirectoryName(project.RootPath); var names = PathHelpers.SplitPath(relativePath).ToList(); foreach (var name in names) { if (name == names.Last()) { return(new ProjectFileName(project, fileSystemNameFactory.CreateFileName(directoryName, name))); } directoryName = fileSystemNameFactory.CreateDirectoryName(directoryName, name); } throw Invariants.Fail("Unreachable code"); }
/// <summary> /// Return the <see cref="FullPath"/> of the parent name. /// </summary> public FullPath GetAbsolutePath() { for (var current = this; current != null; current = current.Parent) { if (current.IsAbsoluteName) { return(current.FullPath); } } throw Invariants.Fail("Name does not have a parent with an absolute path."); }
private string LoadConfigFile(string name) { var localFileSystem = new FileSystem(); var path = new FullPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)) .Combine(new RelativePath(ConfigurationDirectoryNames.LocalInstallConfigurationDirectoryName)); var filePath = path.Combine(new RelativePath(name)); if (localFileSystem.FileExists(filePath)) { return(localFileSystem.ReadText(filePath)); } throw Invariants.Fail("File not found"); }
public static FullPath GetProjectPath(this NodeViewModel node) { Invariants.CheckArgumentNotNull(node, nameof(node)); for (; node != null; node = node.Parent) { if (node is RootNodeViewModel) { return(node.FullPath); } } throw Invariants.Fail("Unable to determine project path of node"); }