Example #1
0
        public override bool Rename(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            Drive.ValidateName(name);

            if (string.Compare(name, Name, StringComparison.OrdinalIgnoreCase) == 0)
            {
                return(false);
            }

            if (FullPath == null || !Directory.Exists(FullPath))
            {
                return(false);
            }

            Directory.Move(FullPath, Path.Combine(Path.GetDirectoryName(FullPath), Id.ToString("N") + "." + ParentId.ToString("N") + "." + name));
            return(true);
        }
Example #2
0
        public Folder EnsureChildFolder(string name)
        {
            Drive.ValidateName(name);

            string dir  = EnsureDirectory();
            var    item = GetItem(name);

            if (item != null)
            {
                if (item is Folder fld)
                {
                    return(fld);
                }

                throw new InvalidOperationException();
            }

            var folder = new Folder();

            folder.FullPath = Path.Combine(dir, Guid.NewGuid().ToString("N") + "." + Id.ToString("N") + "." + name);
            Directory.CreateDirectory(folder.FullPath);
            return(folder);
        }
Example #3
0
        public Item GetItem(string name)
        {
            Drive.ValidateName(name);

            string dir = Path.GetDirectoryName(FullPath);

            if (!Directory.Exists(dir))
            {
                return(null);
            }

            var file = Directory.EnumerateFileSystemEntries(dir, "*." + Id.ToString("N") + "." + name).FirstOrDefault();

            if (file == null)
            {
                return(null);
            }

            var item = File.Exists(file) ? new Item() : new Folder();

            item.FullPath = file;
            return(item);
        }