示例#1
0
        public override T Using <T>(DirectoryContentHash cwd, Func <IFileSystemContext, T> action)
        {
            if (Root == null)
            {
                throw new InvalidOperationException("Unable to retrieve the root directory.");
            }

            DirectoryType rootDirectoryType;

            if (!EntityDirectoryTypes.TryGetValue(Root.LogicalName, out rootDirectoryType))
            {
                throw new InvalidOperationException("Unable to retrieve the root directory.");
            }

            DirectoryType currentDirectoryType;

            if (!EntityDirectoryTypes.TryGetValue(cwd.LogicalName, out currentDirectoryType))
            {
                throw new InvalidOperationException("Unable to retrieve the target directory");
            }

            var current = new EntityDirectory(this, cwd.ToEntityReference(), currentDirectoryType);

            if (!current.Exists)
            {
                throw new InvalidOperationException("Unable to retrieve the target directory");
            }

            return(action(new EntityFileSystemContext(this, Root, rootDirectoryType, current)));
        }
        private IDirectory GetDirectory(ContentMap contentMap, DirectoryContentHash hash)
        {
            var entityReference = hash.ToEntityReference();

            WebPageNode node;

            if (contentMap.TryGetValue(entityReference, out node))
            {
                return(new WebPageNodeDirectory(this, contentMap, node));
            }

            DirectoryType entityDirectoryType;

            if (EntityDirectoryTypes.TryGetValue(entityReference.LogicalName, out entityDirectoryType))
            {
                return(new EntityDirectory(this, entityReference, entityDirectoryType));
            }

            return(null);
        }