/// <summary> /// returns a List of availble remote Properties for the given source. /// This list determines what Resources can be found at the given Uri /// </summary> /// <param name="sourceUri"></param> /// <returns>A List of Remote properties or an empty List if nothing is found at the requested Uri</returns> public IEnumerable <IRemoteProperty> GetProperties(string sourceUri) { PropfindResponse properties = FindProperties(_webDavClient, sourceUri, true).Result; if (properties != null && properties.IsSuccessful) { return(properties.Resources.ToList().ConvertAll(x => new WebDavRemoteProperty(x, _config.Remote.RemoteFolderPath))); } return(null); }
public async Task <OcsDirectoryInfo> GetDirectoryInfo(string name) { PropfindResponse response = await this.webDav.Propfind(name) .ConfigureAwait(false); if (!response.IsSuccessful) { return(null); } WebDavResource resource = response.Resources .OrderBy(r => r.Uri.Length) .FirstOrDefault(); if (resource == null) { return new OcsDirectoryInfo { Name = name } } ; WebDavProperty usedProperty = resource.Properties.FirstOrDefault(p => p.Name.LocalName == "quota-used-bytes"); WebDavProperty availableProperty = resource.Properties.FirstOrDefault(p => p.Name.LocalName == "quota-available-bytes"); long used, avail; if (usedProperty == null || !long.TryParse(usedProperty.Value, out used)) { used = long.MinValue; } if (availableProperty == null || !long.TryParse(availableProperty.Value, out avail)) { avail = long.MinValue; } long?quota = null; if (used != long.MinValue && avail != long.MinValue) { quota = used + avail; } return(new OcsDirectoryInfo { Name = name, QuotaBytes = quota, SizeBytes = used != long.MinValue ? used : default(long?) }); }
/// <summary> /// Try to get the Property of the given dstUri /// </summary> /// <param name="dstUri"></param> /// <param name="client"></param> /// <returns>The Found Property as WebDavRemoteProperty or null if an error occured</returns> private WebDavRemoteProperty GetProperty(string dstUri, WebDavClient client) { PropfindResponse result = FindProperties(client, dstUri, false).Result; if (result != null && result.IsSuccessful) { return(new WebDavRemoteProperty(result.Resources.FirstOrDefault(), _config.Remote.RemoteFolderPath)); } else { _logger.Error("Could not get Properties from destination " + dstUri); } return(null); }
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); } } } }