Beispiel #1
0
        public async Task <WebDAVFile> GET(WebDAVLocation location, string filename)
        {
            _logger.LogDebug($"Getting file at {location}/{filename}");
            var uri = getUrlForFilename(location.Value, filename);

            return(await GET(uri));
        }
Beispiel #2
0
        public async Task <bool> DELETE(WebDAVLocation location, string filename)
        {
            _logger.LogDebug("Deleting file at {Location}/{Filename}", location, filename);
            var uri    = getUrlForFilename(location.Value, filename);
            var result = await GetClient().DeleteAsync(uri);

            return(result.IsSuccessStatusCode);
        }
Beispiel #3
0
        public async Task <bool> PUT(WebDAVLocation location, string filename, byte[] contents)
        {
            _logger.LogDebug("Putting file {Location}/{Filename}", location, filename);
            var uri         = getUrlForFilename(location.Value, filename);
            var httpContent = new ByteArrayContent(contents);
            var result      = await GetClient().PutAsync(uri, httpContent);

            return(result.IsSuccessStatusCode);
        }
Beispiel #4
0
        public async Task <bool> UNZIP(WebDAVLocation location, string filename)
        {
            _logger.LogDebug("Unzipping file at {Location}/{Filename}", location, filename);
            var uri     = getUrlForFilename(location.Value, filename);
            var request = new HttpRequestMessage(HttpMethod.Post, uri)
            {
                Content = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("method", "UNZIP")
                })
            };
            var result = await GetClient().SendAsync(request);

            return(result.IsSuccessStatusCode);
        }
Beispiel #5
0
        public async Task <bool> PUT(WebDAVLocation location, string filename, Stream contents,
                                     TransferProgressReporter.ReportProgressHandler progressHandler = null)
        {
            _logger.LogDebug("Putting file {Location}/{Filename}", location, filename);
            var uri      = getUrlForFilename(location.Value, filename);
            var reporter = new TransferProgressReporter();

            if (progressHandler != null)
            {
                reporter.Handler += progressHandler;
            }

            var httpContent = new ProgressReportingHttpContent(contents, reporter);
            var result      = await GetClient().PutAsync(uri, httpContent).ConfigureAwait(false);

            return(result.IsSuccessStatusCode);
        }
Beispiel #6
0
        public async Task <bool> MakeDirectory(WebDAVLocation location, string directory)
        {
            _logger.LogDebug("Creating Directory {Location}/{Directory}", location, directory);
            var uri  = getUrlForFilename(location.Value, directory);
            var file = await GET(location, directory);

            if (file != null)
            {
                _logger.LogDebug($"Directory {location}/{directory} exists");
                return(true);
            }

            var request = new HttpRequestMessage
            {
                RequestUri = new Uri($"https://{_env.Server}{uri}"),
                Method     = new HttpMethod("MKCOL")
            };
            var result = await GetClient().SendAsync(request);

            return(result.IsSuccessStatusCode);
        }
Beispiel #7
0
        public async Task <IList <WebDAVFile> > ListDirectory(WebDAVLocation location, string directory)
        {
            _logger.LogDebug($"Listing Directory {location}/{directory}");
            var uri     = getUrlForFilename(location.Value, directory);
            var request = new HttpRequestMessage
            {
                RequestUri = new Uri($"https://{_env.Server}{uri}"),
                Method     = new HttpMethod("PROPFIND")
            };
            var result = await GetClient().SendAsync(request);

            result.EnsureSuccessStatusCode();
            var bodyStream = await result.Content.ReadAsStreamAsync();

            var collection = await XElement.LoadAsync(bodyStream, LoadOptions.None, CancellationToken.None);

            var responses = collection.Descendants(DAV + "response");
            var files     = responses.Select(FileFromXML);

            return(files.Skip(1).ToList());
        }
Beispiel #8
0
        public async Task <WebDAVFile> GETInfo(WebDAVLocation location, string path)
        {
            var filePath = getUrlForFilename(location.Value, path);

            return(await GETInfo(filePath));
        }
Beispiel #9
0
        public async Task <Stream> GETStream(WebDAVLocation location, string path)
        {
            var filePath = getUrlForFilename(location.Value, path);

            return(await GETStream(filePath));
        }