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(); } } }
public override void Delete() { using (HttpClient client = VfsUtils.NewHttpClient(_href, _fileSystem._creds)) { client.DefaultRequestHeaders.IfMatch.Add(EntityTagHeaderValue.Any); client.DeleteAsync(_href.AbsolutePath).Result.EnsureSuccessful(); } }
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()); } }
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); } } }
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); }