///<inheritdoc> public async Task UnlockAsync() { if (MsOfficeHelper.IsMsOfficeLocked(UserFileSystemPath)) // Required for PowerPoint. It does not block the for writing. { throw new ClientLockFailedException("The file is blocked for writing."); } ExternalDataManager customDataManager = Engine.CustomDataManager(UserFileSystemPath, Logger); LockManager lockManager = customDataManager.LockManager; // Set pending icon, so the user has a feedback as unlock operation may take some time. await customDataManager.SetLockPendingIconAsync(true); // Read lock-token from lock-info file. string lockToken = (await lockManager.GetLockInfoAsync()).LockToken; // Unlock the item in the remote storage here. // Delete lock-mode and lock-token info. lockManager.DeleteLock(); // Remove lock icon and lock info in custom columns. await customDataManager.SetLockInfoAsync(null); Logger.LogMessage("Unlocked in the remote storage succesefully", UserFileSystemPath); }
/// <inheritdoc/> public async Task WriteAsync(IFileMetadata fileMetadata, Stream content = null) { if (MsOfficeHelper.IsMsOfficeLocked(UserFileSystemPath)) // Required for PowerPoint. It does not block the for writing. { throw new ClientLockFailedException("The file is blocked for writing."); } Logger.LogMessage($"{nameof(IFile)}.{nameof(WriteAsync)}()", UserFileSystemPath); ExternalDataManager customDataManager = Engine.CustomDataManager(UserFileSystemPath); // Send the ETag to the server as part of the update to ensure the file in the remote storge is not modified since last read. string oldEtag = await customDataManager.ETagManager.GetETagAsync(); // Send the lock-token to the server as part of the update. string lockToken = (await customDataManager.LockManager.GetLockInfoAsync())?.LockToken; FileInfo remoteStorageItem = new FileInfo(RemoteStoragePath); if (content != null) { // Upload remote storage file content. await using (FileStream remoteStorageStream = remoteStorageItem.Open(FileMode.Open, FileAccess.Write, FileShare.Delete)) { await content.CopyToAsync(remoteStorageStream); remoteStorageStream.SetLength(content.Length); } } // Update remote storage file metadata. remoteStorageItem.Attributes = fileMetadata.Attributes; remoteStorageItem.CreationTimeUtc = fileMetadata.CreationTime.UtcDateTime; remoteStorageItem.LastWriteTimeUtc = fileMetadata.LastWriteTime.UtcDateTime; remoteStorageItem.LastAccessTimeUtc = fileMetadata.LastAccessTime.UtcDateTime; remoteStorageItem.LastWriteTimeUtc = fileMetadata.LastWriteTime.UtcDateTime; // Get the new ETag from server here as part of the update and save it on the client. string newEtag = "1234567890"; await customDataManager.ETagManager.SetETagAsync(newEtag); await customDataManager.SetCustomColumnsAsync(new[] { new FileSystemItemPropertyData((int)CustomColumnIds.ETag, newEtag) }); }