@@ -264,7 +264,9 @@ public async Task LockAsync(LockMode lockMode, IOperationContext operationContex
264264 // Save the lock token and other lock info received from the remote storage on the client.
265265 // Supply the lock-token as part of each remote storage update in IFile.WriteAsync() method.
266266
267- LockInfo lockInfo = await Program . DavClient . LockAsync ( new Uri ( RemoteStoragePath ) , LockScope . Exclusive , false , null , TimeSpan . MaxValue , cancellationToken ) ;
267+ // Here we set lock owner name to loged-in user for demo purposes.
268+ string lockOwner = Environment . UserName ;
269+ LockInfo lockInfo = await Program . DavClient . LockAsync ( new Uri ( RemoteStoragePath ) , LockScope . Exclusive , false , lockOwner , TimeSpan . MaxValue , cancellationToken ) ;
268270 ServerLockInfo serverLockInfo = new ServerLockInfo
269271 {
270272 LockToken = lockInfo . LockToken . LockToken ,
@@ -274,11 +276,14 @@ public async Task LockAsync(LockMode lockMode, IOperationContext operationContex
274276 } ;
275277
276278 // Save lock-token and lock-mode.
277- PlaceholderItem placeholder = Engine . Placeholders . GetItem ( UserFileSystemPath ) ;
278- await placeholder . Properties . AddOrUpdateAsync ( "LockInfo" , serverLockInfo ) ;
279- await placeholder . Properties . AddOrUpdateAsync ( "LockMode" , lockMode ) ;
279+ if ( Engine . Placeholders . TryGetItem ( UserFileSystemPath , out PlaceholderItem placeholder ) )
280+ {
281+ await placeholder . Properties . AddOrUpdateAsync ( "LockInfo" , serverLockInfo ) ;
282+ await placeholder . Properties . AddOrUpdateAsync ( "LockMode" , lockMode ) ;
283+ placeholder . UpdateUI ( ) ;
280284
281- Logger . LogDebug ( "Locked in the remote storage successfully" , UserFileSystemPath , default , operationContext ) ;
285+ Logger . LogDebug ( "Locked in the remote storage successfully" , UserFileSystemPath , default , operationContext ) ;
286+ }
282287 }
283288
284289
@@ -308,25 +313,28 @@ public async Task UnlockAsync(IOperationContext operationContext = null, Cancell
308313 Logger . LogMessage ( $ "{ nameof ( ILock ) } .{ nameof ( UnlockAsync ) } ()", UserFileSystemPath , default , operationContext ) ;
309314
310315 // Read the lock-token.
311- PlaceholderItem placeholder = Engine . Placeholders . GetItem ( UserFileSystemPath ) ;
312- string lockToken = ( await placeholder . Properties [ "LockInfo" ] . GetValueAsync < ServerLockInfo > ( ) ) ? . LockToken ;
316+ if ( Engine . Placeholders . TryGetItem ( UserFileSystemPath , out PlaceholderItem placeholder ) )
317+ {
318+ string lockToken = ( await placeholder . Properties [ "LockInfo" ] . GetValueAsync < ServerLockInfo > ( ) ) ? . LockToken ;
313319
314- LockUriTokenPair [ ] lockTokens = new LockUriTokenPair [ ] { new LockUriTokenPair ( new Uri ( RemoteStoragePath ) , lockToken ) } ;
320+ LockUriTokenPair [ ] lockTokens = new LockUriTokenPair [ ] { new LockUriTokenPair ( new Uri ( RemoteStoragePath ) , lockToken ) } ;
315321
316- // Unlock the item in the remote storage.
317- try
318- {
319- await Program . DavClient . UnlockAsync ( new Uri ( RemoteStoragePath ) , lockTokens , cancellationToken ) ;
320- Logger . LogDebug ( "Unlocked in the remote storage successfully" , UserFileSystemPath , default , operationContext ) ;
321- }
322- catch ( ITHit . WebDAV . Client . Exceptions . ConflictException )
323- {
324- Logger . LogDebug ( "The item is already unlocked." , UserFileSystemPath , default , operationContext ) ;
325- }
322+ // Unlock the item in the remote storage.
323+ try
324+ {
325+ await Program . DavClient . UnlockAsync ( new Uri ( RemoteStoragePath ) , lockTokens , cancellationToken ) ;
326+ Logger . LogDebug ( "Unlocked in the remote storage successfully" , UserFileSystemPath , default , operationContext ) ;
327+ }
328+ catch ( ITHit . WebDAV . Client . Exceptions . ConflictException )
329+ {
330+ Logger . LogDebug ( "The item is already unlocked." , UserFileSystemPath , default , operationContext ) ;
331+ }
326332
327- // Delete lock-mode and lock-token info.
328- placeholder . Properties . Remove ( "LockInfo" ) ;
329- placeholder . Properties . Remove ( "LockMode" ) ;
333+ // Delete lock-mode and lock-token info.
334+ placeholder . Properties . Remove ( "LockInfo" ) ;
335+ placeholder . Properties . Remove ( "LockMode" ) ;
336+ placeholder . UpdateUI ( ) ;
337+ }
330338 }
331339
332340 }
0 commit comments