public static IRelativePath Combine(this RelativeDirectoryPath basePath, IRelativePath path) { return(path == null ? basePath : path.MatchWith( (RelativeFilePath file) => (IRelativePath)basePath.Combine(file), (RelativeDirectoryPath dir) => (IRelativePath)basePath.Combine(dir))); }
static OutputDirWithLock TestOutputDirGen(RelativeDirectoryPath basePath) { var shell = new Shell(); var generator = new OutputDirGenerator(shell); var baseP = Assembly.GetExecutingAssembly().GetCodeBaseFilePath().ContainingDirectory / basePath; return(generator.CreateOrReuseOutputDir(baseP)); }
public void EnsureDirectoryExists(RelativeDirectoryPath path) { var fullyQualifiedPath = GetFullyQualifiedPath(path); if (!Directory.Exists(fullyQualifiedPath.FullName)) { Directory.CreateDirectory(fullyQualifiedPath.FullName); } }
static AbsoluteFilePath FindMonoExe(AbsoluteDirectoryPath fuseRoot) { var monoRoot = File.ReadAllText((fuseRoot / new FileName(".mono_root")).NativePath); var monoPath = RelativeDirectoryPath.TryParse(monoRoot) .Select(monoRelative => fuseRoot / monoRelative) .Or(AbsoluteDirectoryPath.TryParse(monoRoot)) .OrThrow(new InvalidPath(monoRoot, new Exception("Invalid mono root path."))); return(monoPath / new DirectoryName("bin") / new FileName("mono")); }
public void Equality_is_based_on_same_resolved_directory_path( string value1, string value2) { var path1 = new RelativeDirectoryPath(value1); var path2 = new RelativeDirectoryPath(value2); path1.GetHashCode().Should().Be(path2.GetHashCode()); path1.Equals(path2).Should().BeTrue(); path2.Equals(path1).Should().BeTrue(); }
public void TestDirInUse() { var name0 = "TestDirInUse"; var name1 = "TestDirInUse1"; var result0 = TestOutputDirGen(RelativeDirectoryPath.Parse(name0)); var result1 = TestOutputDirGen(RelativeDirectoryPath.Parse(name0)); // Expects the base path to Assert.True(result0.OutputDir.Name == new DirectoryName(name0)); Assert.True(result1.OutputDir.Name == new DirectoryName(name1)); }
public void TestDirReuse() { var name0 = "TestDirReuse"; var result0 = TestOutputDirGen(RelativeDirectoryPath.Parse(name0)); result0.LockFile.Dispose(); var result1 = TestOutputDirGen(RelativeDirectoryPath.Parse(name0)); // Expects the base path to Assert.True(result0.OutputDir.Name == new DirectoryName(name0)); Assert.True(result1.OutputDir.Name == new DirectoryName(name0)); }
public static RelativeDirectoryPath Combine(this RelativeDirectoryPath basePath, DirectoryName directoryName) { if (directoryName.IsCurrentDirectory) { return(basePath); } if (directoryName.IsParentDirectory && basePath.HasContainingDirectory()) { return(basePath.GetContainingDirectory()); } return(new RelativeDirectoryPath(directoryName, basePath)); }
static void ExtractZipTo(CancellationToken ct, Stream stream, AbsoluteDirectoryPath outFolder, IProgress <InstallerEvent> progress) { progress.Report(new InstallerStep("Extracting")); var zipIn = new ZipInputStream(stream); var zipEntry = zipIn.GetNextEntry(); if (zipEntry.IsDirectory) { zipEntry = zipIn.GetNextEntry(); } while (zipEntry != null) { ct.ThrowIfCancellationRequested(); var entryFileName = zipEntry.Name; var parts = zipEntry.IsDirectory ? RelativeDirectoryPath.Parse(entryFileName.Substring(0, entryFileName.Length - 1)).Parts : RelativeFilePath.Parse(entryFileName).Parts; var newPathStr = ""; var partsArray = parts.ToArray(); for (var i = 1; i < partsArray.Length; ++i) { newPathStr += partsArray[i] + (i + 1 == partsArray.Length ? "" : Path.DirectorySeparatorChar.ToString()); } var buffer = new byte[4096]; var fullZipToPath = Path.Combine(outFolder.NativePath, newPathStr); var directoryName = zipEntry.IsFile ? Path.GetDirectoryName(fullZipToPath) : fullZipToPath; if (directoryName.Length > 0) { Directory.CreateDirectory(directoryName); } if (zipEntry.IsFile) { progress.Report(new InstallerMessage("Extracting: " + newPathStr)); using (var streamWriter = File.Create(fullZipToPath)) { StreamUtils.Copy(zipIn, streamWriter, buffer); } } zipEntry = zipIn.GetNextEntry(); } }
public static Optional <NamespaceName> ToNamespace(this RelativeDirectoryPath directoryPath, Optional <NamespaceName> rootNamespace) { if (directoryPath == null) { return(rootNamespace); } var relativeNamespace = new NamespaceName( directoryPath.Parts .Select(p => p.ToString() .Replace(".", "_") .Replace(" ", "_")).Join(".")); return(rootNamespace.MatchWith( some: root => new NamespaceName(root.FullName + (root.FullName == "" ? "" : ".") + relativeNamespace.FullName), none: () => relativeNamespace)); }
public void TestDirInUseSimultaneously() { var name = "TestDirInUseSim"; var listOfPossibilities = new List <DirectoryName> { new DirectoryName("TestDirInUseSim"), new DirectoryName("TestDirInUseSim1"), new DirectoryName("TestDirInUseSim2"), new DirectoryName("TestDirInUseSim3"), new DirectoryName("TestDirInUseSim4") }; var result0 = Task.Run(() => TestOutputDirGen(RelativeDirectoryPath.Parse(name))); var result1 = Task.Run(() => TestOutputDirGen(RelativeDirectoryPath.Parse(name))); var result2 = Task.Run(() => TestOutputDirGen(RelativeDirectoryPath.Parse(name))); var result3 = Task.Run(() => TestOutputDirGen(RelativeDirectoryPath.Parse(name))); var result4 = Task.Run(() => TestOutputDirGen(RelativeDirectoryPath.Parse(name))); // Expects the base path to Assert.True(listOfPossibilities.Remove(result0.Result.OutputDir.Name)); Assert.True(listOfPossibilities.Remove(result1.Result.OutputDir.Name)); Assert.True(listOfPossibilities.Remove(result2.Result.OutputDir.Name)); Assert.True(listOfPossibilities.Remove(result3.Result.OutputDir.Name)); Assert.True(listOfPossibilities.Remove(result4.Result.OutputDir.Name)); foreach (var r in new[] { result0, result1, result2, result3, result4 }) { try { r.Result.LockFile.Dispose(); } catch (Exception e) { Console.WriteLine("Got error while trying to dispose lock in {0}: {1}", r.Result.OutputDir, e); throw; } } }
public bool DirectoryExists(RelativeDirectoryPath path) { return(false); }
public void Normalises_the_passed_path() { var path = new RelativeDirectoryPath(@"..\src"); path.Value.Should().Be("../src/"); }
public void Can_create_directory_paths_from_string_with_directory() { var path = new RelativeDirectoryPath("../src"); path.Value.Should().Be("../src/"); }
public IDirectoryAccessor GetDirectoryAccessorForRelativePath(RelativeDirectoryPath relativePath) { var absolutePath = _rootDirectory.Combine(relativePath).FullName; return(new FileSystemDirectoryAccessor(new DirectoryInfo(absolutePath))); }
public bool DirectoryExists(RelativeDirectoryPath path) { return(GetFullyQualifiedPath(path).Exists); }
static RelativeDirectoryPath ToLeaf(this RelativeDirectoryPath self, AbsoluteDirectoryPath ancestor, AbsoluteDirectoryPath leaf) { return(leaf == ancestor ? self : new RelativeDirectoryPath(leaf.Name, self.ToLeaf(ancestor, leaf.ContainingDirectory))); }
///<summary> ///Try get a new <see cref="IAbsoluteDirectoryPath"/> object from this string. ///</summary> ///<returns><i>true</i> if <paramref name="pathString"/> is a valid relative directory path and as a consequence, the returned <paramref name="relativeDirectoryPath"/> is not null.</returns> ///<remarks>The path represented by this string doesn't need to exist for this operation to complete properly.</remarks> ///<param name="pathString">Represents the path.</param> ///<param name="relativeDirectoryPath">If this method returns <i>true</i>, this is the returned path object.</param> ///<param name="failureReason">If this method returns <i>false</i>, this is the plain english description of the failure.</param> public static bool TryGetRelativeDirectoryPath(this string pathString, out IRelativeDirectoryPath relativeDirectoryPath, out string failureReason) { relativeDirectoryPath = null; if (pathString.IsPathStringNullOrEmpty(out failureReason)) { return false; } if (!pathString.IsValidRelativeDirectoryPath(out failureReason)) { return false; } relativeDirectoryPath = new RelativeDirectoryPath(pathString); return true; }
public static RelativeDirectoryPath Rename(this RelativeDirectoryPath path, DirectoryName newName) { return(new RelativeDirectoryPath(newName, path.BasePath)); }
static RelativeDirectoryPath GetContainingDirectory(this RelativeDirectoryPath path) { return(path.BasePath); }
public static RelativeFilePath Combine(this RelativeDirectoryPath basePath, RelativeFilePath path) { return(basePath.Combine(path.BasePath).Combine(path.Name)); }
public IDirectoryAccessor GetDirectoryAccessorForRelativePath(RelativeDirectoryPath relativePath) { return(this); }
public static RelativeDirectoryPath Combine(this RelativeDirectoryPath basePath, RelativeDirectoryPath relativePath) { return(relativePath == null ? basePath : basePath.Combine(relativePath.BasePath).Combine(relativePath.Name)); }
static bool HasContainingDirectory(this RelativeDirectoryPath path) { return(path != null && !path.Name.IsParentDirectory); }
public void EnsureDirectoryExists(RelativeDirectoryPath path) { }
public static RelativeFilePath Combine(this RelativeDirectoryPath basePath, FileName fileName) { return(new RelativeFilePath(fileName, basePath)); }
/// <summary> /// Try get a new <see cref="IAbsoluteDirectoryPath" /> object from this string. /// </summary> /// <returns> /// <i>true</i> if <paramref name="path" /> is a valid relative directory path and as a consequence, the returned /// <paramref name="relativePath" /> is not null. /// </returns> /// <remarks>The path represented by this string doesn't need to exist for this operation to complete properly.</remarks> /// <param name="path">Represents the path.</param> /// <param name="relativePath">If this method returns <i>true</i>, this is the returned path object.</param> /// <param name="failureMessage">If this method returns <i>false</i>, this is the plain english description of the failure.</param> public static bool TryGetRelativeDirectoryPath(this string path, out IRelativeDirectoryPath relativePath, out string failureMessage) { relativePath = null; if (IsNullOrEmpty(() => path, out failureMessage)) { return false; } if (!path.IsValidRelativeDirectoryPath(out failureMessage)) { return false; } relativePath = new RelativeDirectoryPath(path); return true; }