public bool AddOrGet(DirectoryIdentifier id, out List <DirectoryControlBlock> result)
        {
            var keys = DirectoryIdentifier.Split(id);

            var controlBlocks = new List <KeyValuePair <bool, DirectoryControlBlock> >();

            foreach (var i in keys)
            {
                var isNew = AddOrGetSingle(i, out var block);
                controlBlocks.Add(new KeyValuePair <bool, DirectoryControlBlock>(isNew, block));
            }

            bool added = false;
            int  index = controlBlocks.FindLastIndex(i => !i.Key);

            if (index == controlBlocks.Count - 1)
            {
                // no new item
                result = new List <DirectoryControlBlock> {
                    controlBlocks[controlBlocks.Count - 1].Value
                };
            }
            else
            {
                index  = Math.Max(0, index);
                result = controlBlocks.GetRange(index, controlBlocks.Count - index).Select(i => i.Value).ToList();
                added  = true;
            }
            return(added);
        }
Exemplo n.º 2
0
        public static bool GetRelative(DirectoryIdentifier from, DirectoryIdentifier to, out string relPath)
        {
            var f = from.FullName;
            var t = to.FullName;

            return(PathHelper.GetRelativePath(f, true, t, true, out relPath));
        }
Exemplo n.º 3
0
 public void OnDirectoryMoved(DirectoryIdentifier from, DirectoryIdentifier to)
 {
     if (_directories.TryGetValue(from, out var found))
     {
         _directories.Remove(from);
         found.ChangePath(to.FullName);
         _directories.Add(to, found);
     }
 }
Exemplo n.º 4
0
        public static DirectoryIdentifier Parent(DirectoryIdentifier id)
        {
            var di = new DirectoryInfo(id.FullName);

            if (di.Parent == null)
            {
                return(null);
            }
            return(new DirectoryIdentifier(di.Parent.FullName));
        }
        private bool AddOrGetSingle(DirectoryIdentifier key, out DirectoryControlBlock result)
        {
            var added = false;

            if (!_collection.TryGetValue(key, out result))
            {
                result           = new DirectoryControlBlock(key);
                _collection[key] = result;
                added            = true;
            }
            return(added);
        }
        public DirectoryControlBlock Change(DirectoryIdentifier from, DirectoryIdentifier to)
        {
            if (_collection.TryGetValue(from, out var ctrlBlock))
            {
                _collection.Remove(from);
            }

            var result = ctrlBlock.Clone(to);

            _collection.Add(to, result);
            return(result);
        }
Exemplo n.º 7
0
        public FakeDirectory CreateDirectory(string path, IDiskDriver driver)
        {
            var id = new DirectoryIdentifier(path);

            if (_directories.TryGetValue(id, out var result))
            {
                return(result);
            }

            result = DirectoryFactoryMethod(path, driver);
            _directories.Add(id, result);
            return(result);
        }
Exemplo n.º 8
0
 public FileIdentifier(DirectoryIdentifier dirId, FileName name)
 {
     OwningDirectory = dirId;
     Name            = name;
 }
Exemplo n.º 9
0
        public static DirectoryIdentifier CombineDirId(DirectoryIdentifier id, string path)
        {
            var newPath = Path.Combine(id.FullName, path);

            return(new DirectoryIdentifier(newPath));
        }
Exemplo n.º 10
0
        public static FileIdentifier CombineFileId(DirectoryIdentifier id, string path)
        {
            var newPath = Path.Combine(id.FullName, path);

            return(FileIdentifier.FromPath(newPath));
        }
Exemplo n.º 11
0
        public static FileIdentifier ConvertToFileId(DirectoryIdentifier id)
        {
            var path = id.FullName;

            return(FileIdentifier.FromPath(path));
        }
Exemplo n.º 12
0
        public static DirectoryIdentifier Root(DirectoryIdentifier id)
        {
            var di = new DirectoryInfo(id.FullName);

            return(new DirectoryIdentifier(di.Root.FullName));
        }
 public bool Remove(DirectoryIdentifier id)
 {
     return(_collection.Remove(id));
 }
 public bool TryGet(DirectoryIdentifier id, out DirectoryControlBlock result)
 {
     return(_collection.TryGetValue(id, out result));
 }