コード例 #1
0
 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)));
 }
コード例 #2
0
        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));
        }
コード例 #3
0
        public void EnsureDirectoryExists(RelativeDirectoryPath path)
        {
            var fullyQualifiedPath = GetFullyQualifiedPath(path);

            if (!Directory.Exists(fullyQualifiedPath.FullName))
            {
                Directory.CreateDirectory(fullyQualifiedPath.FullName);
            }
        }
コード例 #4
0
        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"));
        }
コード例 #5
0
        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();
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        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));
        }
コード例 #8
0
        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));
        }
コード例 #9
0
ファイル: ZipHelper.cs プロジェクト: yongaru/fuse-studio
        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();
            }
        }
コード例 #10
0
        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));
        }
コード例 #11
0
        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;
                }
            }
        }
コード例 #12
0
ファイル: MarkdownProject.cs プロジェクト: xwf20050250/try
 public bool DirectoryExists(RelativeDirectoryPath path)
 {
     return(false);
 }
コード例 #13
0
        public void Normalises_the_passed_path()
        {
            var path = new RelativeDirectoryPath(@"..\src");

            path.Value.Should().Be("../src/");
        }
コード例 #14
0
        public void Can_create_directory_paths_from_string_with_directory()
        {
            var path = new RelativeDirectoryPath("../src");

            path.Value.Should().Be("../src/");
        }
コード例 #15
0
        public IDirectoryAccessor GetDirectoryAccessorForRelativePath(RelativeDirectoryPath relativePath)
        {
            var absolutePath = _rootDirectory.Combine(relativePath).FullName;

            return(new FileSystemDirectoryAccessor(new DirectoryInfo(absolutePath)));
        }
コード例 #16
0
 public bool DirectoryExists(RelativeDirectoryPath path)
 {
     return(GetFullyQualifiedPath(path).Exists);
 }
コード例 #17
0
ファイル: RelativeTo.cs プロジェクト: yongaru/fuse-studio
 static RelativeDirectoryPath ToLeaf(this RelativeDirectoryPath self, AbsoluteDirectoryPath ancestor, AbsoluteDirectoryPath leaf)
 {
     return(leaf == ancestor ? self : new RelativeDirectoryPath(leaf.Name, self.ToLeaf(ancestor, leaf.ContainingDirectory)));
 }
コード例 #18
0
 ///<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;
 }
コード例 #19
0
ファイル: Rename.cs プロジェクト: yongaru/fuse-studio
 public static RelativeDirectoryPath Rename(this RelativeDirectoryPath path, DirectoryName newName)
 {
     return(new RelativeDirectoryPath(newName, path.BasePath));
 }
コード例 #20
0
 static RelativeDirectoryPath GetContainingDirectory(this RelativeDirectoryPath path)
 {
     return(path.BasePath);
 }
コード例 #21
0
 public static RelativeFilePath Combine(this RelativeDirectoryPath basePath, RelativeFilePath path)
 {
     return(basePath.Combine(path.BasePath).Combine(path.Name));
 }
コード例 #22
0
ファイル: MarkdownProject.cs プロジェクト: xwf20050250/try
 public IDirectoryAccessor GetDirectoryAccessorForRelativePath(RelativeDirectoryPath relativePath)
 {
     return(this);
 }
コード例 #23
0
 public static RelativeDirectoryPath Combine(this RelativeDirectoryPath basePath, RelativeDirectoryPath relativePath)
 {
     return(relativePath == null ? basePath : basePath.Combine(relativePath.BasePath).Combine(relativePath.Name));
 }
コード例 #24
0
 static bool HasContainingDirectory(this RelativeDirectoryPath path)
 {
     return(path != null && !path.Name.IsParentDirectory);
 }
コード例 #25
0
ファイル: MarkdownProject.cs プロジェクト: xwf20050250/try
 public void EnsureDirectoryExists(RelativeDirectoryPath path)
 {
 }
コード例 #26
0
 public static RelativeFilePath Combine(this RelativeDirectoryPath basePath, FileName fileName)
 {
     return(new RelativeFilePath(fileName, basePath));
 }
コード例 #27
0
		/// <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;
		}