/// <summary> /// Deletes all extended attributes. /// </summary> /// <param name="dataCloudItem"><see cref="DataCloudItem"/></param> public async Task DeleteExtendedAttributes(DataCloudItem dataCloudItem) { var fileClient = GetFileClient(dataCloudItem.Path); dataCloudItem.Properties.Clear(); await fileClient.SetMetadataAsync(dataCloudItem.Properties); }
/// <summary> /// Gets extended attribute. /// </summary> /// <param name="dataCloudItem"><see cref="DataCloudItem"/></param> /// <param name="attribName">Attribute name.</param> /// <returns>Attribute value.</returns> public async Task <T> GetExtendedAttributeAsync <T>(DataCloudItem dataCloudItem, string attribName) where T : new() { if (string.IsNullOrEmpty(attribName)) { throw new ArgumentNullException("attribName"); } dataCloudItem.Properties.TryGetValue(attribName, out var value); return(Deserialize <T>(value)); }
/// <summary> /// Deletes extended attribute. /// </summary> /// <param name="dataCloudItem"><see cref="DataCloudItem"/></param> /// <param name="attribName">Attribute name.</param> public async Task DeleteExtendedAttributeAsync(DataCloudItem dataCloudItem, string attribName) { if (string.IsNullOrEmpty(attribName)) { throw new ArgumentNullException("attribName"); } var fileClient = GetFileClient(dataCloudItem.Path); dataCloudItem.Properties.Remove(attribName); await fileClient.SetMetadataAsync(dataCloudItem.Properties); }
/// <summary> /// Returns item info for the path. Doesn't check if item exists. /// </summary> /// <param name="path">Path to item.</param> /// <returns><see cref="DataCloudItem"/></returns> public async Task <DataCloudItem> GetItemAsync(string path) { var client = GetFileClient(path); var properties = await client.GetPropertiesAsync(); var dlItem = new DataCloudItem { ContentLength = properties.Value.ContentLength, ContentType = properties.Value.ContentType, Name = EncodeUtil.DecodeUrlPart(client.Name), Path = client.Path, CreatedUtc = properties.Value.CreatedOn.UtcDateTime, ModifiedUtc = properties.Value.LastModified.UtcDateTime, Properties = properties.Value.Metadata, IsDirectory = properties.Value.IsDirectory }; return(dlItem); }
/// <summary> /// Sets extended attribute. /// </summary> /// <param name="dataCloudItem"><see cref="DataCloudItem"/></param> /// <param name="attribName">Attribute name.</param> /// <param name="attribValue">Attribute value.</param> public async Task SetExtendedAttributeAsync(DataCloudItem dataCloudItem, string attribName, object attribValue) { if (string.IsNullOrEmpty(attribName)) { throw new ArgumentNullException("attribName"); } if (attribValue == null) { throw new ArgumentNullException("attribValue"); } if (!dataCloudItem.Properties.ContainsKey(LastModifiedProperty)) { dataCloudItem.Properties[LastModifiedProperty] = (dataCloudItem.ModifiedUtc.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds.ToString(CultureInfo.InvariantCulture); } var fileClient = GetFileClient(dataCloudItem.Path); dataCloudItem.Properties[attribName] = Serialize(attribValue); await fileClient.SetMetadataAsync(dataCloudItem.Properties); }
/// <summary> /// Copy item to another destination. /// </summary> /// <param name="path">Path to item.</param> /// <param name="destFolder">Path to destination folder.</param> /// <param name="destName">Destination name.</param> /// <param name="contentLength">Size of item to copy.</param> /// <param name="sourceProps">Custom attributes to copy.</param> /// <returns></returns> public async Task CopyItemAsync(string path, string destFolder, string destName, long contentLength, IDictionary <string, string> sourceProps) { var sourceClient = GetFileClient(path); var targetFolder = GetDirectoryClient(destFolder); await CreateFileAsync(destFolder, destName); await using var memoryStream = new MemoryStream(); await sourceClient.ReadToAsync(memoryStream); memoryStream.Position = 0; string targetPath = targetFolder.Path + "/" + EncodeUtil.EncodeUrlPart(destName); await WriteItemAsync(targetPath, memoryStream, contentLength, sourceProps); await CopyExtendedAttributes(new DataCloudItem { Properties = sourceProps }, targetPath); var destItem = new DataCloudItem { Name = destName, Path = targetPath }; await DeleteExtendedAttributeAsync(destItem, "Locks"); }
/// <summary> /// Moves all extended attributes. /// </summary> /// <param name="dataCloudItem"><see cref="DataCloudItem"/></param> /// <param name="destPath">Destination path.</param> public async Task MoveExtendedAttributes(DataCloudItem dataCloudItem, string destPath) { await CopyExtendedAttributes(dataCloudItem, destPath); await DeleteExtendedAttributes(dataCloudItem); }
/// <summary> /// Copies all extended attributes. /// </summary> /// <param name="dataCloudItem"><see cref="DataCloudItem"/></param> /// <param name="destPath">Destination path.</param> public async Task CopyExtendedAttributes(DataCloudItem dataCloudItem, string destPath) { await GetFileClient(destPath).SetMetadataAsync(dataCloudItem.Properties); }