Exemple #1
0
        public override void Create()
        {
            Uri uri = new Uri(_href, ".empty");
            EntityTagHeaderValue etag;

            using (HttpClient client = VfsUtils.NewHttpClient(uri, _fileSystem._creds))
            {
                var content = new StringContent(String.Empty);
                HttpResponseMessage response = client.PutAsync(uri.AbsolutePath, content).Result;
                if (response.StatusCode != HttpStatusCode.Created)
                {
                    response.EnsureSuccessful();
                }

                etag = response.Headers.ETag;
            }

            using (HttpClient client = VfsUtils.NewHttpClient(uri, _fileSystem._creds))
            {
                client.DefaultRequestHeaders.IfMatch.Add(EntityTagHeaderValue.Any);

                HttpResponseMessage response = client.DeleteAsync(uri.AbsolutePath).Result;
                if (response.StatusCode != HttpStatusCode.Created)
                {
                    response.EnsureSuccessful();
                }
            }
        }
Exemple #2
0
 public override void Delete()
 {
     using (HttpClient client = VfsUtils.NewHttpClient(_href, _fileSystem._creds))
     {
         client.DefaultRequestHeaders.IfMatch.Add(EntityTagHeaderValue.Any);
         client.DeleteAsync(_href.AbsolutePath).Result.EnsureSuccessful();
     }
 }
Exemple #3
0
        public VfsFileInfo(VfsFileSystem fileSystem, FileInfo info)
        {
            _fileSystem = fileSystem;
            _href       = VfsUtils.ToVfsUrl(fileSystem._uri, info);
            _fullName   = info.FullName;
            _name       = info.Name;
            _mime       = VfsUtils.GetMediaType(info.Extension).MediaType;
            _exists     = false;

            ((VfsFileInfoFactory)_fileSystem.FileInfo).UpdateCache(this);
        }
Exemple #4
0
        public VfsDirectoryInfo(VfsFileSystem fileSystem, DirectoryInfo info)
        {
            _fileSystem = fileSystem;
            _href       = VfsUtils.ToVfsUrl(_fileSystem._uri, info);
            _name       = info.Name;
            _fullName   = info.FullName;
            _mime       = VfsDirectory.Mime;
            _mtime      = DateTime.MinValue;

            ((VfsDirectoryInfoFactory)_fileSystem.DirectoryInfo).UpdateCache(this);
        }
Exemple #5
0
        public VfsDirectoryInfo(VfsFileSystem fileSystem, VfsJsonFileSystemInfo json)
        {
            _fileSystem = fileSystem;
            _href       = new Uri(json.Href);
            _name       = json.Name;
            _fullName   = VfsUtils.ToXDrive(_href);
            _mime       = json.Mime;
            _mtime      = DateTime.Parse(json.MTime).ToUniversalTime();
            _exists     = true;

            ((VfsDirectoryInfoFactory)_fileSystem.DirectoryInfo).UpdateCache(this);
        }
Exemple #6
0
        public override byte[] ReadAllBytes(string path)
        {
            Uri uri = VfsUtils.ToVfsUrl(_fileSystem._uri, new FileInfo(path));

            using (var client = VfsUtils.NewHttpClient(uri, _fileSystem._creds))
            {
                MemoryStream mem = new MemoryStream();
                using (Stream stream = client.GetStreamAsync(uri).Result)
                {
                    stream.CopyTo(mem);
                }
                return(mem.GetBuffer());
            }
        }
Exemple #7
0
        public override void WriteAllBytes(string path, byte[] bytes)
        {
            FileInfo info = new FileInfo(path);
            Uri      uri  = VfsUtils.ToVfsUrl(_fileSystem._uri, info);

            using (var client = VfsUtils.NewHttpClient(uri, _fileSystem._creds))
            {
                client.DefaultRequestHeaders.IfMatch.Add(EntityTagHeaderValue.Any);
                MemoryStream mem = new MemoryStream(bytes.Length);
                mem.Write(bytes, 0, bytes.Length);
                mem.Position = 0;
                StreamContent content = new StreamContent(mem);
                content.Headers.ContentType = VfsUtils.GetMediaType(info.Extension);
                using (HttpResponseMessage response = client.PutAsync(uri, content).Result.EnsureSuccessful())
                {
                    DateTime lastWriteTimeUtc = VfsUtils.GetLastWriteTimeUtc(response.Headers.ETag.Tag.Trim('\"'));
                    ((VfsFileInfoFactory)_fileSystem.FileInfo).UpdateLastWriteTimeUtc(info.FullName, lastWriteTimeUtc);
                }
            }
        }
Exemple #8
0
        private FileSystemInfoBase[] GetFileSystemInfosInternal()
        {
            if (_infos == null)
            {
                using (var client = VfsUtils.NewHttpClient(_href, _fileSystem._creds))
                {
                    using (HttpResponseMessage response = client.GetAsync(_href.AbsolutePath).Result)
                    {
                        if (response.StatusCode == HttpStatusCode.NotFound)
                        {
                            throw new DirectoryNotFoundException(this.FullName + " does not exists.");
                        }

                        response.EnsureSuccessful();

                        if (response.Content.Headers.ContentType.MediaType != "application/json")
                        {
                            throw new IOException("The directory name is invalid.");
                        }

                        var array = response.Content.ReadAsAsync <VfsJsonFileSystemInfo[]>().Result;
                        _infos = array.Select(json =>
                        {
                            FileSystemInfoBase info;
                            if (json.Mime == "inode/directory")
                            {
                                info = new VfsDirectoryInfo(_fileSystem, json);
                            }
                            else
                            {
                                info = new VfsFileInfo(_fileSystem, json);
                            }
                            return(info);
                        }).ToArray();
                    }
                }
            }

            return(_infos);
        }
Exemple #9
0
 public VfsDirectory(VfsFileSystem fileSystem)
 {
     _fileSystem = fileSystem;
     _currentDir = VfsUtils.ToXDrive(_fileSystem._uri);
 }