public void AccessByIndex()
        {
            var components = new [] { "a", "b", "c" };
            var path       = FsPath.Parse(string.Join("/", components));

            Assert.Equal(components.Length, path.Count);
            for (var i = 0; i < path.Count; ++i)
            {
                Assert.Equal(components[i], path.Strings[i]);
            }
        }
        public void Enumerate()
        {
            var components = new [] { "a", "b", "c" };
            var path       = FsPath.Parse(string.Join("/", components));
            var enumerable = (IEnumerable <StringSegment>)path;

            Assert.Equal(components.Select(s => new StringSegment(s)), path);
            var i = 0;

            using (var enumerator = enumerable.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Assert.Equal(new StringSegment(components[i]), enumerator.Current);
                    ++i;
                }
            }
        }
        public void Subpath()
        {
            var x  = FsPath.Parse("x/y/z");
            var x0 = FsPath.Empty;
            var x1 = FsPath.Parse("x");
            var x2 = FsPath.Parse("x/y");
            var x3 = FsPath.Parse("x/y/z");

            Assert.Equal(x0, x.SubPath(0));
            Assert.Equal(x1, x.SubPath(1));
            Assert.Equal(x2, x.SubPath(2));
            Assert.Equal(x3, x.SubPath(3));
            Assert.Throws <InvalidOperationException>(() => x.SubPath(4));
            Assert.Throws <InvalidOperationException>(() => x.SubPath(-4));
            Assert.Equal(x0, x.SubPath(-3));
            Assert.Equal(x1, x.SubPath(-2));
            Assert.Equal(x2, x.SubPath(-1));
        }
Beispiel #4
0
        protected internal override async Task <StoragePath> ResolvePathAsync(string absolutePath, CancellationToken cancellationToken)
        {
            var path      = absolutePath.Trim('/');
            var fsPath    = _linuxStorageRoot.RootPath + path;
            var localPath = FsPath.Parse(path);

            if (Directory.Exists(fsPath))
            {
                return(new StorageFolder(_linuxStorageRoot, localPath));
            }
            if (File.Exists(fsPath))
            {
                var mediaType = await _linuxStorageRoot.GetMediaTypeAsync(localPath, cancellationToken).ConfigureAwait(false);

                return(new StorageRecord(_linuxStorageRoot, localPath, mediaType));
            }
            return(new StoragePath(_linuxStorageRoot, localPath));
        }
 protected StorageItem(StorageRoot storageRoot, FsPath localPath)
     : base(storageRoot, localPath)
 {
     Security = storageRoot.GetSecurity(localPath);
 }
Beispiel #6
0
 public StorageRecord(StorageRoot storageRoot, FsPath localPath, string mediaType)
     : base(storageRoot, localPath)
 {
     _fileInfo = new FileInfo(storageRoot.GetFullPath(localPath));
     MediaType = mediaType;
 }
 public StorageFolder(StorageRoot storageRoot, FsPath localPath) : base(storageRoot, localPath)
 {
 }
Beispiel #8
0
 public StoragePath(StorageRoot storageRoot, FsPath localPath)
 {
     StorageRoot = storageRoot ?? throw new ArgumentNullException(nameof(storageRoot));
     LocalPath   = localPath ?? throw new ArgumentNullException(nameof(localPath));
 }
Beispiel #9
0
        protected override IEnumerable <string> GetFileSystemEntries(FsPath localPath)
        {
            string path = null == localPath ? RootPath : GetFullPath(localPath);

            return(Directory.EnumerateFileSystemEntries(path));
        }
Beispiel #10
0
 public override string GetFullPath(FsPath localPath) => RootPath + localPath.Join("/");
Beispiel #11
0
 public override string GetUriPath(FsPath localPath) => RootPath.TrimStart('/') + localPath.Join("/");
 public StringIndexer(FsPath path) => _path = path;
 internal Enumerator(FsPath path)
 {
     _path = path;
     Reset();
 }
        public void AddToNull()
        {
            FsPath nullPath = null;

            Assert.Throws <ArgumentNullException>(() => nullPath + "xxx");
        }