Exemplo n.º 1
0
        public void Move(ICloudDrive drive, string newName, CloudDirectoryNode destinationDirectory)
        {
            if (drive == null)
            {
                throw new ArgumentNullException(nameof(drive));
            }
            if (string.IsNullOrEmpty(newName))
            {
                throw new ArgumentNullException(nameof(newName));
            }
            if (destinationDirectory == null)
            {
                throw new ArgumentNullException(nameof(destinationDirectory));
            }
            if (Parent == null)
            {
                throw new InvalidOperationException($"{nameof(Parent)} of {GetType().Name} '{Name}' is null".ToString(CultureInfo.CurrentCulture));
            }

            var moveItem = CreateNew(drive.MoveItem(Contract, newName, destinationDirectory.Contract));

            if (destinationDirectory.children != null)
            {
                destinationDirectory.children.Add(moveItem.Name, moveItem);
                moveItem.SetParent(destinationDirectory);
            }
            else
            {
                destinationDirectory.GetChildItems(drive);
            }
            Parent.children.Remove(Name);
            SetParent(null);
        }
Exemplo n.º 2
0
        private CloudItemNode GetItem(string fileName)
        {
            var result = _root ?? (_root = new CloudDirectoryNode(_drive.GetRoot())) as CloudItemNode;

            var pathSegments = new Queue <string>(fileName.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries));

            while (result != null && pathSegments.Count > 0)
            {
                result = (result as CloudDirectoryNode)?.GetChildItemByName(_drive, pathSegments.Dequeue());
            }

            return(result);
        }
        public CloudDirectoryNode NewDirectoryItem(ICloudDrive drive, string directoryName)
        {
            if (drive == null)
            {
                throw new ArgumentNullException(nameof(drive));
            }

            var newItem = new CloudDirectoryNode(drive.NewDirectoryItem(Contract, directoryName));

            children.Add(newItem.Name, newItem);
            newItem.SetParent(this);
            return(newItem);
        }
Exemplo n.º 4
0
 public virtual void SetParent(CloudDirectoryNode parent)
 => Parent = parent;
 public override void SetParent(CloudDirectoryNode parent)
 {
     base.SetParent(parent);
     Contract.Parent = parent?.Contract;
 }