Esempio n. 1
0
 public Task <string> LockResourceAsync(ResourceLockType lockType, string resourceId, EntityType resourceType, bool force, CancellationToken cancellationToken = default) =>
 LockResourceAsync(lockType.Validate(nameof(lockType)).GetValue(), resourceId, resourceType.Validate(nameof(resourceType)).GetName(), force, cancellationToken);
Esempio n. 2
0
 /// <summary>
 /// Locks the loan in Encompass and returns the lock id.
 /// </summary>
 /// <param name="lockType">Type of Lock.</param>
 /// <param name="force">Forcefully locks a loan. This parameter allows an administrator to lock a loan that holds an exclusive lock. When set to <c>true</c>, the exclusive lock is released from the loan. The user holding the exclusive lock is notified about the lock being released and that changes cannot be saved. The default value is <c>false</c>.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
 /// <returns></returns>
 public Task <string> LockAsync(ResourceLockType lockType, bool force, CancellationToken cancellationToken = default) => LockAsync(lockType.Validate(nameof(lockType)).GetValue(), force, cancellationToken);
Esempio n. 3
0
 /// <summary>
 /// Locks the loan in Encompass and returns the lock id.
 /// </summary>
 /// <param name="lockType">Type of Lock.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
 /// <returns></returns>
 public Task <string> LockAsync(ResourceLockType lockType, CancellationToken cancellationToken = default) => LockAsync(lockType, false, cancellationToken);
 /// <summary>
 /// Tries to acquire a lock for a given folder and its parent folders,
 /// and executes the submitted <paramref name="action"/> if the lock
 /// was granted. Otherwise audits a warning.
 /// </summary>
 /// <param name="folder">The folder to be locked.</param>
 /// <param name="context">The currently performed file system operation.</param>
 /// <param name="lockType">Whether a read or a write lock is required for the
 /// <paramref name="folder"/>.</param>
 /// <param name="action">An action that is being executed if the locking
 /// succeeded.</param>
 /// <returns>True if locking succeeded and the <paramref name="action"/> was invoked. False
 /// if the lock was not granted.</returns>
 protected virtual bool LockResourceAndExecute(IVirtualFolderItem folder, FileSystemTask context, ResourceLockType lockType, Action action)
 {
   using (var guard = RequestChainedLockGuard(folder, lockType))
   {
     if (!guard.IsLockEnabled)
     {
       AuditEvent ae = lockType == ResourceLockType.Read
                         ? AuditEvent.FolderReadLockDenied
                         : AuditEvent.FolderWriteLockDenied;
       AuditHelper.AuditDeniedOperation(Auditor,context, ae, folder);
       return false;
     }
     
     action();
     return true;
   }
 }
    /// <summary>
    /// Creates a <see cref="ResourceLockGuard"/> that encapsulates
    /// a read or write lock for a given folder as well as read locks
    /// for all its parent folders.
    /// </summary>
    /// <param name="folder">The folder to be locked.</param>
    /// <param name="lockType">Whether a read or a write lock is being
    /// required for the <paramref name="folder"/>.</param>
    /// <returns>A guard which releases folder resource and all folders once it is being disposed.
    /// If locking did not succeed because an element in the chain could not be locked,
    /// the returned <see cref="ResourceLockGuard.IsLockEnabled"/> property
    /// is false.</returns>
    protected virtual ResourceLockGuard RequestChainedLockGuard(IVirtualFolderItem folder, ResourceLockType lockType)
    {
      List<string> parentFolders = GetResourceLockChain(folder);

      switch (lockType)
      {
        case ResourceLockType.Read:
          return LockRepository.GetResourceChainLock(folder.QualifiedIdentifier, false, parentFolders);
        case ResourceLockType.Write:
          return LockRepository.GetResourceChainLock(folder.QualifiedIdentifier, true, parentFolders);
        default:
          throw new ArgumentOutOfRangeException("lockType", "Unknown lock type: " + lockType);
      }
    }
Esempio n. 6
0
 public Task<string> LockResourceAsync(ResourceLockType lockType, string resourceId, string resourceType, bool force, CancellationToken cancellationToken = default) =>
     LockResourceAsync(lockType.AsString(), resourceId, resourceType, force, cancellationToken);