/// <summary> /// Locks the item in the remote storage. The item must implement <see cref="IVirtualLock"/> interface. /// </summary> /// <param name="lockSync">Sync lock.</param> /// <param name="lockMode">Indicates automatic or manual lock.</param> private async Task <ServerLockInfo> LockAsync(LockSync lockSync, LockMode lockMode) { ServerLockInfo lockInfo = null; try { logger.LogMessage("Locking in remote storage", userFileSystemPath); // Set lock-pending icon. await userFileSystemRawItem.SetLockPendingIconAsync(true); // Lock file in remote storage. IVirtualLock userLock = await GetItemAsync(userFileSystemPath) as IVirtualLock; lockInfo = await userLock.LockAsync(); // Save lock-token and lock-mode. await lockManager.SetLockInfoAsync(lockInfo); await lockManager.SetLockModeAsync(lockMode); logger.LogMessage("Locked in remote storage succesefully.", userFileSystemPath); } catch (Exception ex) { logger.LogError("Locking in remote storage failed.", userFileSystemPath, null, ex); // Delete lock-token and lock-mode files. await lockManager.DeleteLockAsync(); // Clear lock icon. await userFileSystemRawItem.SetLockInfoAsync(null); // Rethrow the exception preserving stack trace of the original exception. System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(ex).Throw(); } // Set locked icon and all lock properties. await userFileSystemRawItem.SetLockInfoAsync(lockInfo); return(lockInfo); }