Ejemplo n.º 1
0
        public Item EnsureChildItem(string name, out bool isNew)
        {
            Drive.ValidateName(name);

            var item = GetItem(name);

            if (item != null)
            {
                isNew = false;
                return(item);
            }

            string dir = EnsureDirectory();

            item          = new Item();
            item.FullPath = Path.Combine(dir, Guid.NewGuid().ToString("N") + "." + Id.ToString("N") + "." + name);
            using (var file = File.OpenWrite(item.FullPath))
            {
                // do nothing special
            }

            isNew = true;

            // reread infos
            var newItem = new Item();

            newItem.FullPath = item.FullPath;
            return(newItem);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }