Example #1
0
        internal override async Task MoveTo(string newPath, TreeItem trashNode)
        {
            try
            {
                await this.Lock();

                if (!Directory.Exists(newPath))
                {
                    Directory.CreateDirectory(newPath);
                }
                var newFullPath = Path.Combine(newPath, Path.GetFileName(this.FullPath));

                if (!File.Exists(newFullPath))
                {
                    File.Move(this.FullPath, newFullPath);
                    this.FullPath = newFullPath;
                    this.Parent?.RemoveChild(this);
                    trashNode.AddChild(this);
                    return;
                }
                throw new Exception($"File {newFullPath} already exists");
            } catch
            {
                throw;
            } finally
            {
                this.ReleaseLock();
            }
        }
        protected TreeItem(string relative_path, TreeItem parent, string name, string fullPath)
        {
            Id       = GetId(relative_path);
            Name     = name;
            Children = null;

            Parent   = parent;
            FullPath = fullPath;

            if (parent != null)
            {
                parent.AddChild(this);
            }
        }