void Copy(FileSystemItemInfo sourceItem, FileSystemItemInfo destinationItem, bool deleteSource = false)
        {
            string sourceKey      = GetFileItemPath(sourceItem);
            string destinationKey = GetFileItemPath(destinationItem) + "/" + sourceItem.Name;

            Copy(sourceKey, destinationKey, deleteSource);
        }
Exemplo n.º 2
0
        void ThrowItemNotFoundException(FileSystemItemInfo item)
        {
            var    itemType  = item.IsDirectory ? "Directory" : "File";
            var    errorCode = item.IsDirectory ? FileSystemErrorCode.DirectoryNotFound : FileSystemErrorCode.FileNotFound;
            string message   = $"{itemType} '{item.Path}' not found.";

            throw new FileSystemException(errorCode, message);
        }
Exemplo n.º 3
0
        static bool AllowCopyOrMove(FileSystemItemInfo item, FileSystemItemInfo destinationDirectory)
        {
            if (destinationDirectory.PathKeys.Length < item.PathKeys.Length)
            {
                return(true);
            }

            var isValid = false;

            for (var i = 0; i < destinationDirectory.PathKeys.Length && !isValid; i++)
            {
                isValid = destinationDirectory.PathKeys[i] != item.PathKeys[i];
            }
            return(isValid);
        }
Exemplo n.º 4
0
        bool IsFileItemExists(FileSystemItemInfo itemInfo)
        {
            var pathKeys     = itemInfo.PathKeys.Select(key => ParseKey(key)).ToArray();
            var foundEntries = FileManagementDbContext.FileItems
                               .Where(item => pathKeys.Contains(item.Id))
                               .Select(item => new { item.Id, item.ParentId, item.Name, item.IsDirectory });

            var pathNames = itemInfo.Path.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);

            var isDirectoryExists = true;

            for (var i = 0; i < pathKeys.Length && isDirectoryExists; i++)
            {
                var entry = foundEntries.FirstOrDefault(e => e.Id == pathKeys[i]);
                isDirectoryExists = entry != null && entry.Name == pathNames[i] &&
                                    (i == 0 && entry.ParentId == 0 || entry.ParentId == pathKeys[i - 1]);
                if (isDirectoryExists && i < pathKeys.Length - 1)
                {
                    isDirectoryExists = entry.IsDirectory;
                }
            }
            return(isDirectoryExists);
        }
 string GetFileItemPath(FileSystemItemInfo item)
 {
     return(item.Path.Replace('\\', '/'));
 }
Exemplo n.º 6
0
        FileItem GetFileItem(FileSystemItemInfo item)
        {
            var itemId = ParseKey(item.Key);

            return(FileManagementDbContext.FileItems.FirstOrDefault(i => i.Id == itemId));
        }