Пример #1
0
        public static string GetRelativeOrAbsolutePath(this VirtualFile file, VirtualDirectory directory)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            string result = file.GetRelativePath(directory);

            if (result.StartsWith("..", StringComparison.Ordinal))
            {
                return(file.FullName);
            }

            return(result);
        }
Пример #2
0
        public VirtualDirectory Directory(params string[] directoryParts)
        {
            if (!directoryParts.Any())
            {
                return(this);
            }

            string           directoryName = directoryParts[0];
            VirtualDirectory result        = Entries.OfType <VirtualDirectory>().FirstOrDefault(d => d.Name == directoryName);

            if (result == null)
            {
                result = contentResolver.Create <VirtualDirectory>(directoryName);
                AddEntry(result);
            }
            return(result.Directory(directoryParts.Skip(1).ToArray()));
        }
Пример #3
0
        public async Task CopyToAsync(VirtualDirectory destination)
        {
            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }

            foreach (VirtualFile file in Entries.OfType <VirtualFile>())
            {
                VirtualFile destinationFile = destination.File(file.Name);
                using (Stream destinationStream = destinationFile.OpenWrite())
                    using (Stream sourceStream = file.OpenRead())
                    {
                        await sourceStream.CopyToAsync(destinationStream).ConfigureAwait(false);
                    }
            }

            foreach (VirtualDirectory directory in Directories)
            {
                await directory.CopyToAsync(destination.Directory(directory.Name)).ConfigureAwait(false);
            }
        }
Пример #4
0
        public VirtualFile CopyTo(VirtualDirectory destinationDirectory)
        {
            if (destinationDirectory == null)
            {
                throw new ArgumentNullException(nameof(destinationDirectory));
            }

            if (destinationDirectory.FileExists(Name))
            {
                throw new FormattableIoException($"File {Name} already exists in {destinationDirectory.FullName}");
            }

            VirtualFile result = destinationDirectory.File(Name);

            using (Stream readStream = OpenRead())
                using (Stream writeStream = result.OpenWrite())
                {
                    readStream.CopyTo(writeStream);
                }

            return(result);
        }
Пример #5
0
 internal void SetParent(VirtualDirectory parent)
 {
     Parent = parent;
 }