Exemplo n.º 1
0
        /// <inheritdoc/>
        public async Task OpenAsync(IOperationContext operationContext, IResultContext context)
        {
            Logger.LogMessage($"{nameof(IFile)}.{nameof(OpenAsync)}()", UserFileSystemPath);

            // Auto-lock the file.
            string userFileSystemFilePath = UserFileSystemPath;

            if (Engine.ChangesProcessingEnabled && FsPath.Exists(userFileSystemFilePath))
            {
                if (VirtualDrive.Settings.AutoLock &&
                    !FsPath.AvoidAutoLock(userFileSystemFilePath) &&
                    !await VirtualDrive.LockManager(userFileSystemFilePath, Logger).IsLockedAsync() &&
                    FsPath.IsWriteLocked(userFileSystemFilePath) &&
                    !new PlaceholderFile(userFileSystemFilePath).IsNew(VirtualDrive))
                {
                    RemoteStorageRawItem <IVirtualFile> remoteStorageRawItem = new RemoteStorageRawItem <IVirtualFile>(userFileSystemFilePath, VirtualDrive, Logger);
                    if (await remoteStorageRawItem.IsLockSupportedAsync())
                    {
                        try
                        {
                            await remoteStorageRawItem.LockAsync(LockMode.Auto);
                        }
                        catch (ClientLockFailedException ex)
                        {
                            // Lock file is blocked by a concurrent thread. This is a normal behaviour.
                            Logger.LogMessage(ex.Message, userFileSystemFilePath);
                        }
                    }
                }
            }
        }