/// <summary>
        /// Gets the directory quota.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns>The fsrm quota instance.</returns>
        private IFsrmQuota GetDirectoryFsrmQuota(string path)
        {
            path = CanonicalPath(path);
            IFsrmQuota dirQuota = null;

            lock (this.quotasCacheLock)
            {
                this.quotasCache.TryGetValue(path, out dirQuota);
            }

            if (dirQuota == null)
            {
                try
                {
                    dirQuota = this.quotaManager.GetQuota(path);
                }
                catch (COMException ex)
                {
                    if (ex.ErrorCode == -2147200255)
                    {
                        // Error code: 0x80045301
                        // The specified quota could not be found.
                        dirQuota = null;
                    }
                    else if (ex.ErrorCode == -2147200252)
                    {
                        // Error code: 0x80045301
                        // The quota for the specified path could not be found.
                        throw new DirectoryNotFoundException(path);
                    }
                    else
                    {
                        throw;
                    }
                }

                if (dirQuota == null)
                {
                    dirQuota            = this.quotaManager.CreateQuota(path);
                    dirQuota.QuotaLimit = (long)1024 * 1024 * 1024 * 10; // 10 GiB

                    // FsrmQuotaFlags_Enforce            = 0x00000100,
                    // FsrmQuotaFlags_Disable            = 0x00000200,
                    // FsrmQuotaFlags_StatusIncomplete   = 0x00010000,
                    // FsrmQuotaFlags_StatusRebuilding   = 0x00020000
                    dirQuota.QuotaFlags = 0x00000000; // Soft quota enforcement
                    dirQuota.Commit();
                }

                lock (this.quotasCacheLock)
                {
                    this.quotasCache[path] = dirQuota;
                }
            }

            return(dirQuota);
        }
        /// <summary>
        /// Enforces the quota.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="sizeBytes">The size bytes.</param>
        public void SetDirectoryQuota(string path, long sizeBytes)
        {
            path = CanonicalPath(path);
            IFsrmQuota dirQuota = this.GetDirectoryFsrmQuota(path);

            dirQuota.QuotaLimit = sizeBytes;
            dirQuota.QuotaFlags = 0x00000100; // Hard quota enforcement
            dirQuota.Commit();
        }
        /// <summary>
        /// Removes the directory quota.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns>True if quota was found and deleted. False if quota was not found.</returns>
        public bool RemoveDirectoryQuota(string path)
        {
            path = CanonicalPath(path);
            bool ret = false;

            IFsrmQuota dirQuota = null;

            lock (this.quotasCacheLock)
            {
                this.quotasCache.TryGetValue(path, out dirQuota);
            }

            if (dirQuota == null)
            {
                try
                {
                    dirQuota = this.quotaManager.GetQuota(path);
                }
                catch (COMException)
                {
                }
            }

            if (dirQuota != null)
            {
                dirQuota.Delete();
                dirQuota.Commit();
                ret = true;
            }

            lock (this.quotasCacheLock)
            {
                this.quotasCache.Remove(path);
            }

            return(ret);
        }