static async Task <bool> CheckIfFileIsUploaded(string baseAddress, string filePath) { var requestUri = baseAddress + filePath.Replace("\\", "/"); var result = await _client.Propfind(requestUri); return(result.IsSuccessful); }
public async Task <(Stream, string)> GetFile(string path) { string fullPath = GetFullPath(path); var result = await Client.Propfind(fullPath); if (result.IsSuccessful) { var file = result.Resources.FirstOrDefault(); if (file == null) { throw new FileNotFoundException($"Path: {fullPath}"); } using (var stream = await Client.GetRawFile(file.Uri)) { byte[] buffer = new byte[32768]; var ms = new MemoryStream(); int readedBytes = 0; while ((readedBytes = await stream.Stream.ReadAsync(buffer, 0, buffer.Length)) > 0) { await ms.WriteAsync(buffer, 0, readedBytes); } return(ms, file.DisplayName); } } else { throw new FileNotFoundException($"Path: {fullPath}"); } }
public async void TryConnect() { try { await _client.Mkcol("Measurement Data"); var result = await _client.Propfind("Measurement Data"); if (result.IsSuccessful) { await DisplayAlert("Оповещение", "Вход выполнен", "Ок"); } else { await DisplayAlert("Оповещение", "Проверьте правильность ввода данных", "Ок"); } } catch { await DisplayAlert("Оповещение", "Не удалось соединится", "Ок"); } }
async private Task DownloadFolder(string resourceToDownloadUri, string destinationDir) { PropfindResponse resourceProperties = await Client.Propfind(resourceToDownloadUri); if (resourceProperties.IsSuccessful) { int resourceNo = 0; int fileCount = 0; foreach (var nextResource in resourceProperties.Resources) { if (!nextResource.IsCollection) { fileCount++; } } foreach (var nextResource in resourceProperties.Resources) { if (nextResource.IsCollection) { if (nextResource.Uri != resourceToDownloadUri) { string[] resourceParts = nextResource.Uri.Split(Path.AltDirectorySeparatorChar); var dirName = (string)resourceParts.GetValue(resourceParts.Count() - 2); var newDestinationDir = Path.Combine(destinationDir, dirName); Directory.CreateDirectory(newDestinationDir); await DownloadFolder(nextResource.Uri, newDestinationDir); } } else { resourceNo++; await DownloadFile(nextResource, destinationDir, resourceNo, fileCount); } } } }