/// <summary>
    /// Internally resolves a given file resource by invoking <see cref="ResolveFileResourcePath"/>,
    /// and performs basic exception handling, auditing, access and availability checks.<br/>
    /// This method may be overridden in case additional work needs to be done in order to resolve
    /// the resource based on the submitted path.
    /// </summary>
    /// <param name="virtualFilePath">The submitted file path that needs to be resolved.</param>
    /// <param name="mustExist">Whether the file must exist on the file system. If this parameter is true
    /// and the received <typeparamref name="TFile"/>'s <see cref="IVirtualFileItem.Exists"/> is
    /// false, and <see cref="VirtualResourceNotFoundException"/> is being thrown.</param>
    /// <param name="context">The file system operation that is being performed during the invocation of
    /// this method. Used for internal auditing.</param>
    /// <returns>A wrapper item that includes the a <see cref="VirtualFileInfo"/> that corresponds
    /// to the submitted <paramref name="virtualFilePath"/>.</returns>
    /// <exception cref="ArgumentNullException">If <paramref name="virtualFilePath"/>
    /// is a null reference.</exception>
    /// <exception cref="VirtualResourceNotFoundException">If <paramref name="mustExist"/> is true, and
    /// the folder's <see cref="IVirtualFileItem.Exists"/> property is false.</exception>
        protected IVirtualFileItem ResolveFileResourcePathInternal(string virtualFilePath, bool mustExist, FileSystemTask context)
    {
      //TODO allow null (also for folders), but write test first
      Ensure.ArgumentNotNull(virtualFilePath, "virtualFilePath");

      IVirtualFileItem fileItem;
      try
      {
        fileItem = ResolveFileResourcePath(virtualFilePath, context);
      }
      catch (InvalidResourcePathException e)
      {
        AuditHelper.AuditException(Auditor,e, context, AuditEvent.InvalidFilePathFormat);
        throw;
      }
      catch (VfsException e)
      {
        //audit exception
        AuditHelper.AuditException(Auditor,e, context, AuditEvent.FileResolveFailed);
        throw;
      }
      catch (Exception e)
      {
        //wrap exception and audit
        string msg = String.Format("Unexpected exception while resolving file path [{0}]", virtualFilePath);
        var rae = new ResourceAccessException(msg, e);

        AuditHelper.AuditException(Auditor,rae, context, AuditEvent.FileResolveFailed);
        throw rae;
      }


      if (mustExist && !fileItem.Exists)
      {
        //audit and throw exception
        AuditHelper.AuditRequestedFileNotFound(Auditor,fileItem, context);

        string msg = String.Format("File [{0}] not found on file system.", fileItem.ResourceInfo.FullName);
        throw new VirtualResourceNotFoundException(msg) { Resource = fileItem.ResourceInfo, IsAudited = true };
      }

      return fileItem;
    }
    /// <summary>
    /// Internally resolves a given folder resource by invoking <see cref="ResolveFolderResourcePath"/>,
    /// and performs basic exception handling, auditing, access and availability checks.<br/>
    /// This method may be overridden in case additional work needs to be done in order to resolve
    /// the resource based on the submitted path.
    /// </summary>
    /// <param name="virtualFolderPath">The submitted folder path that needs to be resolved.</param>
    /// <param name="mustExist">Whether the folder must exist on the file system. If this parameter is true
    /// and the received <typeparamref name="TFolder"/>'s <see cref="IVirtualFolderItem.Exists"/> is
    /// false, and <see cref="VirtualResourceNotFoundException"/> is being thrown.</param>
    /// <param name="context">The file system operation that is being performed during the invocation of
    /// this method. Used for internal auditing.</param>
    /// <returns>A wrapper item that includes the a <see cref="VirtualFolderInfo"/> that corresponds
    /// to the submitted <paramref name="virtualFolderPath"/>.</returns>
    /// <exception cref="ArgumentNullException">If <paramref name="virtualFolderPath"/>
    /// is a null reference.</exception>
    /// <exception cref="VirtualResourceNotFoundException">If <paramref name="mustExist"/> is true, and
    /// the folder's <see cref="IVirtualFolderItem.Exists"/> property is false.</exception>
        protected virtual IVirtualFolderItem ResolveFolderResourcePathInternal(string virtualFolderPath, bool mustExist, FileSystemTask context)
    {
        IVirtualFolderItem folderItem;
      try
      {
        folderItem = ResolveFolderResourcePath(virtualFolderPath, context);
      }
      catch(InvalidResourcePathException e)
      {
        AuditHelper.AuditException(Auditor,e, context, AuditEvent.InvalidFolderPathFormat);
        throw;
      }
      catch (VfsException e)
      {
        //audit exception
        AuditHelper.AuditException(Auditor,e, context, AuditEvent.FolderResolveFailed);
        throw;
      }
      catch (Exception e)
      {
        //wrap exception and audit
        string msg = String.Format("Unexpected exception while resolving folder path [{0}]", virtualFolderPath);
        var rae = new ResourceAccessException(msg, e);

        AuditHelper.AuditException(Auditor,rae, context, AuditEvent.FolderResolveFailed);
        throw rae;
      }


      if (mustExist && !folderItem.Exists)
      {
        //audit and throw exception
        AuditHelper.AuditRequestedFolderNotFound(Auditor,folderItem, context);

        string msg = String.Format("Folder [{0}] not found on file system.", folderItem.ResourceInfo.FullName);
        throw new VirtualResourceNotFoundException(msg) { Resource = folderItem.ResourceInfo, IsAudited = true};
      }

      return folderItem;
    }